mobigrid-module 1.1.28 → 1.1.35

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.
package/README.md CHANGED
@@ -2,55 +2,204 @@
2
2
 
3
3
  A flexible and customizable data table interface module with advanced filtering, column management, and action handling capabilities.
4
4
 
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install mobigrid-module
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ You can use the `MobigridModule` component by importing it into your React application.
14
+
15
+ ```tsx
16
+ import MobigridModule from 'mobigrid-module';
17
+ import 'mobigrid-module/dist/index.css'; // Import styles if necessary
18
+
19
+ function App() {
20
+ const handlePrint = (row) => {
21
+ console.log('Print ticket:', row.ticket_numbers);
22
+ };
23
+
24
+ const handleRefund = (row) => {
25
+ console.log('Refund transaction:', row.request_id);
26
+ };
27
+
28
+ // Callback to determine if print button should be shown
29
+ const canPrintTicket = (row) => {
30
+ return row.status === 'PAID' && row.canPrint === true;
31
+ };
32
+
33
+ return (
34
+ <MobigridModule
35
+ configUrl="https://api.example.com/config"
36
+ // OR provide configJson directly
37
+ // configJson={myConfigObject}
38
+ dataUrl="https://api.example.com/transactions"
39
+ callbacks={{
40
+ onPrint: handlePrint,
41
+ onRefund: handleRefund,
42
+ checkPrint: canPrintTicket
43
+ }}
44
+ customHeaders={{
45
+ 'Authorization': 'Bearer token123'
46
+ }}
47
+ />
48
+ );
49
+ }
50
+ ```
51
+
52
+ ## Component Props
53
+
54
+ The `MobigridModule` accepts the following props:
55
+
56
+ | Prop | Type | Description |
57
+ |------|------|-------------|
58
+ | `configUrl` | `string` | URL to fetch the configuration JSON from. |
59
+ | `configJson` | `object` | Direct configuration object. Use this or `configUrl`. |
60
+ | `dataUrl` | `string` | URL to fetch the table data from. Overrides `data_url` in config. |
61
+ | `preJsUrl` | `string` | URL to fetch a JavaScript file to execute before rendering (e.g., for global functions). |
62
+ | `preJs` | `string` | Direct JavaScript code string to execute. |
63
+ | `callbacks` | `object` | An object containing functions referenced by action buttons or conditions. |
64
+ | `customHeaders` | `object` | Custom HTTP headers to include in API requests (data and config). |
65
+ | `itemsPerPage` | `number` | Number of items to display per page (default: 14). |
66
+ | `dateFormat` | `string` | Format string for dates in API requests (default: "MM-dd-yyyy HH:mm"). |
67
+ | `children` | `ReactNode` | Child components to render at the bottom of the module. |
68
+
5
69
  ## Configuration Structure
6
70
 
7
- The configuration object defines the structure and behavior of a data table interface. It includes filters, columns, actions, and other settings.
71
+ The configuration object defines the structure of the table, filters, and columns. You can provide this via the `configUrl` endpoint or directly via the `configJson` prop.
72
+
73
+ ### Example Configuration (Payment History)
74
+
75
+ ```json
76
+ {
77
+ "title": "Payment History",
78
+ "data_url": "https://api.example.com/payments",
79
+ "Filters": [
80
+ [
81
+ {
82
+ "type": "Text",
83
+ "name": "request_id",
84
+ "label": "Request ID"
85
+ },
86
+ {
87
+ "type": "Select",
88
+ "name": "status",
89
+ "label": "Status",
90
+ "options": [
91
+ { "label": "Paid", "value": "PAID" },
92
+ { "label": "Failed", "value": "FAILED" }
93
+ ]
94
+ }
95
+ ],
96
+ [
97
+ {
98
+ "type": "Date",
99
+ "name": "fromDate",
100
+ "label": "From Date"
101
+ },
102
+ {
103
+ "type": "Date",
104
+ "name": "toDate",
105
+ "label": "To Date"
106
+ }
107
+ ]
108
+ ],
109
+ "colomns": [
110
+ {
111
+ "title": "Request ID",
112
+ "key": "request_id",
113
+ "type": "text"
114
+ },
115
+ {
116
+ "title": "Date",
117
+ "key": "created_date",
118
+ "type": "date",
119
+ "pattern": "dd/MM/yyyy HH:mm"
120
+ },
121
+ {
122
+ "title": "POS Code",
123
+ "key": "pos_code",
124
+ "type": "text"
125
+ },
126
+ {
127
+ "title": "Amount",
128
+ "key": "amount",
129
+ "type": "money",
130
+ "currency": "MAD"
131
+ },
132
+ {
133
+ "title": "Status",
134
+ "key": "status",
135
+ "type": "status"
136
+ },
137
+ {
138
+ "title": "Actions",
139
+ "key": "ACTIONS_BUTTONS",
140
+ "actions": [
141
+ {
142
+ "label": "Print",
143
+ "icon": "icon-printer",
144
+ "action": "onPrint",
145
+ "condition": "checkPrint"
146
+ }
147
+ ]
148
+ }
149
+ ]
150
+ }
151
+ ```
152
+
153
+ ### Filters Configuration
154
+
155
+ Filters are defined as an array of arrays (rows of filters).
156
+
157
+ - **`type`**: The type of filter. Supported types:
158
+ - `"Text"`: Simple text input.
159
+ - `"Select"`: Dropdown menu. Use `urlSource` for dynamic options or `options` for static ones.
160
+ - `"Date"`: Date picker.
161
+ - **`name`**: The query parameter key that will be sent to the `data_url`.
162
+ - **`label`**: The label displayed for the filter.
163
+ - **`urlSource`**: (For `Select` type) URL to fetch options from. Expects an array of objects `{ label, value }`.
164
+ - **`options`**: (For `Select` type) Static array of options `{ label, value }`.
8
165
 
9
- ### Container Props
166
+ ### Columns Configuration (`colomns`)
10
167
 
11
- The module accepts the following configuration properties:
168
+ Defines the table columns.
12
169
 
13
- - **configUrl**: URL to fetch configuration from
14
- - **preJsUrl**: URL to fetch pre-processing JavaScript
15
- - **configJson**: Direct configuration object (alternative to configUrl)
16
- - **preJs**: Direct pre-processing JavaScript (alternative to preJsUrl)
17
- - **customHeaders**: Custom HTTP headers for API requests
18
- - **itemsPerPage**: Number of items to display per page
19
- - **dateFormat**: Default date format for date fields
20
- - **children**: React child components
170
+ - **`title`**: Header text for the column.
171
+ - **`key`**: The key in the data object to display (e.g., `request_id`, `amount`).
172
+ - **`type`**: formatting type.
173
+ - `"text"`: Default display.
174
+ - `"date"`: Formats date using `pattern` (default: `dd-MM-yyyy`).
175
+ - `"money"`: Formats as currency. Usage: `currency` prop required (e.g., "MAD").
176
+ - `"status"`: Displays a colored badge based on status value (PENDING, PAID, CANCELLED, etc.).
177
+ - `"ACTIONS_BUTTONS"`: Special column for action buttons.
178
+ - **`scroll`**: If true, limits height and adds scrollbar for long content.
21
179
 
22
- ### Main Properties
180
+ ### Actions Configuration
23
181
 
24
- - **title**: The title of the configuration
25
- - **data_url**: API endpoint for fetching data
26
- - **Filters**: Array of filter groups for data filtering
27
- - **columns**: Defines the table columns and their properties
28
- - **extractColumns**: Columns used for data export
29
- - **detailsColumns**: Columns shown in detail view
182
+ For columns with `key: "ACTIONS_BUTTONS"`, you can define an `actions` array.
30
183
 
31
- ### Filter Types
184
+ - **`label`**: Text on the button.
185
+ - **`icon`**: Icon name (referenced from Feather icons, prefixed with `icon-`).
186
+ - **`action`**: The name of the callback function in the `callbacks` prop to execute on click. receives the row data.
187
+ - **`condition`**: (Optional) The name of the callback function in the `callbacks` prop to determine visibility. Receives row data and must return `boolean`.
32
188
 
33
- - **Select**: Dropdown with options (static or dynamic from urlSource)
34
- - **Text**: Basic text input
35
- - **Date**: Date picker input
36
- - **Export**: Export functionality
37
- - **Button**: Action buttons (e.g., search)
189
+ ## Development
38
190
 
39
- ### Column Properties
191
+ To build the project:
40
192
 
41
- - **title**: Column header text
42
- - **key**: Data field identifier
43
- - **type**: Data type (date, money, dropdown, etc.)
44
- - **pattern**: Format pattern (for dates)
45
- - **actions**: Available actions for dropdown columns
193
+ ```bash
194
+ npm run build
195
+ ```
46
196
 
47
- ### Additional Settings
197
+ To deploy (build, version bump, publish, and push):
48
198
 
49
- - **max_diff**: Maximum difference value
50
- - **pagesNum**: Number of pages
51
- - **service_path**: Service implementation path
52
- - **authorized_profiles**: Allowed user profile IDs
53
- - **modal_size**: Size of modal windows
54
- - **components**: Required component names
199
+ ```bash
200
+ # Default bump is patch
201
+ ./deploy.sh
55
202
 
56
- ## Example Configuration
203
+ # Specify bump type
204
+ ./deploy.sh minor
205
+ ```