@apexcura/ui-components 0.0.11-Beta2 → 0.0.11-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.
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,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;
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 : lastRow.id;
379
+ const newRow = {
380
+ ...lastRow,
381
+ id: newId
382
+ };
383
+ setRows((prevData) => [...prevData, newRow]);
384
+ };
385
+ const onHandleDelete = (index) => {
386
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
387
+ setRows(remainingRows);
388
+ };
366
389
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
367
390
  title: eachHeadEl.label,
368
391
  dataIndex: eachHeadEl.name,
369
392
  key: eachHeadEl.id
370
393
  })) : [];
371
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
372
- const variableData = eachRow.variable_data.reduce((acc, curr) => {
373
- acc[curr.label] = curr.element;
374
- return acc;
375
- }, {});
376
- console.log("eachRow---------", eachRow);
377
- console.log("VariableData", { ...variableData });
394
+ const renderInputElement = (element) => {
395
+ const { element: type, label } = element;
396
+ if (type === "single-select") {
397
+ return /* @__PURE__ */ import_react13.default.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
398
+ } else if (type === "textarea") {
399
+ return /* @__PURE__ */ import_react13.default.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
400
+ } else {
401
+ return null;
402
+ }
403
+ };
404
+ const dataSource = rows.map((eachRow, index) => {
405
+ const rowElements = {};
406
+ if (eachRow.element && eachRow.label) {
407
+ rowElements[eachRow.label] = renderInputElement(eachRow);
408
+ }
409
+ if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
410
+ eachRow.variable_data.forEach((variable) => {
411
+ Object.entries(variable).forEach(([key, value]) => {
412
+ if (value && value.element && value.label) {
413
+ rowElements[value.label] = renderInputElement(value);
414
+ }
415
+ });
416
+ });
417
+ if (eachRow.variable_data.length > 0) {
418
+ const addIconObject = {
419
+ id: { id: eachRow.variable_data.length + 1 },
420
+ Route: { label: "Route", element: "single-select", type: "text" },
421
+ Dose: { label: "Dose", element: "single-select", type: "text" },
422
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
423
+ When: { label: "When", element: "textarea", type: "text" },
424
+ Duration: { label: "Duration", element: "textarea", type: "text" },
425
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
426
+ addIcon: /* @__PURE__ */ import_react13.default.createElement("button", { onClick: () => console.log("Add more clicked") }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null))
427
+ };
428
+ console.log("eachrow----------", eachRow);
429
+ rowElements["AddMoreIcon"] = addIconObject.addIcon;
430
+ }
431
+ console.log("RowElement", rowElements);
432
+ }
378
433
  return {
379
434
  key: index.toString(),
380
- ...variableData,
381
- ...eachRow
435
+ "#": index + 1,
436
+ ...eachRow,
437
+ ...rowElements,
438
+ 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
439
  };
383
- }) : [];
440
+ });
441
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
442
+ columns.push({
443
+ title: "Actions",
444
+ dataIndex: "actions",
445
+ key: "actions"
446
+ });
447
+ }
384
448
  return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
385
449
  import_antd11.Table,
386
450
  {
package/dist/index.mjs CHANGED
@@ -312,28 +312,92 @@ 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 : lastRow.id;
332
+ const newRow = {
333
+ ...lastRow,
334
+ id: newId
335
+ };
336
+ setRows((prevData) => [...prevData, newRow]);
337
+ };
338
+ const onHandleDelete = (index) => {
339
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
340
+ setRows(remainingRows);
341
+ };
319
342
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
320
343
  title: eachHeadEl.label,
321
344
  dataIndex: eachHeadEl.name,
322
345
  key: eachHeadEl.id
323
346
  })) : [];
324
- const dataSource = tbody && tbody.length > 0 ? tbody.map((eachRow, index) => {
325
- const variableData = eachRow.variable_data.reduce((acc, curr) => {
326
- acc[curr.label] = curr.element;
327
- return acc;
328
- }, {});
329
- console.log("eachRow---------", eachRow);
330
- console.log("VariableData", { ...variableData });
347
+ const renderInputElement = (element) => {
348
+ const { element: type, label } = element;
349
+ if (type === "single-select") {
350
+ return /* @__PURE__ */ React12.createElement(SingleSelectElement, { onChange: (value) => onHandleChange(label, value) });
351
+ } else if (type === "textarea") {
352
+ return /* @__PURE__ */ React12.createElement(TextareaElement, { onChange: (value) => onHandleChange(label, value) });
353
+ } else {
354
+ return null;
355
+ }
356
+ };
357
+ const dataSource = rows.map((eachRow, index) => {
358
+ const rowElements = {};
359
+ if (eachRow.element && eachRow.label) {
360
+ rowElements[eachRow.label] = renderInputElement(eachRow);
361
+ }
362
+ if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
363
+ eachRow.variable_data.forEach((variable) => {
364
+ Object.entries(variable).forEach(([key, value]) => {
365
+ if (value && value.element && value.label) {
366
+ rowElements[value.label] = renderInputElement(value);
367
+ }
368
+ });
369
+ });
370
+ if (eachRow.variable_data.length > 0) {
371
+ const addIconObject = {
372
+ id: { id: eachRow.variable_data.length + 1 },
373
+ Route: { label: "Route", element: "single-select", type: "text" },
374
+ Dose: { label: "Dose", element: "single-select", type: "text" },
375
+ Frequency: { label: "Frequency", element: "single-select", type: "text" },
376
+ When: { label: "When", element: "textarea", type: "text" },
377
+ Duration: { label: "Duration", element: "textarea", type: "text" },
378
+ Instructions: { label: "Instructions", element: "textarea", type: "text" },
379
+ addIcon: /* @__PURE__ */ React12.createElement("button", { onClick: () => console.log("Add more clicked") }, /* @__PURE__ */ React12.createElement(PlusOutlined, null))
380
+ };
381
+ console.log("eachrow----------", eachRow);
382
+ rowElements["AddMoreIcon"] = addIconObject.addIcon;
383
+ }
384
+ console.log("RowElement", rowElements);
385
+ }
331
386
  return {
332
387
  key: index.toString(),
333
- ...variableData,
334
- ...eachRow
388
+ "#": index + 1,
389
+ ...eachRow,
390
+ ...rowElements,
391
+ 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
392
  };
336
- }) : [];
393
+ });
394
+ if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
395
+ columns.push({
396
+ title: "Actions",
397
+ dataIndex: "actions",
398
+ key: "actions"
399
+ });
400
+ }
337
401
  return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
338
402
  Table,
339
403
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.11-Beta2",
3
+ "version": "0.0.11-Beta21",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",