ui-soxo-bootstrap-core 2.6.1-dev.2 → 2.6.1-dev.20

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.
Files changed (66) hide show
  1. package/core/components/extra-info/extra-info-details.js +2 -2
  2. package/core/components/index.js +2 -11
  3. package/core/components/landing-api/landing-api.js +91 -15
  4. package/core/components/landing-api/landing-api.scss +22 -0
  5. package/core/components/license-management/license-alert.js +97 -0
  6. package/core/lib/Store.js +3 -3
  7. package/core/lib/components/global-header/animations.js +78 -4
  8. package/core/lib/components/global-header/global-header.js +224 -255
  9. package/core/lib/components/global-header/global-header.scss +162 -24
  10. package/core/lib/components/sidemenu/animations.js +84 -2
  11. package/core/lib/components/sidemenu/sidemenu.js +191 -65
  12. package/core/lib/components/sidemenu/sidemenu.scss +221 -14
  13. package/core/lib/elements/basic/country-phone-input/country-phone-input.js +14 -8
  14. package/core/lib/elements/basic/dragabble-wrapper/draggable-wrapper.js +1 -1
  15. package/core/lib/elements/basic/menu-tree/menu-tree.js +26 -13
  16. package/core/lib/models/forms/components/form-creator/form-creator.scss +4 -3
  17. package/core/lib/models/menus/components/menu-list/menu-list.js +424 -467
  18. package/core/lib/models/process/components/process-dashboard/process-dashboard.js +469 -3
  19. package/core/lib/models/process/components/process-dashboard/process-dashboard.scss +4 -0
  20. package/core/lib/pages/change-password/change-password.js +17 -24
  21. package/core/lib/pages/change-password/change-password.scss +45 -48
  22. package/core/lib/pages/login/commnication-mode-selection.js +2 -2
  23. package/core/lib/pages/login/login.js +47 -62
  24. package/core/lib/pages/login/login.scss +9 -0
  25. package/core/lib/pages/login/reset-password.js +17 -17
  26. package/core/lib/pages/login/reset-password.scss +10 -1
  27. package/core/lib/pages/profile/themes.json +4 -4
  28. package/core/lib/utils/api/api.utils.js +30 -18
  29. package/core/lib/utils/common/common.utils.js +49 -35
  30. package/core/lib/utils/http/http.utils.js +2 -1
  31. package/core/lib/utils/index.js +4 -1
  32. package/core/models/base/base.js +7 -3
  33. package/core/models/core-scripts/core-scripts.js +134 -126
  34. package/core/models/doctor/components/doctor-add/doctor-add.js +9 -4
  35. package/core/models/menus/components/menu-add/menu-add.js +1 -1
  36. package/core/models/menus/components/menu-lists/menu-lists.js +53 -54
  37. package/core/models/menus/menus.js +27 -2
  38. package/core/models/roles/components/role-add/role-add.js +92 -59
  39. package/core/models/roles/components/role-list/role-list.js +1 -1
  40. package/core/models/staff/components/staff-add/staff-add.js +20 -32
  41. package/core/models/users/components/assign-role/assign-role.js +145 -50
  42. package/core/models/users/components/assign-role/assign-role.scss +209 -45
  43. package/core/models/users/components/assign-role/avatar-props.js +45 -0
  44. package/core/models/users/components/user-add/user-add.js +46 -55
  45. package/core/models/users/components/user-add/user-edit.js +25 -4
  46. package/core/models/users/users.js +9 -1
  47. package/core/modules/dashboard/components/dashboard-card/menu-dashboard-card.js +1 -1
  48. package/core/modules/reporting/components/reporting-dashboard/README.md +316 -0
  49. package/core/modules/reporting/components/reporting-dashboard/adavance-search/advance-search.js +147 -0
  50. package/core/modules/reporting/components/reporting-dashboard/adavance-search/advance-search.scss +76 -0
  51. package/core/modules/reporting/components/reporting-dashboard/display-columns/build-display-columns.js +90 -0
  52. package/core/modules/reporting/components/reporting-dashboard/display-columns/build-display-columns.test.js +74 -0
  53. package/core/modules/reporting/components/reporting-dashboard/display-columns/display-cell-renderer.js +252 -0
  54. package/core/modules/reporting/components/reporting-dashboard/display-columns/display-cell-renderer.test.js +126 -0
  55. package/core/modules/reporting/components/reporting-dashboard/reporting-dashboard.js +326 -436
  56. package/core/modules/reporting/components/reporting-dashboard/reporting-dashboard.scss +7 -0
  57. package/core/modules/steps/action-buttons.js +33 -15
  58. package/core/modules/steps/action-buttons.scss +55 -9
  59. package/core/modules/steps/chat-assistant.js +141 -0
  60. package/core/modules/steps/openai-realtime.js +275 -0
  61. package/core/modules/steps/readme.md +167 -0
  62. package/core/modules/steps/steps.js +1078 -57
  63. package/core/modules/steps/steps.scss +539 -90
  64. package/core/modules/steps/timeline.js +21 -19
  65. package/core/modules/steps/voice-navigation.js +709 -0
  66. package/package.json +2 -1
@@ -0,0 +1,316 @@
1
+ # Reporting Dashboard
2
+
3
+ This module renders configurable reports using:
4
+ - backend-driven `input_parameters` (filter form)
5
+ - backend-driven `display_columns` (table columns)
6
+ - report data from `CoreScripts.getReportingLisitng(...)`
7
+
8
+ Main component:
9
+ - `core/modules/reporting/components/reporting-dashboard/reporting-dashboard.js`
10
+
11
+ Display column internals:
12
+ - `core/modules/reporting/components/reporting-dashboard/display-columns/build-display-columns.js`
13
+ - `core/modules/reporting/components/reporting-dashboard/display-columns/display-cell-renderer.js`
14
+
15
+ ## Data Flow Overview
16
+
17
+ 1. Dashboard loads `CoreScripts.getRecord({ id, dbPtr })`.
18
+ 2. It parses:
19
+ - `input_parameters` JSON string -> filter form configuration
20
+ - `display_columns` JSON string -> table column configuration
21
+ 3. It submits filter values to `CoreScripts.getReportingLisitng(coreScriptId, formBody, dbPtr)`.
22
+ 4. It renders the table with configured display columns.
23
+
24
+ If `display_columns` is missing, columns are auto-generated from response keys.
25
+
26
+ ## ReportingDashboard Props
27
+
28
+ Common props:
29
+ - `match` / `reportId`: report id source (`reportId` overrides route id)
30
+ - `dbPtr`: db pointer (falls back to `localStorage.db_ptr`)
31
+ - `CustomComponents`: map of reusable custom components
32
+ - `scope`: optional object to override filter payload body
33
+ - `dashBoardIds`: optional cards for dashboard switching
34
+ - `showScanner`: enables QR scanner button
35
+ - `barcodeFilterKey`: field used to match scanned QR value
36
+ - `isFixedIndex`: fixes index `#` column to left
37
+ - `attributes`: JSON string for extra UI controls (for example `buttonAttributes`)
38
+
39
+ ## Input Parameters Configuration
40
+
41
+ `input_parameters` is stored as a JSON string in backend and parsed at runtime.
42
+
43
+ Example:
44
+
45
+ ```json
46
+ [
47
+ {
48
+ "title": "From Date",
49
+ "field": "start",
50
+ "type": "date",
51
+ "default": "startOfDay",
52
+ "required": true
53
+ },
54
+ {
55
+ "title": "To Date",
56
+ "field": "end",
57
+ "type": "date",
58
+ "default": "endOfDay",
59
+ "required": true
60
+ },
61
+ {
62
+ "title": "Department",
63
+ "field": "dept_id",
64
+ "type": "reference-select",
65
+ "modelName": "Department",
66
+ "required": false
67
+ },
68
+ {
69
+ "title": "Status",
70
+ "field": "status",
71
+ "type": "select",
72
+ "options": [
73
+ { "label": "Pending", "value": "Pending" },
74
+ { "label": "Completed", "value": "Completed" }
75
+ ]
76
+ }
77
+ ]
78
+ ```
79
+
80
+ ### Supported default date values
81
+
82
+ For `type: "date"`, supported `default` values:
83
+ - `startOfDay`
84
+ - `endOfDay`
85
+ - `startOfWeek`
86
+ - `endOfWeek`
87
+ - `currentDate`
88
+
89
+ If no date default is provided, current date is used.
90
+
91
+ ### URL synchronization
92
+
93
+ - On load, if URL contains `?field=value`, that value is used over defaults.
94
+ - On submit, active input values are written back to URL query params.
95
+ - Date values are URL-formatted as `YYYY-MM-DD`.
96
+
97
+ ### Hiding input parameter form
98
+
99
+ If `other_details1` JSON includes:
100
+
101
+ ```json
102
+ { "isDisableInputParameters": true }
103
+ ```
104
+
105
+ the input form is hidden, but report data still loads.
106
+
107
+ ## Display Columns Configuration
108
+
109
+ `display_columns` is also a backend JSON string.
110
+
111
+ Each entry maps to one table column.
112
+
113
+ Basic example:
114
+
115
+ ```json
116
+ [
117
+ { "title": "OP No", "field": "opno", "isSortingEnabled": true },
118
+ { "title": "Guest Name", "field": "guest_name", "isFilterEnabled": true },
119
+ { "title": "Amount", "field": "amount", "type": "number", "width": 120 }
120
+ ]
121
+ ```
122
+
123
+ ### Common column keys
124
+
125
+ - `title`: header text
126
+ - `tooltip`: optional header tooltip override
127
+ - `field`: record key to display
128
+ - `width`: numeric width (default `160`)
129
+ - `isFixedColumn`: AntD fixed position (`"left"` / `"right"`)
130
+ - `isFilterEnabled`: generates unique-value filters from table data
131
+ - `isSortingEnabled`: enables string sort on `field`
132
+ - `color`: default text color
133
+ - `type: "number"`: right-aligns cell
134
+
135
+ ## Action Columns (Backward-Compatible Rules)
136
+
137
+ Action logic is intentionally layered to avoid breaking existing reports.
138
+
139
+ Compatibility rules:
140
+ 1. `entry.field === "action"` -> **legacy action** behavior
141
+ 2. else if `entry.type === "action"` -> **new action layer**
142
+ 3. all other types use existing non-action behavior
143
+
144
+ ### Legacy action example (existing reports)
145
+
146
+ ```json
147
+ {
148
+ "title": "Action",
149
+ "field": "action",
150
+ "redirect_link": "/process/@opb_id;",
151
+ "replace_variables": [{ "field": "opb_id" }],
152
+ "display_name_link": "View"
153
+ }
154
+ ```
155
+
156
+ Legacy label behavior:
157
+ - `display_name_link` or `"View"`
158
+
159
+ ### New action layer example (dynamic API label)
160
+
161
+ ```json
162
+ {
163
+ "title": "Action",
164
+ "type": "action",
165
+ "field": "action_text",
166
+ "redirect_link": "/process/@opb_id;",
167
+ "replace_variables": [{ "field": "opb_id" }],
168
+ "label": "View"
169
+ }
170
+ ```
171
+
172
+ New action label fallback order:
173
+ 1. `record[entry.field]` (example: `record.action_text`)
174
+ 2. `entry.label`
175
+ 3. `entry.display_name_link`
176
+ 4. `"View"`
177
+
178
+ ## Other Display Types
179
+
180
+ ### External link column
181
+
182
+ ```json
183
+ { "title": "Report", "field": "report_url", "type": "link" }
184
+ ```
185
+
186
+ Renders anchor with `View` label if URL exists.
187
+
188
+ ### Color tag or span
189
+
190
+ ```json
191
+ { "title": "Status", "field": "status", "enableColor": true, "columnType": "tag" }
192
+ ```
193
+
194
+ or
195
+
196
+ ```json
197
+ { "title": "Status", "field": "status", "enableColor": true, "columnType": "span" }
198
+ ```
199
+
200
+ Uses `record.color_code`.
201
+
202
+ ### Dynamic icon mapping
203
+
204
+ ```json
205
+ {
206
+ "title": "State",
207
+ "field": "state",
208
+ "displayIcons": {
209
+ "Pending": { "icon": "ClockCircleOutlined", "color": "orange", "size": "14px" },
210
+ "Done": { "icon": "CheckCircleOutlined", "color": "green", "size": "14px" }
211
+ }
212
+ }
213
+ ```
214
+
215
+ Icon names are taken from `@ant-design/icons`.
216
+
217
+ ### Custom component column
218
+
219
+ ```json
220
+ {
221
+ "title": "Info",
222
+ "field": "custom",
223
+ "component": "ResultEntryInfo",
224
+ "props": [
225
+ { "field": "description_text", "value": "description" },
226
+ { "field": "opb_id", "value": "opbId" }
227
+ ],
228
+ "config": { "allowEdit": true }
229
+ }
230
+ ```
231
+
232
+ How it resolves:
233
+ - `component` must exist in merged `CustomComponents`
234
+ - each `props` item maps `record[field]` to prop key `value`
235
+ - `config` is spread as static props
236
+ - `callback` prop triggers dashboard `refresh()`
237
+
238
+ ## Redirect Template Variables
239
+
240
+ Action redirects support template replacement in `redirect_link`:
241
+ - placeholder format: `@field;`
242
+ - replacements defined in `replace_variables`
243
+
244
+ Example:
245
+
246
+ ```json
247
+ {
248
+ "redirect_link": "/lab/@opb_id;/visit/@opno;",
249
+ "replace_variables": [{ "field": "opb_id" }, { "field": "opno" }]
250
+ }
251
+ ```
252
+
253
+ With row `{ "opb_id": 12, "opno": "OP-55" }`:
254
+ - result -> `/lab/12/visit/OP-55`
255
+
256
+ ## QR Scanner Behavior
257
+
258
+ When scanner is enabled:
259
+ - scanned value is matched against `patient[barcodeFilterKey]`
260
+ - redirect uses first configured action column with this priority:
261
+ 1. legacy action column (`field === "action"`)
262
+ 2. new action column (`type === "action"`)
263
+
264
+ ## Export Behavior
265
+
266
+ - Export uses current table columns.
267
+ - For `field === "custom"`, export attempts to read the prop mapping where `value === "description"` and exports that source field.
268
+ - Other columns export `record[field]`.
269
+
270
+ ## End-to-End Example
271
+
272
+ `display_columns`:
273
+
274
+ ```json
275
+ [
276
+ { "title": "OP No", "field": "opno", "isSortingEnabled": true, "width": 140 },
277
+ { "title": "Guest", "field": "guest_name", "isFilterEnabled": true, "width": 220 },
278
+ {
279
+ "title": "Status",
280
+ "field": "status",
281
+ "enableColor": true,
282
+ "columnType": "tag"
283
+ },
284
+ {
285
+ "title": "Action",
286
+ "type": "action",
287
+ "field": "action_text",
288
+ "redirect_link": "/process-detail/@opb_id;",
289
+ "replace_variables": [{ "field": "opb_id" }],
290
+ "label": "View"
291
+ }
292
+ ]
293
+ ```
294
+
295
+ Sample API row:
296
+
297
+ ```json
298
+ {
299
+ "opb_id": 1001,
300
+ "opno": "OP-1001",
301
+ "guest_name": "Aisha Rahman",
302
+ "status": "Pending",
303
+ "color_code": "orange",
304
+ "action_text": "Start Consultation"
305
+ }
306
+ ```
307
+
308
+ Rendered action label:
309
+ - `Start Consultation` (dynamic value from API)
310
+
311
+ ## Notes for Developers
312
+
313
+ - Keep `display_columns` as JSON string in DB for backward compatibility.
314
+ - Prefer `type: "action"` for new dynamic action labels.
315
+ - Reserve `field: "action"` for legacy behavior.
316
+ - If adding new display types, implement in `display-cell-renderer.js` and keep order explicit.
@@ -0,0 +1,147 @@
1
+
2
+ import React, { useState, useEffect, useRef } from "react";
3
+ import { Select, Checkbox, Input, Spin } from "antd";
4
+ import { CoreScripts } from "../../../../../models";
5
+ import "./advance-search.scss";
6
+
7
+ const { Search } = Input;
8
+
9
+ export default function AdvancedSearchSelect({ reportId, field, value = [], onChange ,onReset}) {
10
+
11
+ const isSearchQuery = !!field.search_query;
12
+
13
+ const [searchResults, setSearchResults] = useState([]);
14
+ const [selectedItems, setSelectedItems] = useState(value);
15
+ const [loading, setLoading] = useState(false);
16
+ const debounceRef = useRef(null);
17
+
18
+ useEffect(() => {
19
+ setSelectedItems(value);
20
+ }, [value]);
21
+
22
+ const loadOptions = async (searchText = "") => {
23
+ try {
24
+ setLoading(true);
25
+
26
+ const formBody = {
27
+ script_id: reportId,
28
+ search_field: field.field,
29
+ search_condition: searchText,
30
+ };
31
+
32
+ const res = await CoreScripts.getQuerySeacch(formBody);
33
+ const data = Array.isArray(res.data) ? res.data : [];
34
+ const apiValues = data?.map((r) => r[field.field]) || [];
35
+
36
+ setSearchResults(apiValues);
37
+ } catch (error) {
38
+ console.error("Search API error", error);
39
+ } finally {
40
+ setLoading(false);
41
+ }
42
+ };
43
+
44
+ useEffect(() => {
45
+ if (isSearchQuery) loadOptions("");
46
+ }, [field]);
47
+
48
+ const handleSearch = (text) => {
49
+ if (debounceRef.current) clearTimeout(debounceRef.current);
50
+ debounceRef.current = setTimeout(() => loadOptions(text), 400);
51
+ };
52
+
53
+ const toggleValue = (checked, item) => {
54
+ let newValues;
55
+
56
+ if (checked) newValues = [...selectedItems, item];
57
+ else newValues = selectedItems.filter((v) => v !== item);
58
+
59
+ setSelectedItems(newValues);
60
+ onChange(newValues);
61
+ };
62
+
63
+ const handleReset = () => {
64
+ setSelectedItems([]);
65
+ onChange([]);
66
+ // if (onReset) {
67
+ onReset(); // 🔥 trigger dashboard refresh
68
+ // }
69
+ };
70
+
71
+ const displayOptions = [
72
+ ...selectedItems,
73
+ ...searchResults.filter((item) => !selectedItems.includes(item)),
74
+ ];
75
+
76
+ const isActive = value && value.length > 0;
77
+
78
+ // -------- INPUT MODE --------
79
+ if (!isSearchQuery) {
80
+ return (
81
+ <Input
82
+ className={`advanced-search-input ${isActive ? "advanced-search-active" : ""}`}
83
+ placeholder={`Search ${field.caption}`}
84
+ // The parent provides an array for `value`.
85
+ // We take the first element for the input's display value.
86
+ value={value[0] || ""}
87
+ onChange={(e) => {
88
+ const text = e.target.value;
89
+ // Always pass an array back to the parent to be consistent with the Select mode.
90
+ onChange(text ? [text] : []);
91
+ }}
92
+ />
93
+ );
94
+ }
95
+
96
+ // -------- SELECT MODE --------
97
+ return (
98
+ <Select
99
+ className={`advanced-search-select ${isActive ? "advanced-search-active" : ""}`}
100
+ mode="multiple"
101
+ value={value}
102
+ placeholder={field.caption}
103
+ allowClear
104
+ maxTagCount={0}
105
+ onChange={onChange}
106
+ maxTagPlaceholder={() => (
107
+ <span className="tag-placeholder">
108
+ {field.caption}
109
+ <span className="tag-placeholder-count">
110
+ {value?.length || 0}
111
+ </span>
112
+ </span>
113
+ )}
114
+ dropdownRender={() => (
115
+ <div className="dropdown-content">
116
+ <Search
117
+ placeholder={`Search ${field.caption}`}
118
+ onChange={(e) => handleSearch(e.target.value)}
119
+ />
120
+
121
+ <div className="dropdown-options-list">
122
+ {loading ? (
123
+ <Spin />
124
+ ) : (
125
+ displayOptions.map((item) => (
126
+ <div key={item} className="dropdown-option-item">
127
+ <Checkbox
128
+ checked={selectedItems.includes(item)}
129
+ onChange={(e) => toggleValue(e.target.checked, item)}
130
+ >
131
+ {item}
132
+ </Checkbox>
133
+ </div>
134
+ ))
135
+ )}
136
+ </div>
137
+
138
+ <div className="dropdown-footer">
139
+ <span className="dropdown-reset-button" onClick={handleReset}>
140
+ Reset
141
+ </span>
142
+ </div>
143
+ </div>
144
+ )}
145
+ />
146
+ );
147
+ }
@@ -0,0 +1,76 @@
1
+ // .advanced-search-select,
2
+ /* Base select width */
3
+ .advanced-search-select {
4
+ width: 160px;
5
+ }
6
+ .advanced-search-input {
7
+ width: 160px;
8
+ }
9
+ /* Active state (when value selected) */
10
+ .advanced-search-select.advanced-search-active .ant-select-selector {
11
+ border-color: #1677ff !important;
12
+ box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.2) !important;
13
+ border-radius: 6px !important;
14
+ }
15
+
16
+ /* Input active state */
17
+ .advanced-search-input.advanced-search-active {
18
+ border-color: #1677ff !important;
19
+ box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.2);
20
+ border-radius: 6px;
21
+ }
22
+ // .advanced-search-input {
23
+ // width: 250px;
24
+
25
+ // &.advanced-search-active {
26
+ // // Antd Select and Input don't share the same border-radius property,
27
+ // // so we apply a wrapper style that works for both.
28
+ // // For more specific control, you might need to target internal antd classes.
29
+ // border: 1px solid #91caff !important;
30
+ // box-shadow: 0 0 0 1px #91caff;
31
+ // border-radius: 6px;
32
+ // }
33
+ // }
34
+
35
+ .tag-placeholder {
36
+ display: flex;
37
+ align-items: center;
38
+ gap: 8px;
39
+
40
+ .tag-placeholder-count {
41
+ background: #e6f0ff;
42
+ color: #1677ff;
43
+ border-radius: 10px;
44
+ padding: 0 8px;
45
+ font-weight: 600;
46
+ font-size: 12px;
47
+ }
48
+ }
49
+
50
+ .dropdown-content {
51
+ padding: 10px;
52
+
53
+ .dropdown-options-list {
54
+ max-height: 200px;
55
+ overflow-y: auto;
56
+ margin-top: 10px;
57
+
58
+ .dropdown-option-item {
59
+ margin-bottom: 6px;
60
+ }
61
+ }
62
+
63
+ .dropdown-footer {
64
+ display: flex;
65
+ justify-content: flex-end;
66
+ margin-top: 10px;
67
+ border-top: 1px solid #f0f0f0;
68
+ padding-top: 8px;
69
+
70
+ .dropdown-reset-button {
71
+ color: #1677ff;
72
+ cursor: pointer;
73
+ font-weight: 500;
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,90 @@
1
+ import React from 'react';
2
+ import { Tooltip } from 'antd';
3
+ import { renderDisplayCell } from './display-cell-renderer';
4
+
5
+ /**
6
+ * Resolves export value definition for a configured display column.
7
+ *
8
+ * @param {Object} entry
9
+ * @param {Object} record
10
+ * @returns {*}
11
+ */
12
+ function getExportDefinition(entry, record) {
13
+ if (entry.field === 'custom') {
14
+ const description = entry.props?.find((p) => p.value === 'description')?.field;
15
+ return description && record[description] ? record[description] : null;
16
+ }
17
+
18
+ return record[entry.field];
19
+ }
20
+
21
+ /**
22
+ * Builds Ant Design table columns from display column configuration.
23
+ *
24
+ * @param {Object} root0
25
+ * @param {Array} root0.columns
26
+ * @param {Array} root0.patients
27
+ * @param {boolean} root0.isFixedIndex
28
+ * @param {Object.<string, React.ComponentType<any>>} root0.CustomComponents
29
+ * @param {Function} root0.refresh
30
+ * @param {Object} [root0.otherDetails={}] - Optional details from the report configuration.
31
+ * @param {boolean} [root0.otherDetails.isFilterEnabled] - Fallback to enable filtering on all columns.
32
+ * @param {boolean} [root.otherDetails.isSortingEnabled] - Fallback to enable sorting on all columns.
33
+ * @param {boolean} [root0.otherDetails.isHeaderWrapEnabled] - Fallback to enable header text wrapping for all columns.
34
+ * @returns {Array}
35
+ */
36
+ export default function buildDisplayColumns({ columns = [], patients = [], isFixedIndex, CustomComponents, refresh, otherDetails = {} }) {
37
+ const displayColumns = [
38
+ {
39
+ title: '#',
40
+ dataIndex: 'index',
41
+ render: (value, item, index) => index + 1,
42
+ key: 'ColumnIndex',
43
+ fixed: isFixedIndex ? 'left' : null,
44
+ width: 2,
45
+ },
46
+ ];
47
+
48
+ columns.forEach((entry, index) => {
49
+ const isFilterEnabled = entry.isFilterEnabled || otherDetails?.isFilterEnabled;
50
+ const isSortingEnabled = entry.isSortingEnabled || otherDetails?.isSortingEnabled;
51
+ const isHeaderWrapEnabled = otherDetails?.isHeaderWrapEnabled;
52
+
53
+ const titleStyle = isHeaderWrapEnabled ? { whiteSpace: 'pre-wrap', overflowWrap: 'break-word' } : {};
54
+ displayColumns.push({
55
+ render: (record) =>
56
+ renderDisplayCell({
57
+ entry,
58
+ record,
59
+ CustomComponents,
60
+ refresh,
61
+ }),
62
+ field: entry.field,
63
+ title: (
64
+ <Tooltip
65
+ title={entry.tooltip || entry.title}
66
+ overlayInnerStyle={{
67
+ whiteSpace: 'normal',
68
+ overflowWrap: 'break-word',
69
+ }}
70
+ >
71
+ <span style={titleStyle}>{entry.title}</span>
72
+ </Tooltip>
73
+ ),
74
+ key: entry.field || `display_column_${index}`,
75
+ width: entry.width ? parseInt(entry.width, 10) : 160,
76
+ fixed: entry.isFixedColumn ? entry.isFixedColumn : null,
77
+ filters:
78
+ isFilterEnabled && Array.isArray(patients)
79
+ ? [...new Set(patients.map((item) => item[entry.field]).filter(Boolean))].map((value) => ({ text: value, value }))
80
+ : null,
81
+ onFilter: isFilterEnabled ? (value, record) => record[entry.field] === value : null,
82
+ sorter: isSortingEnabled ? (a, b) => String(a[entry.field]).localeCompare(String(b[entry.field])) : null,
83
+ filterSearch: isFilterEnabled ? isFilterEnabled : false,
84
+ exportDefinition: (record) => getExportDefinition(entry, record),
85
+ align: entry.type === 'number' ? 'right' : 'left',
86
+ });
87
+ });
88
+
89
+ return displayColumns;
90
+ }
@@ -0,0 +1,74 @@
1
+ import React from 'react';
2
+ import buildDisplayColumns from './build-display-columns';
3
+
4
+ describe('build-display-columns', () => {
5
+ test('creates index column plus configured columns', () => {
6
+ const columns = buildDisplayColumns({
7
+ columns: [{ title: 'OP NO', field: 'opno' }],
8
+ patients: [{ opno: 'OP-1' }],
9
+ isFixedIndex: true,
10
+ CustomComponents: {},
11
+ refresh: jest.fn(),
12
+ });
13
+
14
+ expect(columns.length).toBe(2);
15
+ expect(columns[0].key).toBe('ColumnIndex');
16
+ expect(columns[0].fixed).toBe('left');
17
+ expect(columns[1].field).toBe('opno');
18
+ });
19
+
20
+ test('preserves legacy action behavior and supports new action dynamic label', () => {
21
+ const refresh = jest.fn();
22
+ const columns = buildDisplayColumns({
23
+ columns: [
24
+ {
25
+ title: 'Legacy Action',
26
+ field: 'action',
27
+ redirect_link: '/legacy/@opb_id;',
28
+ replace_variables: [{ field: 'opb_id' }],
29
+ display_name_link: 'Open',
30
+ },
31
+ {
32
+ title: 'New Action',
33
+ type: 'action',
34
+ field: 'action_text',
35
+ redirect_link: '/new/@opb_id;',
36
+ replace_variables: [{ field: 'opb_id' }],
37
+ label: 'Fallback',
38
+ },
39
+ ],
40
+ patients: [{ opb_id: 10, action: 'Should not replace legacy label', action_text: 'Review' }],
41
+ isFixedIndex: false,
42
+ CustomComponents: {},
43
+ refresh,
44
+ });
45
+
46
+ const row = { opb_id: 10, action: 'Should not replace legacy label', action_text: 'Review' };
47
+
48
+ const legacyElement = columns[1].render(row);
49
+ const newLayerElement = columns[2].render(row);
50
+
51
+ expect(legacyElement.props.children).toBe('Open');
52
+ expect(newLayerElement.props.children).toBe('Review');
53
+ });
54
+
55
+ test('custom exportDefinition returns mapped description field value', () => {
56
+ const columns = buildDisplayColumns({
57
+ columns: [
58
+ {
59
+ title: 'Info',
60
+ field: 'custom',
61
+ props: [{ field: 'status_text', value: 'description' }],
62
+ },
63
+ ],
64
+ patients: [],
65
+ isFixedIndex: false,
66
+ CustomComponents: {},
67
+ refresh: jest.fn(),
68
+ });
69
+
70
+ const exportValue = columns[1].exportDefinition({ status_text: 'Ready' });
71
+ expect(exportValue).toBe('Ready');
72
+ });
73
+ });
74
+