@apexcura/ui-components 0.0.11-Beta4 → 0.0.11-Beta41

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 CHANGED
@@ -22,6 +22,7 @@ type ElementType = {
22
22
  id?: number;
23
23
  thead?: any[];
24
24
  tbody?: any[];
25
+ variable_data?: any[];
25
26
  };
26
27
 
27
28
  interface ElementExecuterProps$3 extends ElementType {
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ type ElementType = {
22
22
  id?: number;
23
23
  thead?: any[];
24
24
  tbody?: any[];
25
+ variable_data?: any[];
25
26
  };
26
27
 
27
28
  interface ElementExecuterProps$3 extends ElementType {
package/dist/index.js CHANGED
@@ -361,26 +361,106 @@ var ButtonElement = () => /* @__PURE__ */ import_react12.default.createElement(i
361
361
  // src/Components/AddMoreTable.tsx
362
362
  var import_react13 = __toESM(require("react"));
363
363
  var import_antd11 = require("antd");
364
+ var import_icons2 = require("@ant-design/icons");
364
365
  var AddMoreTable = (props) => {
365
366
  const { thead, tbody } = props;
367
+ const [tableData, setTableData] = (0, import_react13.useState)({});
368
+ const [rows, setRows] = (0, import_react13.useState)(tbody || []);
369
+ function isColumnType(column) {
370
+ return column.dataIndex !== void 0;
371
+ }
372
+ const onHandleChange = (name, value) => {
373
+ setTableData((prev) => ({ ...prev, [name]: value }));
374
+ console.log(tableData);
375
+ };
376
+ const onHandleRows = () => {
377
+ const lastRow = rows[rows.length - 1];
378
+ const newId = lastRow ? lastRow.id + 1 : 1;
379
+ let newRow = {
380
+ ...lastRow,
381
+ id: newId
382
+ };
383
+ setRows((prevData) => [...prevData, newRow]);
384
+ };
385
+ const onHandleDelete = (index) => {
386
+ if (rows.length > 1) {
387
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
388
+ setRows(remainingRows);
389
+ }
390
+ };
391
+ const onHandleSubRowsAdd = (rowIndex) => {
392
+ setRows((prevRows) => {
393
+ return prevRows.map((row, index) => {
394
+ if (index === rowIndex) {
395
+ const newSubRow = {
396
+ id: row.variable_data.length + 1,
397
+ Route: { label: "Route", element: "single-select", type: "text" },
398
+ Dose: { label: "Dose", element: "single-select", type: "text" },
399
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
400
+ When: { label: "When", element: "textarea", type: "text" },
401
+ Duration: { label: "Duration", element: "textarea", type: "text" },
402
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
403
+ icons: { delete: "plusOutlined", add: "plusOutlined" }
404
+ };
405
+ return {
406
+ ...row,
407
+ variable_data: [...row.variable_data, newSubRow]
408
+ };
409
+ }
410
+ return row;
411
+ });
412
+ });
413
+ };
366
414
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
367
415
  title: eachHeadEl.label,
368
416
  dataIndex: eachHeadEl.name,
369
417
  key: eachHeadEl.id
370
418
  })) : [];
371
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
372
- console.log("eachRow---------", eachRow);
373
- const variableData = eachRow.variable_data.reduce((acc, curr) => {
374
- acc[curr.label] = curr.element;
375
- return acc;
376
- }, {});
377
- console.log("variableData", variableData);
419
+ const renderInputElement = (element) => {
420
+ const { element: type, label } = element;
421
+ if (type === "single-select") {
422
+ return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
423
+ } else if (type === "textarea") {
424
+ return /* @__PURE__ */ import_react13.default.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
425
+ } else {
426
+ return null;
427
+ }
428
+ };
429
+ const dataSource = rows.map((eachRow, index) => {
430
+ const rowElements = {};
431
+ if (eachRow.element && eachRow.label) {
432
+ rowElements[eachRow.label] = renderInputElement(eachRow);
433
+ }
434
+ if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
435
+ eachRow.variable_data.forEach((variable) => {
436
+ Object.entries(variable).forEach(([key, value]) => {
437
+ if (key === "icons" && value) {
438
+ {
439
+ eachRow.variable_data.map((variable2, subIndex) => {
440
+ rowElements["sub rows"] = /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, eachRow.variable_data.length > 1 && /* @__PURE__ */ import_react13.default.createElement("button", null, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ import_react13.default.createElement("button", { onClick: () => onHandleSubRowsAdd(index) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
441
+ });
442
+ }
443
+ } else if (value && value.element && value.label) {
444
+ rowElements[value.label] = renderInputElement(value);
445
+ }
446
+ });
447
+ });
448
+ }
378
449
  return {
379
450
  key: index.toString(),
451
+ "#": index + 1,
380
452
  ...eachRow,
381
- ...variableData
453
+ ...rowElements,
454
+ actions: /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement("button", { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ import_react13.default.createElement("button", { onClick: onHandleRows }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)))
382
455
  };
383
- }) : [];
456
+ });
457
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
458
+ columns.push({
459
+ title: "Actions",
460
+ dataIndex: "actions",
461
+ key: "actions"
462
+ });
463
+ }
384
464
  return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
385
465
  import_antd11.Table,
386
466
  {
package/dist/index.mjs CHANGED
@@ -312,28 +312,108 @@ import { Button as Button2, Flex as Flex2 } from "antd";
312
312
  var ButtonElement = () => /* @__PURE__ */ React11.createElement(Flex2, { gap: "small" }, /* @__PURE__ */ React11.createElement(Button2, { type: "primary" }, "Primary Button"));
313
313
 
314
314
  // src/Components/AddMoreTable.tsx
315
- import React12 from "react";
315
+ import React12, { useState as useState3 } from "react";
316
316
  import { Table } from "antd";
317
+ import { PlusOutlined, DeleteOutlined } from "@ant-design/icons";
317
318
  var AddMoreTable = (props) => {
318
319
  const { thead, tbody } = props;
320
+ const [tableData, setTableData] = useState3({});
321
+ const [rows, setRows] = useState3(tbody || []);
322
+ function isColumnType(column) {
323
+ return column.dataIndex !== void 0;
324
+ }
325
+ const onHandleChange = (name, value) => {
326
+ setTableData((prev) => ({ ...prev, [name]: value }));
327
+ console.log(tableData);
328
+ };
329
+ const onHandleRows = () => {
330
+ const lastRow = rows[rows.length - 1];
331
+ const newId = lastRow ? lastRow.id + 1 : 1;
332
+ let newRow = {
333
+ ...lastRow,
334
+ id: newId
335
+ };
336
+ setRows((prevData) => [...prevData, newRow]);
337
+ };
338
+ const onHandleDelete = (index) => {
339
+ if (rows.length > 1) {
340
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
341
+ setRows(remainingRows);
342
+ }
343
+ };
344
+ const onHandleSubRowsAdd = (rowIndex) => {
345
+ setRows((prevRows) => {
346
+ return prevRows.map((row, index) => {
347
+ if (index === rowIndex) {
348
+ const newSubRow = {
349
+ id: row.variable_data.length + 1,
350
+ Route: { label: "Route", element: "single-select", type: "text" },
351
+ Dose: { label: "Dose", element: "single-select", type: "text" },
352
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
353
+ When: { label: "When", element: "textarea", type: "text" },
354
+ Duration: { label: "Duration", element: "textarea", type: "text" },
355
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
356
+ icons: { delete: "plusOutlined", add: "plusOutlined" }
357
+ };
358
+ return {
359
+ ...row,
360
+ variable_data: [...row.variable_data, newSubRow]
361
+ };
362
+ }
363
+ return row;
364
+ });
365
+ });
366
+ };
319
367
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
320
368
  title: eachHeadEl.label,
321
369
  dataIndex: eachHeadEl.name,
322
370
  key: eachHeadEl.id
323
371
  })) : [];
324
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
325
- console.log("eachRow---------", eachRow);
326
- const variableData = eachRow.variable_data.reduce((acc, curr) => {
327
- acc[curr.label] = curr.element;
328
- return acc;
329
- }, {});
330
- console.log("variableData", variableData);
372
+ const renderInputElement = (element) => {
373
+ const { element: type, label } = element;
374
+ if (type === "single-select") {
375
+ return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
376
+ } else if (type === "textarea") {
377
+ return /* @__PURE__ */ React12.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
378
+ } else {
379
+ return null;
380
+ }
381
+ };
382
+ const dataSource = rows.map((eachRow, index) => {
383
+ const rowElements = {};
384
+ if (eachRow.element && eachRow.label) {
385
+ rowElements[eachRow.label] = renderInputElement(eachRow);
386
+ }
387
+ if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
388
+ eachRow.variable_data.forEach((variable) => {
389
+ Object.entries(variable).forEach(([key, value]) => {
390
+ if (key === "icons" && value) {
391
+ {
392
+ eachRow.variable_data.map((variable2, subIndex) => {
393
+ rowElements["sub rows"] = /* @__PURE__ */ React12.createElement(React12.Fragment, null, eachRow.variable_data.length > 1 && /* @__PURE__ */ React12.createElement("button", null, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement("button", { onClick: () => onHandleSubRowsAdd(index) }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
394
+ });
395
+ }
396
+ } else if (value && value.element && value.label) {
397
+ rowElements[value.label] = renderInputElement(value);
398
+ }
399
+ });
400
+ });
401
+ }
331
402
  return {
332
403
  key: index.toString(),
404
+ "#": index + 1,
333
405
  ...eachRow,
334
- ...variableData
406
+ ...rowElements,
407
+ actions: /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("button", { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ React12.createElement("button", { onClick: onHandleRows }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)))
335
408
  };
336
- }) : [];
409
+ });
410
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
411
+ columns.push({
412
+ title: "Actions",
413
+ dataIndex: "actions",
414
+ key: "actions"
415
+ });
416
+ }
337
417
  return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
338
418
  Table,
339
419
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.11-Beta4",
3
+ "version": "0.0.11-Beta41",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",