@react-pakistan/util-functions 1.25.87 → 1.25.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -84,7 +84,7 @@ var GenericTable = function (_a) {
|
|
|
84
84
|
return (react_1.default.createElement("div", { className: "space-y-4 ".concat(isRTL ? 'rtl' : 'ltr'), dir: isRTL ? 'rtl' : 'ltr' },
|
|
85
85
|
react_1.default.createElement(enhanced_table_1.EnhancedTable, { currentPage: Number(context.state.currentPage), handleNextOnClick: context.handlePageChange, handleOnSelect: context.handlePageLimitChange, handlePreviousOnClick: function () {
|
|
86
86
|
return context.handlePageChange(context.state.currentPage - 1);
|
|
87
|
-
}, handleSearchInput: context.handleSearch, headerActions: allHeaderActions, isNextDisabled: (0, general_1.isNextButtonDisabled)(context.state.currentPage, totalPages), isPreviousDisabled: (0, general_1.isPreviousButtonDisabled)(context.state.currentPage), listOptions: (0, general_1.getAvailablePageLimits)(context.state.count), loading: context.listLoading, nodeSelectKey: "pageLimit", numberOfFilters: numberOfFilters, onClearFilters: config.onClearFilters, pageLimit: context.state.pageLimit, rowActions: rowActions || context.rowActions || [], searchDisabled: false, searchEnabled: true, searchId: "".concat(config.moduleName.toLowerCase(), "-search"), searchPlaceholder: config.searchPlaceholder, searchValue: context.state.searchQuery, tableBodyCols: tableBodyCols, tableBodyRows: context.state.items, tableDescription: config.tableDescription, tableHeading: config.tableTitle, tableHeadItems: tableHeadItems, totalPages: Number(totalPages) })));
|
|
87
|
+
}, handleSearchInput: function (key, value) { var _a; return (_a = context.handleSearch) === null || _a === void 0 ? void 0 : _a.call(context, value); }, headerActions: allHeaderActions, isNextDisabled: (0, general_1.isNextButtonDisabled)(context.state.currentPage, totalPages), isPreviousDisabled: (0, general_1.isPreviousButtonDisabled)(context.state.currentPage), listOptions: (0, general_1.getAvailablePageLimits)(context.state.count), loading: context.listLoading, nodeSelectKey: "pageLimit", numberOfFilters: numberOfFilters, onClearFilters: config.onClearFilters, pageLimit: context.state.pageLimit, rowActions: rowActions || context.rowActions || [], searchDisabled: false, searchEnabled: true, searchId: "".concat(config.moduleName.toLowerCase(), "-search"), searchPlaceholder: config.searchPlaceholder, searchValue: context.state.searchQuery, tableBodyCols: tableBodyCols, tableBodyRows: context.state.items, tableDescription: config.tableDescription, tableHeading: config.tableTitle, tableHeadItems: tableHeadItems, totalPages: Number(totalPages) })));
|
|
88
88
|
};
|
|
89
89
|
exports.GenericTable = GenericTable;
|
|
90
90
|
var GenericDrawer = function (_a) {
|
|
@@ -35,20 +35,28 @@ export declare const GENERIC_ACTION_TYPES: {
|
|
|
35
35
|
readonly SET_FILTERS: "SET_FILTERS";
|
|
36
36
|
};
|
|
37
37
|
export declare const createGenericReducer: <T>(config: ModuleConfig<T>) => (state: T, action: any) => T;
|
|
38
|
-
export declare const createGenericModuleHook: <T>(config: ModuleConfig<T>) => () =>
|
|
38
|
+
export declare const createGenericModuleHook: <T>(config: ModuleConfig<T>) => () => GenericModuleContextWithHandlers<T>;
|
|
39
39
|
export declare const createGenericModuleProvider: <T>(config: ModuleConfig<T>) => {
|
|
40
40
|
Provider: React.FC<{
|
|
41
41
|
children: React.ReactNode;
|
|
42
42
|
}>;
|
|
43
|
-
useContext: () =>
|
|
44
|
-
Context: React.Context<
|
|
43
|
+
useContext: () => GenericModuleContextWithHandlers<T>;
|
|
44
|
+
Context: React.Context<GenericModuleContextWithHandlers<T> | undefined>;
|
|
45
45
|
};
|
|
46
|
+
export interface GenericModuleContextWithHandlers<T = any> extends GenericModuleContext<T> {
|
|
47
|
+
handleSearch?: (query: string) => void;
|
|
48
|
+
handlePageChange?: (page: number) => void;
|
|
49
|
+
handlePageLimitChange?: (limit: number) => void;
|
|
50
|
+
handleCloseDrawer?: () => void;
|
|
51
|
+
handleSubmit?: (data: any) => void;
|
|
52
|
+
}
|
|
53
|
+
export declare const createGenericHandlers: <T>(dispatch: React.Dispatch<any>) => Omit<GenericModuleContextWithHandlers<T>, "state" | "dispatch">;
|
|
46
54
|
export declare const createGenericModule: <T>(config: ModuleConfig<T>) => {
|
|
47
55
|
reducer: (state: T, action: any) => T;
|
|
48
56
|
Provider: React.FC<{
|
|
49
57
|
children: React.ReactNode;
|
|
50
58
|
}>;
|
|
51
|
-
useContext: () =>
|
|
59
|
+
useContext: () => GenericModuleContextWithHandlers<T>;
|
|
52
60
|
config: ModuleConfig<T>;
|
|
53
61
|
actionTypes: {
|
|
54
62
|
readonly RESET_FORM: "RESET_FORM";
|
|
@@ -64,4 +72,5 @@ export declare const createGenericModule: <T>(config: ModuleConfig<T>) => {
|
|
|
64
72
|
readonly SET_FILTERS: "SET_FILTERS";
|
|
65
73
|
};
|
|
66
74
|
initialState: T;
|
|
75
|
+
createHandlers: <T_1>(dispatch: React.Dispatch<any>) => Omit<GenericModuleContextWithHandlers<T_1>, "state" | "dispatch">;
|
|
67
76
|
};
|
|
@@ -51,7 +51,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
};
|
|
52
52
|
})();
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.createGenericModule = exports.createGenericModuleProvider = exports.createGenericModuleHook = exports.createGenericReducer = exports.GENERIC_ACTION_TYPES = void 0;
|
|
54
|
+
exports.createGenericModule = exports.createGenericHandlers = exports.createGenericModuleProvider = exports.createGenericModuleHook = exports.createGenericReducer = exports.GENERIC_ACTION_TYPES = void 0;
|
|
55
55
|
var react_1 = __importStar(require("react"));
|
|
56
56
|
// ============================================================================
|
|
57
57
|
// ACTION TYPES
|
|
@@ -112,10 +112,8 @@ exports.createGenericReducer = createGenericReducer;
|
|
|
112
112
|
var createGenericModuleHook = function (config) {
|
|
113
113
|
return function () {
|
|
114
114
|
var _a = (0, react_1.useReducer)((0, exports.createGenericReducer)(config), config.initialState), state = _a[0], dispatch = _a[1];
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
dispatch: dispatch,
|
|
118
|
-
};
|
|
115
|
+
var handlers = (0, exports.createGenericHandlers)(dispatch);
|
|
116
|
+
return __assign({ state: state, dispatch: dispatch }, handlers);
|
|
119
117
|
};
|
|
120
118
|
};
|
|
121
119
|
exports.createGenericModuleHook = createGenericModuleHook;
|
|
@@ -144,6 +142,35 @@ var createGenericModuleProvider = function (config) {
|
|
|
144
142
|
};
|
|
145
143
|
};
|
|
146
144
|
exports.createGenericModuleProvider = createGenericModuleProvider;
|
|
145
|
+
var createGenericHandlers = function (dispatch) {
|
|
146
|
+
return {
|
|
147
|
+
handleSearch: function (query) {
|
|
148
|
+
dispatch({
|
|
149
|
+
type: exports.GENERIC_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
150
|
+
payload: { searchQuery: query },
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
handlePageChange: function (page) {
|
|
154
|
+
dispatch({
|
|
155
|
+
type: exports.GENERIC_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
156
|
+
payload: { currentPage: page },
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
handlePageLimitChange: function (limit) {
|
|
160
|
+
dispatch({
|
|
161
|
+
type: exports.GENERIC_ACTION_TYPES.SET_PAGE_LIMIT,
|
|
162
|
+
payload: { pageLimit: limit },
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
handleCloseDrawer: function () {
|
|
166
|
+
dispatch({
|
|
167
|
+
type: exports.GENERIC_ACTION_TYPES.SET_DRAWER,
|
|
168
|
+
payload: { drawer: null },
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
exports.createGenericHandlers = createGenericHandlers;
|
|
147
174
|
// ============================================================================
|
|
148
175
|
// MAIN MODULE FACTORY
|
|
149
176
|
// ============================================================================
|
|
@@ -157,6 +184,7 @@ var createGenericModule = function (config) {
|
|
|
157
184
|
config: config,
|
|
158
185
|
actionTypes: exports.GENERIC_ACTION_TYPES,
|
|
159
186
|
initialState: config.initialState,
|
|
187
|
+
createHandlers: exports.createGenericHandlers,
|
|
160
188
|
};
|
|
161
189
|
};
|
|
162
190
|
exports.createGenericModule = createGenericModule;
|