@apexcura/ui-components 0.0.12-Beta3 → 0.0.12-Beta31
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/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +152 -44
- package/dist/index.mjs +157 -49
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
|
|
3
3
|
type ElementType = {
|
|
4
|
+
selectedStyle: boolean;
|
|
5
|
+
style: boolean;
|
|
6
|
+
className: string | undefined;
|
|
4
7
|
placeholder?: string;
|
|
5
8
|
addonBefore?: React.ReactNode;
|
|
6
9
|
defaultValue?: string;
|
|
7
10
|
disabled?: boolean;
|
|
8
11
|
prefix?: React.ReactNode;
|
|
9
12
|
type?: string;
|
|
10
|
-
value?: string | number | boolean | any[];
|
|
13
|
+
value?: string | number | boolean | any[] | null;
|
|
11
14
|
status?: "error" | "warning";
|
|
12
15
|
styles?: React.CSSProperties;
|
|
13
16
|
classNames?: string;
|
|
@@ -17,12 +20,16 @@ type ElementType = {
|
|
|
17
20
|
suffix?: React.ReactNode;
|
|
18
21
|
maxLength?: number;
|
|
19
22
|
fieldNames?: any[];
|
|
23
|
+
options?: any[];
|
|
20
24
|
onChange?: (value: string | number | boolean | any[]) => void;
|
|
21
25
|
dropDownOptions?: any[];
|
|
22
26
|
id?: number;
|
|
23
27
|
thead?: any[];
|
|
24
28
|
tbody?: any[];
|
|
25
29
|
variable_data?: any[];
|
|
30
|
+
optionType?: string;
|
|
31
|
+
selectedClassName?: string;
|
|
32
|
+
action?: React.MouseEventHandler<HTMLElement> | string;
|
|
26
33
|
};
|
|
27
34
|
|
|
28
35
|
interface ElementExecuterProps$3 extends ElementType {
|
|
@@ -67,7 +74,7 @@ declare const SingleSelectElement: (props: ElementType) => React$1.JSX.Element;
|
|
|
67
74
|
|
|
68
75
|
declare const MultipleSelectElement: (props: ElementType) => React$1.JSX.Element;
|
|
69
76
|
|
|
70
|
-
declare const ButtonElement: () => React$1.JSX.Element;
|
|
77
|
+
declare const ButtonElement: (props: ElementType) => React$1.JSX.Element;
|
|
71
78
|
|
|
72
79
|
declare const AddMoreTable: (props: ElementType) => React$1.JSX.Element;
|
|
73
80
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
|
|
3
3
|
type ElementType = {
|
|
4
|
+
selectedStyle: boolean;
|
|
5
|
+
style: boolean;
|
|
6
|
+
className: string | undefined;
|
|
4
7
|
placeholder?: string;
|
|
5
8
|
addonBefore?: React.ReactNode;
|
|
6
9
|
defaultValue?: string;
|
|
7
10
|
disabled?: boolean;
|
|
8
11
|
prefix?: React.ReactNode;
|
|
9
12
|
type?: string;
|
|
10
|
-
value?: string | number | boolean | any[];
|
|
13
|
+
value?: string | number | boolean | any[] | null;
|
|
11
14
|
status?: "error" | "warning";
|
|
12
15
|
styles?: React.CSSProperties;
|
|
13
16
|
classNames?: string;
|
|
@@ -17,12 +20,16 @@ type ElementType = {
|
|
|
17
20
|
suffix?: React.ReactNode;
|
|
18
21
|
maxLength?: number;
|
|
19
22
|
fieldNames?: any[];
|
|
23
|
+
options?: any[];
|
|
20
24
|
onChange?: (value: string | number | boolean | any[]) => void;
|
|
21
25
|
dropDownOptions?: any[];
|
|
22
26
|
id?: number;
|
|
23
27
|
thead?: any[];
|
|
24
28
|
tbody?: any[];
|
|
25
29
|
variable_data?: any[];
|
|
30
|
+
optionType?: string;
|
|
31
|
+
selectedClassName?: string;
|
|
32
|
+
action?: React.MouseEventHandler<HTMLElement> | string;
|
|
26
33
|
};
|
|
27
34
|
|
|
28
35
|
interface ElementExecuterProps$3 extends ElementType {
|
|
@@ -67,7 +74,7 @@ declare const SingleSelectElement: (props: ElementType) => React$1.JSX.Element;
|
|
|
67
74
|
|
|
68
75
|
declare const MultipleSelectElement: (props: ElementType) => React$1.JSX.Element;
|
|
69
76
|
|
|
70
|
-
declare const ButtonElement: () => React$1.JSX.Element;
|
|
77
|
+
declare const ButtonElement: (props: ElementType) => React$1.JSX.Element;
|
|
71
78
|
|
|
72
79
|
declare const AddMoreTable: (props: ElementType) => React$1.JSX.Element;
|
|
73
80
|
|
package/dist/index.js
CHANGED
|
@@ -115,7 +115,6 @@ var NumberElement = (props) => {
|
|
|
115
115
|
prefix: props.prefix,
|
|
116
116
|
type: props.type,
|
|
117
117
|
status: props.status,
|
|
118
|
-
style: props.styles,
|
|
119
118
|
className: props.classNames,
|
|
120
119
|
variant: props.variant,
|
|
121
120
|
name: props.name,
|
|
@@ -138,7 +137,6 @@ var TextareaElement = (props) => {
|
|
|
138
137
|
disabled: props.disabled,
|
|
139
138
|
id: props.name,
|
|
140
139
|
status: props.status,
|
|
141
|
-
style: props.styles,
|
|
142
140
|
className: props.classNames,
|
|
143
141
|
variant: props.variant,
|
|
144
142
|
name: props.name,
|
|
@@ -188,14 +186,47 @@ var SelectElement = (props) => {
|
|
|
188
186
|
var import_react6 = __toESM(require("react"));
|
|
189
187
|
var import_antd6 = require("antd");
|
|
190
188
|
var RadioElement = (props) => {
|
|
189
|
+
const [isDisabled, setIsDisabled] = (0, import_react6.useState)(props.disabled);
|
|
190
|
+
const [selectedValue, setSelectedValue] = (0, import_react6.useState)(props.value);
|
|
191
|
+
let optionType;
|
|
192
|
+
if (props.optionType === "button") {
|
|
193
|
+
optionType = props.optionType;
|
|
194
|
+
}
|
|
195
|
+
(0, import_react6.useEffect)(() => {
|
|
196
|
+
setIsDisabled(props.disabled);
|
|
197
|
+
}, [props.disabled]);
|
|
191
198
|
const handleChange = (e) => {
|
|
199
|
+
const selectedVal = e.target.value;
|
|
200
|
+
const selectedOptions = [{ id: selectedVal, value: selectedVal }];
|
|
201
|
+
setSelectedValue(selectedVal);
|
|
202
|
+
setIsDisabled(true);
|
|
192
203
|
if (props.onChange) {
|
|
193
|
-
const selectedVal = e.target.value;
|
|
194
|
-
const selectedOptions = [{ id: selectedVal, value: selectedVal }];
|
|
195
204
|
props.onChange(selectedOptions);
|
|
196
205
|
}
|
|
197
206
|
};
|
|
198
|
-
|
|
207
|
+
const getButtonStyle = (option) => {
|
|
208
|
+
return selectedValue === option.value ? option.selectedClassName : option.className;
|
|
209
|
+
};
|
|
210
|
+
return /* @__PURE__ */ import_react6.default.createElement(
|
|
211
|
+
import_antd6.Radio.Group,
|
|
212
|
+
{
|
|
213
|
+
onChange: handleChange,
|
|
214
|
+
optionType,
|
|
215
|
+
className: props.className ? props.className : "",
|
|
216
|
+
value: selectedValue
|
|
217
|
+
},
|
|
218
|
+
props.options && props.options.map((option) => /* @__PURE__ */ import_react6.default.createElement(
|
|
219
|
+
import_antd6.Radio,
|
|
220
|
+
{
|
|
221
|
+
key: option.value,
|
|
222
|
+
value: option.value,
|
|
223
|
+
disabled: isDisabled && selectedValue !== option.value,
|
|
224
|
+
className: getButtonStyle(option),
|
|
225
|
+
style: { pointerEvents: isDisabled && selectedValue !== option.value ? "none" : "auto" }
|
|
226
|
+
},
|
|
227
|
+
option.label
|
|
228
|
+
))
|
|
229
|
+
);
|
|
199
230
|
};
|
|
200
231
|
|
|
201
232
|
// src/Components/Checkbox.tsx
|
|
@@ -356,64 +387,141 @@ var MultipleSelectElement = (props) => {
|
|
|
356
387
|
// src/Components/Button.tsx
|
|
357
388
|
var import_react12 = __toESM(require("react"));
|
|
358
389
|
var import_antd10 = require("antd");
|
|
359
|
-
var ButtonElement = () =>
|
|
390
|
+
var ButtonElement = (props) => {
|
|
391
|
+
const handleClick = typeof props.action === "string" ? () => {
|
|
392
|
+
console.log("Performing action:", props.action);
|
|
393
|
+
} : props.action;
|
|
394
|
+
return /* @__PURE__ */ import_react12.default.createElement(import_antd10.Flex, null, /* @__PURE__ */ import_react12.default.createElement(import_antd10.Button, { onClick: handleClick, className: props.className }, props.label));
|
|
395
|
+
};
|
|
360
396
|
|
|
361
397
|
// src/Components/AddMoreTable.tsx
|
|
362
398
|
var import_react13 = __toESM(require("react"));
|
|
363
399
|
var import_antd11 = require("antd");
|
|
400
|
+
var import_icons2 = require("@ant-design/icons");
|
|
364
401
|
var AddMoreTable = (props) => {
|
|
365
402
|
const { thead, tbody } = props;
|
|
366
|
-
const [
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
403
|
+
const [rows, setRows] = (0, import_react13.useState)(tbody || []);
|
|
404
|
+
const onHandleRows = () => {
|
|
405
|
+
const newId = rows.length > 0 ? rows[rows.length - 1].id + 1 : 1;
|
|
406
|
+
let newRow = {
|
|
407
|
+
id: newId,
|
|
408
|
+
label: "Medicine",
|
|
409
|
+
name: "Medicine",
|
|
410
|
+
type: "text",
|
|
411
|
+
variable_data: [
|
|
412
|
+
{
|
|
413
|
+
id: 1,
|
|
414
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
415
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
416
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
417
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
418
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
419
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
420
|
+
SubRows: { delete: "delete", add: "plus" }
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
};
|
|
424
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
370
425
|
};
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
426
|
+
const onHandleDelete = (id) => {
|
|
427
|
+
setRows((prevRows) => prevRows.filter((row) => row.id !== id));
|
|
428
|
+
};
|
|
429
|
+
const onHandleSubRowsAdd = (rowIndex) => {
|
|
430
|
+
setRows((prevRows) => {
|
|
431
|
+
return prevRows.map((row, index) => {
|
|
432
|
+
if (index === rowIndex) {
|
|
433
|
+
const newSubRow = {
|
|
434
|
+
id: row.variable_data.length + 1,
|
|
435
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
436
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
437
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
438
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
439
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
440
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
441
|
+
SubRows: { delete: "delete", add: "plus" }
|
|
442
|
+
};
|
|
443
|
+
const updatedVariableData = [...row.variable_data, newSubRow];
|
|
444
|
+
return {
|
|
445
|
+
...row,
|
|
446
|
+
variable_data: updatedVariableData
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
return row;
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
const onHandleSubRowsDelete = (rowIndex, subIndex) => {
|
|
454
|
+
setRows((prevRows) => {
|
|
455
|
+
return prevRows.map((row, index) => {
|
|
456
|
+
if (index === rowIndex) {
|
|
457
|
+
const updatedVariableData = row.variable_data.filter((_, i) => i !== subIndex);
|
|
458
|
+
return {
|
|
459
|
+
...row,
|
|
460
|
+
variable_data: updatedVariableData
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
return row;
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
};
|
|
467
|
+
(0, import_react13.useEffect)(() => {
|
|
468
|
+
console.log(rows);
|
|
469
|
+
}, [rows]);
|
|
470
|
+
const renderInputElement = (element, value) => {
|
|
471
|
+
if (!element)
|
|
472
|
+
return null;
|
|
377
473
|
const { element: type, label } = element;
|
|
378
|
-
console.log("type....", type);
|
|
379
474
|
if (type === "single-select") {
|
|
380
|
-
return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (
|
|
475
|
+
return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value2) => console.log(label, value2), optionType: "", className: void 0, selectedStyle: false, style: false });
|
|
381
476
|
} else if (type === "textarea") {
|
|
382
|
-
return /* @__PURE__ */ import_react13.default.createElement(TextareaElement, { onChange: (
|
|
477
|
+
return /* @__PURE__ */ import_react13.default.createElement(TextareaElement, { onChange: (value2) => console.log(label, value2), optionType: "", className: void 0, selectedStyle: false, style: false });
|
|
383
478
|
} else {
|
|
384
479
|
return null;
|
|
385
480
|
}
|
|
386
481
|
};
|
|
387
|
-
const dataSource =
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
console.error(`Invalid element in row ${index}:`, curr);
|
|
396
|
-
return acc;
|
|
397
|
-
}
|
|
398
|
-
acc[curr.label] = renderInputElement(curr);
|
|
399
|
-
return acc;
|
|
400
|
-
}, {}) : {};
|
|
401
|
-
return {
|
|
402
|
-
key: index.toString(),
|
|
403
|
-
...eachRow,
|
|
404
|
-
...rowElements,
|
|
405
|
-
...variableData
|
|
482
|
+
const dataSource = rows.map((eachRow, rowIndex) => {
|
|
483
|
+
const rowData = {
|
|
484
|
+
key: eachRow.id,
|
|
485
|
+
"#": rowIndex + 1,
|
|
486
|
+
"Medicine": renderInputElement({
|
|
487
|
+
element: eachRow.element,
|
|
488
|
+
label: eachRow.label
|
|
489
|
+
})
|
|
406
490
|
};
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
491
|
+
rowData["Medicine"] = renderInputElement(eachRow.variable_data[0].Medicine);
|
|
492
|
+
eachRow.variable_data.map((variable, subIndex) => {
|
|
493
|
+
Object.keys(variable).forEach((key) => {
|
|
494
|
+
if (key === "SubRows") {
|
|
495
|
+
rowData[`${key}`] = /* @__PURE__ */ import_react13.default.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleSubRowsDelete(rowIndex, subIndex) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleSubRowsAdd(rowIndex) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
|
|
496
|
+
} else {
|
|
497
|
+
rowData[`${key}`] = renderInputElement(variable[key]);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
rowData.actions = /* @__PURE__ */ import_react13.default.createElement("div", null, /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), rowIndex === rows.length - 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: onHandleRows }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
|
|
502
|
+
return rowData;
|
|
503
|
+
});
|
|
504
|
+
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
505
|
+
title: eachHeadEl.label,
|
|
506
|
+
dataIndex: eachHeadEl.name,
|
|
507
|
+
key: eachHeadEl.id
|
|
508
|
+
})) : [];
|
|
509
|
+
if (!columns.some((col) => col.dataIndex === "actions")) {
|
|
510
|
+
columns.push({
|
|
511
|
+
title: "Actions",
|
|
512
|
+
dataIndex: "actions",
|
|
513
|
+
key: "actions"
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return /* @__PURE__ */ import_react13.default.createElement(
|
|
410
517
|
import_antd11.Table,
|
|
411
518
|
{
|
|
412
519
|
columns,
|
|
413
|
-
|
|
414
|
-
|
|
520
|
+
dataSource,
|
|
521
|
+
pagination: false,
|
|
522
|
+
bordered: true
|
|
415
523
|
}
|
|
416
|
-
)
|
|
524
|
+
);
|
|
417
525
|
};
|
|
418
526
|
// Annotate the CommonJS export names for ESM import in node:
|
|
419
527
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -68,7 +68,6 @@ var NumberElement = (props) => {
|
|
|
68
68
|
prefix: props.prefix,
|
|
69
69
|
type: props.type,
|
|
70
70
|
status: props.status,
|
|
71
|
-
style: props.styles,
|
|
72
71
|
className: props.classNames,
|
|
73
72
|
variant: props.variant,
|
|
74
73
|
name: props.name,
|
|
@@ -91,7 +90,6 @@ var TextareaElement = (props) => {
|
|
|
91
90
|
disabled: props.disabled,
|
|
92
91
|
id: props.name,
|
|
93
92
|
status: props.status,
|
|
94
|
-
style: props.styles,
|
|
95
93
|
className: props.classNames,
|
|
96
94
|
variant: props.variant,
|
|
97
95
|
name: props.name,
|
|
@@ -138,27 +136,60 @@ var SelectElement = (props) => {
|
|
|
138
136
|
};
|
|
139
137
|
|
|
140
138
|
// src/Components/RadioElement.tsx
|
|
141
|
-
import React6 from "react";
|
|
139
|
+
import React6, { useState as useState2, useEffect } from "react";
|
|
142
140
|
import { Radio } from "antd";
|
|
143
141
|
var RadioElement = (props) => {
|
|
142
|
+
const [isDisabled, setIsDisabled] = useState2(props.disabled);
|
|
143
|
+
const [selectedValue, setSelectedValue] = useState2(props.value);
|
|
144
|
+
let optionType;
|
|
145
|
+
if (props.optionType === "button") {
|
|
146
|
+
optionType = props.optionType;
|
|
147
|
+
}
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
setIsDisabled(props.disabled);
|
|
150
|
+
}, [props.disabled]);
|
|
144
151
|
const handleChange = (e) => {
|
|
152
|
+
const selectedVal = e.target.value;
|
|
153
|
+
const selectedOptions = [{ id: selectedVal, value: selectedVal }];
|
|
154
|
+
setSelectedValue(selectedVal);
|
|
155
|
+
setIsDisabled(true);
|
|
145
156
|
if (props.onChange) {
|
|
146
|
-
const selectedVal = e.target.value;
|
|
147
|
-
const selectedOptions = [{ id: selectedVal, value: selectedVal }];
|
|
148
157
|
props.onChange(selectedOptions);
|
|
149
158
|
}
|
|
150
159
|
};
|
|
151
|
-
|
|
160
|
+
const getButtonStyle = (option) => {
|
|
161
|
+
return selectedValue === option.value ? option.selectedClassName : option.className;
|
|
162
|
+
};
|
|
163
|
+
return /* @__PURE__ */ React6.createElement(
|
|
164
|
+
Radio.Group,
|
|
165
|
+
{
|
|
166
|
+
onChange: handleChange,
|
|
167
|
+
optionType,
|
|
168
|
+
className: props.className ? props.className : "",
|
|
169
|
+
value: selectedValue
|
|
170
|
+
},
|
|
171
|
+
props.options && props.options.map((option) => /* @__PURE__ */ React6.createElement(
|
|
172
|
+
Radio,
|
|
173
|
+
{
|
|
174
|
+
key: option.value,
|
|
175
|
+
value: option.value,
|
|
176
|
+
disabled: isDisabled && selectedValue !== option.value,
|
|
177
|
+
className: getButtonStyle(option),
|
|
178
|
+
style: { pointerEvents: isDisabled && selectedValue !== option.value ? "none" : "auto" }
|
|
179
|
+
},
|
|
180
|
+
option.label
|
|
181
|
+
))
|
|
182
|
+
);
|
|
152
183
|
};
|
|
153
184
|
|
|
154
185
|
// src/Components/Checkbox.tsx
|
|
155
|
-
import React7, { useState as
|
|
186
|
+
import React7, { useState as useState3 } from "react";
|
|
156
187
|
import { Checkbox, Divider } from "antd";
|
|
157
188
|
var CheckboxGroup = Checkbox.Group;
|
|
158
189
|
var plainOptions = ["Apple", "Pear", "Orange"];
|
|
159
190
|
var defaultCheckedList = [];
|
|
160
191
|
var CheckboxElement = (props) => {
|
|
161
|
-
const [checkedList, setCheckedList] =
|
|
192
|
+
const [checkedList, setCheckedList] = useState3(defaultCheckedList);
|
|
162
193
|
const checkAll = plainOptions.length === checkedList.length;
|
|
163
194
|
const handleChange = (list) => {
|
|
164
195
|
setCheckedList(list);
|
|
@@ -309,64 +340,141 @@ var MultipleSelectElement = (props) => {
|
|
|
309
340
|
// src/Components/Button.tsx
|
|
310
341
|
import React11 from "react";
|
|
311
342
|
import { Button as Button2, Flex as Flex2 } from "antd";
|
|
312
|
-
var ButtonElement = () =>
|
|
343
|
+
var ButtonElement = (props) => {
|
|
344
|
+
const handleClick = typeof props.action === "string" ? () => {
|
|
345
|
+
console.log("Performing action:", props.action);
|
|
346
|
+
} : props.action;
|
|
347
|
+
return /* @__PURE__ */ React11.createElement(Flex2, null, /* @__PURE__ */ React11.createElement(Button2, { onClick: handleClick, className: props.className }, props.label));
|
|
348
|
+
};
|
|
313
349
|
|
|
314
350
|
// src/Components/AddMoreTable.tsx
|
|
315
|
-
import React12, { useState as
|
|
316
|
-
import { Table } from "antd";
|
|
351
|
+
import React12, { useEffect as useEffect2, useState as useState4 } from "react";
|
|
352
|
+
import { Table, Button as Button3 } from "antd";
|
|
353
|
+
import { PlusOutlined, DeleteOutlined } from "@ant-design/icons";
|
|
317
354
|
var AddMoreTable = (props) => {
|
|
318
355
|
const { thead, tbody } = props;
|
|
319
|
-
const [
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
356
|
+
const [rows, setRows] = useState4(tbody || []);
|
|
357
|
+
const onHandleRows = () => {
|
|
358
|
+
const newId = rows.length > 0 ? rows[rows.length - 1].id + 1 : 1;
|
|
359
|
+
let newRow = {
|
|
360
|
+
id: newId,
|
|
361
|
+
label: "Medicine",
|
|
362
|
+
name: "Medicine",
|
|
363
|
+
type: "text",
|
|
364
|
+
variable_data: [
|
|
365
|
+
{
|
|
366
|
+
id: 1,
|
|
367
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
368
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
369
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
370
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
371
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
372
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
373
|
+
SubRows: { delete: "delete", add: "plus" }
|
|
374
|
+
}
|
|
375
|
+
]
|
|
376
|
+
};
|
|
377
|
+
setRows((prevData) => [...prevData, newRow]);
|
|
323
378
|
};
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
379
|
+
const onHandleDelete = (id) => {
|
|
380
|
+
setRows((prevRows) => prevRows.filter((row) => row.id !== id));
|
|
381
|
+
};
|
|
382
|
+
const onHandleSubRowsAdd = (rowIndex) => {
|
|
383
|
+
setRows((prevRows) => {
|
|
384
|
+
return prevRows.map((row, index) => {
|
|
385
|
+
if (index === rowIndex) {
|
|
386
|
+
const newSubRow = {
|
|
387
|
+
id: row.variable_data.length + 1,
|
|
388
|
+
Route: { label: "Route", element: "single-select", type: "text" },
|
|
389
|
+
Dose: { label: "Dose", element: "single-select", type: "text" },
|
|
390
|
+
Frequency: { label: "Frequency", element: "single-select", type: "text" },
|
|
391
|
+
When: { label: "When", element: "textarea", type: "text" },
|
|
392
|
+
Duration: { label: "Duration", element: "textarea", type: "text" },
|
|
393
|
+
Instructions: { label: "Instructions", element: "textarea", type: "text" },
|
|
394
|
+
SubRows: { delete: "delete", add: "plus" }
|
|
395
|
+
};
|
|
396
|
+
const updatedVariableData = [...row.variable_data, newSubRow];
|
|
397
|
+
return {
|
|
398
|
+
...row,
|
|
399
|
+
variable_data: updatedVariableData
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
return row;
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
const onHandleSubRowsDelete = (rowIndex, subIndex) => {
|
|
407
|
+
setRows((prevRows) => {
|
|
408
|
+
return prevRows.map((row, index) => {
|
|
409
|
+
if (index === rowIndex) {
|
|
410
|
+
const updatedVariableData = row.variable_data.filter((_, i) => i !== subIndex);
|
|
411
|
+
return {
|
|
412
|
+
...row,
|
|
413
|
+
variable_data: updatedVariableData
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return row;
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
useEffect2(() => {
|
|
421
|
+
console.log(rows);
|
|
422
|
+
}, [rows]);
|
|
423
|
+
const renderInputElement = (element, value) => {
|
|
424
|
+
if (!element)
|
|
425
|
+
return null;
|
|
330
426
|
const { element: type, label } = element;
|
|
331
|
-
console.log("type....", type);
|
|
332
427
|
if (type === "single-select") {
|
|
333
|
-
return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (
|
|
428
|
+
return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value2) => console.log(label, value2), optionType: "", className: void 0, selectedStyle: false, style: false });
|
|
334
429
|
} else if (type === "textarea") {
|
|
335
|
-
return /* @__PURE__ */ React12.createElement(TextareaElement, { onChange: (
|
|
430
|
+
return /* @__PURE__ */ React12.createElement(TextareaElement, { onChange: (value2) => console.log(label, value2), optionType: "", className: void 0, selectedStyle: false, style: false });
|
|
336
431
|
} else {
|
|
337
432
|
return null;
|
|
338
433
|
}
|
|
339
434
|
};
|
|
340
|
-
const dataSource =
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
console.error(`Invalid element in row ${index}:`, curr);
|
|
349
|
-
return acc;
|
|
350
|
-
}
|
|
351
|
-
acc[curr.label] = renderInputElement(curr);
|
|
352
|
-
return acc;
|
|
353
|
-
}, {}) : {};
|
|
354
|
-
return {
|
|
355
|
-
key: index.toString(),
|
|
356
|
-
...eachRow,
|
|
357
|
-
...rowElements,
|
|
358
|
-
...variableData
|
|
435
|
+
const dataSource = rows.map((eachRow, rowIndex) => {
|
|
436
|
+
const rowData = {
|
|
437
|
+
key: eachRow.id,
|
|
438
|
+
"#": rowIndex + 1,
|
|
439
|
+
"Medicine": renderInputElement({
|
|
440
|
+
element: eachRow.element,
|
|
441
|
+
label: eachRow.label
|
|
442
|
+
})
|
|
359
443
|
};
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
444
|
+
rowData["Medicine"] = renderInputElement(eachRow.variable_data[0].Medicine);
|
|
445
|
+
eachRow.variable_data.map((variable, subIndex) => {
|
|
446
|
+
Object.keys(variable).forEach((key) => {
|
|
447
|
+
if (key === "SubRows") {
|
|
448
|
+
rowData[`${key}`] = /* @__PURE__ */ React12.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsDelete(rowIndex, subIndex) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsAdd(rowIndex) }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
|
|
449
|
+
} else {
|
|
450
|
+
rowData[`${key}`] = renderInputElement(variable[key]);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
rowData.actions = /* @__PURE__ */ React12.createElement("div", null, /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), rowIndex === rows.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: onHandleRows }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
|
|
455
|
+
return rowData;
|
|
456
|
+
});
|
|
457
|
+
const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
|
|
458
|
+
title: eachHeadEl.label,
|
|
459
|
+
dataIndex: eachHeadEl.name,
|
|
460
|
+
key: eachHeadEl.id
|
|
461
|
+
})) : [];
|
|
462
|
+
if (!columns.some((col) => col.dataIndex === "actions")) {
|
|
463
|
+
columns.push({
|
|
464
|
+
title: "Actions",
|
|
465
|
+
dataIndex: "actions",
|
|
466
|
+
key: "actions"
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return /* @__PURE__ */ React12.createElement(
|
|
363
470
|
Table,
|
|
364
471
|
{
|
|
365
472
|
columns,
|
|
366
|
-
|
|
367
|
-
|
|
473
|
+
dataSource,
|
|
474
|
+
pagination: false,
|
|
475
|
+
bordered: true
|
|
368
476
|
}
|
|
369
|
-
)
|
|
477
|
+
);
|
|
370
478
|
};
|
|
371
479
|
export {
|
|
372
480
|
AddMoreTable,
|