mobigrid-module 1.1.28 → 1.1.31
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 +170 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,55 +2,187 @@
|
|
|
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 handleEdit = (row) => {
|
|
21
|
+
console.log('Edit row:', row);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const handleDelete = (row) => {
|
|
25
|
+
console.log('Delete row:', row);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const checkEditPermission = (row) => {
|
|
29
|
+
return row.status !== 'LOCKED';
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<MobigridModule
|
|
34
|
+
configUrl="https://api.example.com/config"
|
|
35
|
+
// OR provide configJson directly
|
|
36
|
+
// configJson={myConfigObject}
|
|
37
|
+
dataUrl="https://api.example.com/data"
|
|
38
|
+
callbacks={{
|
|
39
|
+
onEdit: handleEdit,
|
|
40
|
+
onDelete: handleDelete,
|
|
41
|
+
canEdit: checkEditPermission
|
|
42
|
+
}}
|
|
43
|
+
customHeaders={{
|
|
44
|
+
'Authorization': 'Bearer token123'
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Component Props
|
|
52
|
+
|
|
53
|
+
The `MobigridModule` accepts the following props:
|
|
54
|
+
|
|
55
|
+
| Prop | Type | Description |
|
|
56
|
+
|------|------|-------------|
|
|
57
|
+
| `configUrl` | `string` | URL to fetch the configuration JSON from. |
|
|
58
|
+
| `configJson` | `object` | Direct configuration object. Use this or `configUrl`. |
|
|
59
|
+
| `dataUrl` | `string` | URL to fetch the table data from. Overrides `data_url` in config. |
|
|
60
|
+
| `preJsUrl` | `string` | URL to fetch a JavaScript file to execute before rendering (e.g., for global functions). |
|
|
61
|
+
| `preJs` | `string` | Direct JavaScript code string to execute. |
|
|
62
|
+
| `callbacks` | `object` | An object containing functions referenced by action buttons or conditions. |
|
|
63
|
+
| `customHeaders` | `object` | Custom HTTP headers to include in API requests (data and config). |
|
|
64
|
+
| `itemsPerPage` | `number` | Number of items to display per page (default: 14). |
|
|
65
|
+
| `dateFormat` | `string` | Format string for dates in API requests (default: "MM-dd-yyyy HH:mm"). |
|
|
66
|
+
| `children` | `ReactNode` | Child components to render at the bottom of the module. |
|
|
67
|
+
|
|
5
68
|
## Configuration Structure
|
|
6
69
|
|
|
7
|
-
The configuration object defines the structure and
|
|
70
|
+
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.
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"title": "User Management",
|
|
75
|
+
"data_url": "https://api.example.com/users",
|
|
76
|
+
"Filters": [
|
|
77
|
+
[
|
|
78
|
+
{
|
|
79
|
+
"type": "Text",
|
|
80
|
+
"name": "search",
|
|
81
|
+
"label": "Search Users"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"type": "Select",
|
|
85
|
+
"name": "role",
|
|
86
|
+
"label": "Role",
|
|
87
|
+
"urlSource": "https://api.example.com/roles" // Dynamic options
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
{
|
|
92
|
+
"type": "Date",
|
|
93
|
+
"name": "fromDate",
|
|
94
|
+
"label": "From Date"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"type": "Date",
|
|
98
|
+
"name": "toDate",
|
|
99
|
+
"label": "To Date"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
],
|
|
103
|
+
"colomns": [ // Note: spelling is 'colomns' in current version
|
|
104
|
+
{
|
|
105
|
+
"title": "Name",
|
|
106
|
+
"key": "fullName",
|
|
107
|
+
"type": "text"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"title": "Status",
|
|
111
|
+
"key": "status",
|
|
112
|
+
"type": "status"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"title": "Created At",
|
|
116
|
+
"key": "createdAt",
|
|
117
|
+
"type": "date",
|
|
118
|
+
"pattern": "dd/MM/yyyy"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"title": "Actions",
|
|
122
|
+
"key": "ACTIONS_BUTTONS",
|
|
123
|
+
"actions": [
|
|
124
|
+
{
|
|
125
|
+
"label": "Edit",
|
|
126
|
+
"icon": "icon-edit",
|
|
127
|
+
"action": "onEdit",
|
|
128
|
+
"condition": "canEdit"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Filters Configuration
|
|
137
|
+
|
|
138
|
+
Filters are defined as an array of arrays (rows of filters).
|
|
139
|
+
|
|
140
|
+
- **`type`**: The type of filter. Supported types:
|
|
141
|
+
- `"Text"`: Simple text input.
|
|
142
|
+
- `"Select"`: Dropdown menu. Use `urlSource` for dynamic options or `options` for static ones.
|
|
143
|
+
- `"Date"`: Date picker.
|
|
144
|
+
- **`name`**: The query parameter key that will be sent to the `data_url`.
|
|
145
|
+
- **`label`**: The label displayed for the filter.
|
|
146
|
+
- **`urlSource`**: (For `Select` type) URL to fetch options from. Expects an array of objects `{ label, value }`.
|
|
147
|
+
- **`options`**: (For `Select` type) Static array of options `{ label, value }`.
|
|
8
148
|
|
|
9
|
-
###
|
|
149
|
+
### Columns Configuration (`colomns`)
|
|
10
150
|
|
|
11
|
-
|
|
151
|
+
Defines the table columns.
|
|
12
152
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
153
|
+
- **`title`**: Header text for the column.
|
|
154
|
+
- **`key`**: The key in the data object to display.
|
|
155
|
+
- **`type`**: formatting type.
|
|
156
|
+
- `"text"`: Default display.
|
|
157
|
+
- `"date"`: Formats date using `pattern` (default: `dd-MM-yyyy`).
|
|
158
|
+
- `"money"`: Formats as currency. Usage: `currency` prop required.
|
|
159
|
+
- `"status"`: Displays a colored badge based on status value (PENDING, PAID, CANCELLED, etc.).
|
|
160
|
+
- `"ACTIONS_BUTTONS"`: Special column for action buttons.
|
|
161
|
+
- **`scroll`**: If true, limits height and adds scrollbar for long content.
|
|
21
162
|
|
|
22
|
-
###
|
|
163
|
+
### Actions Configuration
|
|
23
164
|
|
|
24
|
-
|
|
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
|
|
165
|
+
For columns with `key: "ACTIONS_BUTTONS"`, you can define an `actions` array.
|
|
30
166
|
|
|
31
|
-
|
|
167
|
+
- **`label`**: Text on the button.
|
|
168
|
+
- **`icon`**: Icon name (referenced from Feather icons, prefixed with `icon-`).
|
|
169
|
+
- **`action`**: The name of the callback function in the `callbacks` prop to execute on click. receives the row data.
|
|
170
|
+
- **`condition`**: (Optional) The name of the callback function in the `callbacks` prop to determine visibility. Receives row data and must return `boolean`.
|
|
32
171
|
|
|
33
|
-
|
|
34
|
-
- **Text**: Basic text input
|
|
35
|
-
- **Date**: Date picker input
|
|
36
|
-
- **Export**: Export functionality
|
|
37
|
-
- **Button**: Action buttons (e.g., search)
|
|
172
|
+
## Development
|
|
38
173
|
|
|
39
|
-
|
|
174
|
+
To build the project:
|
|
40
175
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
- **pattern**: Format pattern (for dates)
|
|
45
|
-
- **actions**: Available actions for dropdown columns
|
|
176
|
+
```bash
|
|
177
|
+
npm run build
|
|
178
|
+
```
|
|
46
179
|
|
|
47
|
-
|
|
180
|
+
To deploy (build, version bump, publish, and push):
|
|
48
181
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- **authorized_profiles**: Allowed user profile IDs
|
|
53
|
-
- **modal_size**: Size of modal windows
|
|
54
|
-
- **components**: Required component names
|
|
182
|
+
```bash
|
|
183
|
+
# Default bump is patch
|
|
184
|
+
./deploy.sh
|
|
55
185
|
|
|
56
|
-
|
|
186
|
+
# Specify bump type
|
|
187
|
+
./deploy.sh minor
|
|
188
|
+
```
|