@apexcura/ui-components 0.0.11-Beta5 → 0.0.11-Beta50

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,20 +361,90 @@ 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;
366
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
+ }
367
372
  const onHandleChange = (name, value) => {
368
373
  setTableData((prev) => ({ ...prev, [name]: value }));
369
374
  console.log(tableData);
370
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
+ variable_data: [
383
+ {
384
+ id: 1,
385
+ Route: { label: "Route", element: "single-select", type: "text" },
386
+ Dose: { label: "Dose", element: "single-select", type: "text" },
387
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
388
+ When: { label: "When", element: "textarea", type: "text" },
389
+ Duration: { label: "Duration", element: "textarea", type: "text" },
390
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
391
+ icons: { delete: "plusOutlined", add: "plusOutlined" }
392
+ }
393
+ ]
394
+ };
395
+ console.log(rows);
396
+ setRows((prevData) => [...prevData, newRow]);
397
+ };
398
+ const onHandleDelete = (index) => {
399
+ if (rows.length > 1) {
400
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
401
+ setRows(remainingRows);
402
+ }
403
+ };
404
+ const onHandleSubRowsAdd = (rowIndex) => {
405
+ setRows((prevRows) => {
406
+ return prevRows.map((row, index) => {
407
+ if (index === rowIndex) {
408
+ const newSubRow = {
409
+ id: row.variable_data.length + 1,
410
+ Route: { label: "Route", element: "single-select", type: "text" },
411
+ Dose: { label: "Dose", element: "single-select", type: "text" },
412
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
413
+ When: { label: "When", element: "textarea", type: "text" },
414
+ Duration: { label: "Duration", element: "textarea", type: "text" },
415
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
416
+ icons: { delete: "plusOutlined", add: "plusOutlined" }
417
+ };
418
+ return {
419
+ ...row,
420
+ variable_data: [...row.variable_data, newSubRow]
421
+ };
422
+ }
423
+ return row;
424
+ });
425
+ });
426
+ };
427
+ const onHandleSubRowsDelete = (rowIndex, subIndex) => {
428
+ setRows((prevRows) => {
429
+ return prevRows.map((row, index) => {
430
+ if (index === rowIndex) {
431
+ const updatedVariableData = row.variable_data.filter((_, i) => i !== subIndex);
432
+ return {
433
+ ...row,
434
+ variable_data: updatedVariableData
435
+ };
436
+ }
437
+ return row;
438
+ });
439
+ });
440
+ };
371
441
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
372
442
  title: eachHeadEl.label,
373
443
  dataIndex: eachHeadEl.name,
374
444
  key: eachHeadEl.id
375
445
  })) : [];
376
446
  const renderInputElement = (element) => {
377
- const { type, label } = element;
447
+ const { element: type, label } = element;
378
448
  if (type === "single-select") {
379
449
  return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
380
450
  } else if (type === "textarea") {
@@ -383,26 +453,48 @@ var AddMoreTable = (props) => {
383
453
  return null;
384
454
  }
385
455
  };
386
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
387
- console.log("eachRow---------", eachRow);
388
- const variableData = eachRow.variable_data.reduce((acc, curr) => {
389
- acc[curr.label] = renderInputElement(curr);
390
- return acc;
391
- }, {});
392
- return {
456
+ const dataSource = rows.flatMap((eachRow, index) => {
457
+ const rowData = [];
458
+ const mainRow = {
393
459
  key: index.toString(),
460
+ "#": index + 1,
394
461
  ...eachRow,
395
- ...variableData
462
+ actions: /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.DeleteOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: onHandleRows }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)))
396
463
  };
397
- }) : [];
398
- return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
464
+ console.log(...eachRow);
465
+ rowData.push(mainRow);
466
+ if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
467
+ eachRow.variable_data.forEach((variable, subIndex) => {
468
+ const subRowElements = {};
469
+ Object.entries(variable).forEach(([key, value]) => {
470
+ if (key === "icons" && value) {
471
+ subRowElements["sub rows"] = /* @__PURE__ */ import_react13.default.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, { onClick: () => onHandleSubRowsDelete(index, 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(index) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
472
+ } else if (value && value.element && value.label) {
473
+ subRowElements[value.label] = renderInputElement(value);
474
+ }
475
+ });
476
+ rowData.push(subRowElements);
477
+ });
478
+ }
479
+ console.log(rowData);
480
+ return rowData;
481
+ });
482
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
483
+ columns.push({
484
+ title: "Actions",
485
+ dataIndex: "actions",
486
+ key: "actions"
487
+ });
488
+ }
489
+ return /* @__PURE__ */ import_react13.default.createElement(
399
490
  import_antd11.Table,
400
491
  {
401
492
  columns,
402
- expandable: { defaultExpandedRowKeys: ["0"] },
403
- dataSource
493
+ dataSource,
494
+ pagination: false,
495
+ bordered: true
404
496
  }
405
- ));
497
+ );
406
498
  };
407
499
  // Annotate the CommonJS export names for ESM import in node:
408
500
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -313,21 +313,91 @@ var ButtonElement = () => /* @__PURE__ */ React11.createElement(Flex2, { gap: "s
313
313
 
314
314
  // src/Components/AddMoreTable.tsx
315
315
  import React12, { useState as useState3 } from "react";
316
- import { Table } from "antd";
316
+ import { Table, Button as Button3 } from "antd";
317
+ import { PlusOutlined, DeleteOutlined } from "@ant-design/icons";
317
318
  var AddMoreTable = (props) => {
318
319
  const { thead, tbody } = props;
319
320
  const [tableData, setTableData] = useState3({});
321
+ const [rows, setRows] = useState3(tbody || []);
322
+ function isColumnType(column) {
323
+ return column.dataIndex !== void 0;
324
+ }
320
325
  const onHandleChange = (name, value) => {
321
326
  setTableData((prev) => ({ ...prev, [name]: value }));
322
327
  console.log(tableData);
323
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
+ variable_data: [
336
+ {
337
+ id: 1,
338
+ Route: { label: "Route", element: "single-select", type: "text" },
339
+ Dose: { label: "Dose", element: "single-select", type: "text" },
340
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
341
+ When: { label: "When", element: "textarea", type: "text" },
342
+ Duration: { label: "Duration", element: "textarea", type: "text" },
343
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
344
+ icons: { delete: "plusOutlined", add: "plusOutlined" }
345
+ }
346
+ ]
347
+ };
348
+ console.log(rows);
349
+ setRows((prevData) => [...prevData, newRow]);
350
+ };
351
+ const onHandleDelete = (index) => {
352
+ if (rows.length > 1) {
353
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
354
+ setRows(remainingRows);
355
+ }
356
+ };
357
+ const onHandleSubRowsAdd = (rowIndex) => {
358
+ setRows((prevRows) => {
359
+ return prevRows.map((row, index) => {
360
+ if (index === rowIndex) {
361
+ const newSubRow = {
362
+ id: row.variable_data.length + 1,
363
+ Route: { label: "Route", element: "single-select", type: "text" },
364
+ Dose: { label: "Dose", element: "single-select", type: "text" },
365
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
366
+ When: { label: "When", element: "textarea", type: "text" },
367
+ Duration: { label: "Duration", element: "textarea", type: "text" },
368
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
369
+ icons: { delete: "plusOutlined", add: "plusOutlined" }
370
+ };
371
+ return {
372
+ ...row,
373
+ variable_data: [...row.variable_data, newSubRow]
374
+ };
375
+ }
376
+ return row;
377
+ });
378
+ });
379
+ };
380
+ const onHandleSubRowsDelete = (rowIndex, subIndex) => {
381
+ setRows((prevRows) => {
382
+ return prevRows.map((row, index) => {
383
+ if (index === rowIndex) {
384
+ const updatedVariableData = row.variable_data.filter((_, i) => i !== subIndex);
385
+ return {
386
+ ...row,
387
+ variable_data: updatedVariableData
388
+ };
389
+ }
390
+ return row;
391
+ });
392
+ });
393
+ };
324
394
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
325
395
  title: eachHeadEl.label,
326
396
  dataIndex: eachHeadEl.name,
327
397
  key: eachHeadEl.id
328
398
  })) : [];
329
399
  const renderInputElement = (element) => {
330
- const { type, label } = element;
400
+ const { element: type, label } = element;
331
401
  if (type === "single-select") {
332
402
  return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
333
403
  } else if (type === "textarea") {
@@ -336,26 +406,48 @@ var AddMoreTable = (props) => {
336
406
  return null;
337
407
  }
338
408
  };
339
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
340
- console.log("eachRow---------", eachRow);
341
- const variableData = eachRow.variable_data.reduce((acc, curr) => {
342
- acc[curr.label] = renderInputElement(curr);
343
- return acc;
344
- }, {});
345
- return {
409
+ const dataSource = rows.flatMap((eachRow, index) => {
410
+ const rowData = [];
411
+ const mainRow = {
346
412
  key: index.toString(),
413
+ "#": index + 1,
347
414
  ...eachRow,
348
- ...variableData
415
+ actions: /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: onHandleRows }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)))
349
416
  };
350
- }) : [];
351
- return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
417
+ console.log(...eachRow);
418
+ rowData.push(mainRow);
419
+ if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
420
+ eachRow.variable_data.forEach((variable, subIndex) => {
421
+ const subRowElements = {};
422
+ Object.entries(variable).forEach(([key, value]) => {
423
+ if (key === "icons" && value) {
424
+ subRowElements["sub rows"] = /* @__PURE__ */ React12.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsDelete(index, subIndex) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsAdd(index) }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
425
+ } else if (value && value.element && value.label) {
426
+ subRowElements[value.label] = renderInputElement(value);
427
+ }
428
+ });
429
+ rowData.push(subRowElements);
430
+ });
431
+ }
432
+ console.log(rowData);
433
+ return rowData;
434
+ });
435
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
436
+ columns.push({
437
+ title: "Actions",
438
+ dataIndex: "actions",
439
+ key: "actions"
440
+ });
441
+ }
442
+ return /* @__PURE__ */ React12.createElement(
352
443
  Table,
353
444
  {
354
445
  columns,
355
- expandable: { defaultExpandedRowKeys: ["0"] },
356
- dataSource
446
+ dataSource,
447
+ pagination: false,
448
+ bordered: true
357
449
  }
358
- ));
450
+ );
359
451
  };
360
452
  export {
361
453
  AddMoreTable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.11-Beta5",
3
+ "version": "0.0.11-Beta50",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",