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

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