@apexcura/ui-components 0.0.12-Beta2 → 0.0.12-Beta21

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 (3) hide show
  1. package/dist/index.js +103 -13
  2. package/dist/index.mjs +103 -13
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -361,13 +361,93 @@ 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
+ };
383
+ if (newRow.variable_data && newRow.variable_data.length > 0) {
384
+ const updatedVariableData = newRow.variable_data.map((item, index) => {
385
+ const { icons, ...rest } = item;
386
+ return {
387
+ ...rest,
388
+ icons: { delete: "", plus: index === newRow.variable_data.length - 1 ? "" : void 0 }
389
+ };
390
+ });
391
+ newRow.variable_data = updatedVariableData;
392
+ }
393
+ setRows((prevData) => [...prevData, newRow]);
394
+ };
395
+ const onHandleDelete = (index) => {
396
+ if (rows.length > 1) {
397
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
398
+ setRows(remainingRows);
399
+ }
400
+ };
401
+ const onHandleVariableData = (rowId) => {
402
+ setRows((prevRows) => prevRows.map((row) => {
403
+ if (row.id === rowId) {
404
+ const newVariableDataId = row.variable_data.length > 0 ? row.variable_data[row.variable_data.length - 1].id + 1 : 1;
405
+ const newVariableData = {
406
+ id: newVariableDataId,
407
+ Route: {
408
+ label: "Route",
409
+ element: "single-select",
410
+ type: "text"
411
+ },
412
+ Dose: {
413
+ label: "Dose",
414
+ element: "single-select",
415
+ type: "text"
416
+ },
417
+ Frequency: {
418
+ label: "Frequency",
419
+ element: "single-select",
420
+ type: "text"
421
+ },
422
+ When: {
423
+ label: "When",
424
+ element: "textarea",
425
+ type: "text"
426
+ },
427
+ Duration: {
428
+ label: "Duration",
429
+ element: "textarea",
430
+ type: "text"
431
+ },
432
+ Instructions: {
433
+ label: "Instructions",
434
+ element: "textarea",
435
+ type: "text"
436
+ },
437
+ icons: { delete: "", plus: "" }
438
+ };
439
+ const updatedVariableData = [...row.variable_data, newVariableData].map((item, index, array) => ({
440
+ ...item,
441
+ icons: { delete: "", plus: index === array.length - 1 ? "" : void 0 }
442
+ }));
443
+ return {
444
+ ...row,
445
+ variable_data: updatedVariableData
446
+ };
447
+ }
448
+ return row;
449
+ }));
450
+ };
371
451
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
372
452
  title: eachHeadEl.label,
373
453
  dataIndex: eachHeadEl.name,
@@ -375,7 +455,6 @@ var AddMoreTable = (props) => {
375
455
  })) : [];
376
456
  const renderInputElement = (element) => {
377
457
  const { element: type, label } = element;
378
- console.log("type....", type);
379
458
  if (type === "single-select") {
380
459
  return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
381
460
  } else if (type === "textarea") {
@@ -384,27 +463,38 @@ var AddMoreTable = (props) => {
384
463
  return null;
385
464
  }
386
465
  };
387
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
466
+ const dataSource = rows.map((eachRow, index) => {
388
467
  const rowElements = {};
389
468
  if (eachRow.element && eachRow.label) {
390
469
  rowElements[eachRow.label] = renderInputElement(eachRow);
391
470
  }
392
- const variableData = eachRow.variable_data && Array.isArray(eachRow.variable_data) ? eachRow.variable_data.reduce((acc, curr) => {
393
- if (!curr.label || !curr.element) {
394
- console.error(`Invalid element in row ${index}:`, curr);
395
- return acc;
396
- }
397
- acc[curr.label] = renderInputElement(curr);
398
- return acc;
399
- }, {}) : {};
471
+ if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
472
+ eachRow.variable_data.forEach((variable, varIndex) => {
473
+ Object.entries(variable).forEach(([key, value]) => {
474
+ if (value && value.element && value.label) {
475
+ rowElements[value.label] = renderInputElement(value);
476
+ }
477
+ if (key === "icons") {
478
+ rowElements[`icons_${varIndex}`] = /* @__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)), varIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ import_react13.default.createElement("button", { onClick: () => onHandleVariableData(eachRow.id) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
479
+ }
480
+ });
481
+ });
482
+ }
400
483
  return {
401
484
  key: index.toString(),
485
+ "#": index + 1,
402
486
  ...eachRow,
403
487
  ...rowElements,
404
- ...variableData
488
+ 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)))
405
489
  };
406
- }) : [];
407
- console.log("dataSource.........", dataSource);
490
+ });
491
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
492
+ columns.push({
493
+ title: "Actions",
494
+ dataIndex: "actions",
495
+ key: "actions"
496
+ });
497
+ }
408
498
  return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
409
499
  import_antd11.Table,
410
500
  {
package/dist/index.mjs CHANGED
@@ -314,13 +314,93 @@ var ButtonElement = () => /* @__PURE__ */ React11.createElement(Flex2, { gap: "s
314
314
  // src/Components/AddMoreTable.tsx
315
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;
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
+ };
336
+ if (newRow.variable_data && newRow.variable_data.length > 0) {
337
+ const updatedVariableData = newRow.variable_data.map((item, index) => {
338
+ const { icons, ...rest } = item;
339
+ return {
340
+ ...rest,
341
+ icons: { delete: "", plus: index === newRow.variable_data.length - 1 ? "" : void 0 }
342
+ };
343
+ });
344
+ newRow.variable_data = updatedVariableData;
345
+ }
346
+ setRows((prevData) => [...prevData, newRow]);
347
+ };
348
+ const onHandleDelete = (index) => {
349
+ if (rows.length > 1) {
350
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
351
+ setRows(remainingRows);
352
+ }
353
+ };
354
+ const onHandleVariableData = (rowId) => {
355
+ setRows((prevRows) => prevRows.map((row) => {
356
+ if (row.id === rowId) {
357
+ const newVariableDataId = row.variable_data.length > 0 ? row.variable_data[row.variable_data.length - 1].id + 1 : 1;
358
+ const newVariableData = {
359
+ id: newVariableDataId,
360
+ Route: {
361
+ label: "Route",
362
+ element: "single-select",
363
+ type: "text"
364
+ },
365
+ Dose: {
366
+ label: "Dose",
367
+ element: "single-select",
368
+ type: "text"
369
+ },
370
+ Frequency: {
371
+ label: "Frequency",
372
+ element: "single-select",
373
+ type: "text"
374
+ },
375
+ When: {
376
+ label: "When",
377
+ element: "textarea",
378
+ type: "text"
379
+ },
380
+ Duration: {
381
+ label: "Duration",
382
+ element: "textarea",
383
+ type: "text"
384
+ },
385
+ Instructions: {
386
+ label: "Instructions",
387
+ element: "textarea",
388
+ type: "text"
389
+ },
390
+ icons: { delete: "", plus: "" }
391
+ };
392
+ const updatedVariableData = [...row.variable_data, newVariableData].map((item, index, array) => ({
393
+ ...item,
394
+ icons: { delete: "", plus: index === array.length - 1 ? "" : void 0 }
395
+ }));
396
+ return {
397
+ ...row,
398
+ variable_data: updatedVariableData
399
+ };
400
+ }
401
+ return row;
402
+ }));
403
+ };
324
404
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
325
405
  title: eachHeadEl.label,
326
406
  dataIndex: eachHeadEl.name,
@@ -328,7 +408,6 @@ var AddMoreTable = (props) => {
328
408
  })) : [];
329
409
  const renderInputElement = (element) => {
330
410
  const { element: type, label } = element;
331
- console.log("type....", type);
332
411
  if (type === "single-select") {
333
412
  return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
334
413
  } else if (type === "textarea") {
@@ -337,27 +416,38 @@ var AddMoreTable = (props) => {
337
416
  return null;
338
417
  }
339
418
  };
340
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
419
+ const dataSource = rows.map((eachRow, index) => {
341
420
  const rowElements = {};
342
421
  if (eachRow.element && eachRow.label) {
343
422
  rowElements[eachRow.label] = renderInputElement(eachRow);
344
423
  }
345
- const variableData = eachRow.variable_data && Array.isArray(eachRow.variable_data) ? eachRow.variable_data.reduce((acc, curr) => {
346
- if (!curr.label || !curr.element) {
347
- console.error(`Invalid element in row ${index}:`, curr);
348
- return acc;
349
- }
350
- acc[curr.label] = renderInputElement(curr);
351
- return acc;
352
- }, {}) : {};
424
+ if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
425
+ eachRow.variable_data.forEach((variable, varIndex) => {
426
+ Object.entries(variable).forEach(([key, value]) => {
427
+ if (value && value.element && value.label) {
428
+ rowElements[value.label] = renderInputElement(value);
429
+ }
430
+ if (key === "icons") {
431
+ rowElements[`icons_${varIndex}`] = /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("button", { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), varIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement("button", { onClick: () => onHandleVariableData(eachRow.id) }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
432
+ }
433
+ });
434
+ });
435
+ }
353
436
  return {
354
437
  key: index.toString(),
438
+ "#": index + 1,
355
439
  ...eachRow,
356
440
  ...rowElements,
357
- ...variableData
441
+ 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)))
358
442
  };
359
- }) : [];
360
- console.log("dataSource.........", dataSource);
443
+ });
444
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
445
+ columns.push({
446
+ title: "Actions",
447
+ dataIndex: "actions",
448
+ key: "actions"
449
+ });
450
+ }
361
451
  return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
362
452
  Table,
363
453
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.12-Beta2",
3
+ "version": "0.0.12-Beta21",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",