@apexcura/ui-components 0.0.11-Beta40 → 0.0.11-Beta42

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.js CHANGED
@@ -388,8 +388,28 @@ var AddMoreTable = (props) => {
388
388
  setRows(remainingRows);
389
389
  }
390
390
  };
391
- const onHandleSubRowsAdd = () => {
392
- console.log(rows);
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
+ });
393
413
  };
394
414
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
395
415
  title: eachHeadEl.label,
@@ -406,33 +426,29 @@ var AddMoreTable = (props) => {
406
426
  return null;
407
427
  }
408
428
  };
409
- const dataSource = rows.map((eachRow, index) => {
410
- const rowElements = {};
411
- if (eachRow.element && eachRow.label) {
412
- rowElements[eachRow.label] = renderInputElement(eachRow);
413
- }
429
+ const dataSource = rows.flatMap((eachRow, index) => {
430
+ const rowData = [];
431
+ const mainRow = {
432
+ key: index.toString(),
433
+ "#": index + 1,
434
+ ...eachRow,
435
+ 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)))
436
+ };
437
+ rowData.push(mainRow);
414
438
  if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
415
- eachRow.variable_data.forEach((variable) => {
439
+ eachRow.variable_data.forEach((variable, subIndex) => {
440
+ const subRowElements = {};
416
441
  Object.entries(variable).forEach(([key, value]) => {
417
442
  if (key === "icons" && value) {
418
- {
419
- eachRow.variable_data.map((variable2, subIndex) => {
420
- 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 }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)));
421
- });
422
- }
443
+ subRowElements["sub rows"] = /* @__PURE__ */ import_react13.default.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ import_react13.default.createElement(import_antd11.Button, null, /* @__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)));
423
444
  } else if (value && value.element && value.label) {
424
- rowElements[value.label] = renderInputElement(value);
445
+ subRowElements[value.label] = renderInputElement(value);
425
446
  }
426
447
  });
448
+ rowData.push(subRowElements);
427
449
  });
428
450
  }
429
- return {
430
- key: index.toString(),
431
- "#": index + 1,
432
- ...eachRow,
433
- ...rowElements,
434
- 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)))
435
- };
451
+ return rowData;
436
452
  });
437
453
  if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
438
454
  columns.push({
@@ -441,14 +457,15 @@ var AddMoreTable = (props) => {
441
457
  key: "actions"
442
458
  });
443
459
  }
444
- return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement(
460
+ return /* @__PURE__ */ import_react13.default.createElement(
445
461
  import_antd11.Table,
446
462
  {
447
463
  columns,
448
- expandable: { defaultExpandedRowKeys: ["0"] },
449
- dataSource
464
+ dataSource,
465
+ pagination: false,
466
+ bordered: true
450
467
  }
451
- ));
468
+ );
452
469
  };
453
470
  // Annotate the CommonJS export names for ESM import in node:
454
471
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -313,7 +313,7 @@ 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
317
  import { PlusOutlined, DeleteOutlined } from "@ant-design/icons";
318
318
  var AddMoreTable = (props) => {
319
319
  const { thead, tbody } = props;
@@ -341,8 +341,28 @@ var AddMoreTable = (props) => {
341
341
  setRows(remainingRows);
342
342
  }
343
343
  };
344
- const onHandleSubRowsAdd = () => {
345
- console.log(rows);
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
+ });
346
366
  };
347
367
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
348
368
  title: eachHeadEl.label,
@@ -359,33 +379,29 @@ var AddMoreTable = (props) => {
359
379
  return null;
360
380
  }
361
381
  };
362
- const dataSource = rows.map((eachRow, index) => {
363
- const rowElements = {};
364
- if (eachRow.element && eachRow.label) {
365
- rowElements[eachRow.label] = renderInputElement(eachRow);
366
- }
382
+ const dataSource = rows.flatMap((eachRow, index) => {
383
+ const rowData = [];
384
+ const mainRow = {
385
+ key: index.toString(),
386
+ "#": index + 1,
387
+ ...eachRow,
388
+ 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)))
389
+ };
390
+ rowData.push(mainRow);
367
391
  if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
368
- eachRow.variable_data.forEach((variable) => {
392
+ eachRow.variable_data.forEach((variable, subIndex) => {
393
+ const subRowElements = {};
369
394
  Object.entries(variable).forEach(([key, value]) => {
370
395
  if (key === "icons" && value) {
371
- {
372
- eachRow.variable_data.map((variable2, subIndex) => {
373
- 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 }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
374
- });
375
- }
396
+ subRowElements["sub rows"] = /* @__PURE__ */ React12.createElement("div", { key: subIndex }, eachRow.variable_data.length > 1 && /* @__PURE__ */ React12.createElement(Button3, null, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), subIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement(Button3, { onClick: () => onHandleSubRowsAdd(index) }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)));
376
397
  } else if (value && value.element && value.label) {
377
- rowElements[value.label] = renderInputElement(value);
398
+ subRowElements[value.label] = renderInputElement(value);
378
399
  }
379
400
  });
401
+ rowData.push(subRowElements);
380
402
  });
381
403
  }
382
- return {
383
- key: index.toString(),
384
- "#": index + 1,
385
- ...eachRow,
386
- ...rowElements,
387
- 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)))
388
- };
404
+ return rowData;
389
405
  });
390
406
  if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
391
407
  columns.push({
@@ -394,14 +410,15 @@ var AddMoreTable = (props) => {
394
410
  key: "actions"
395
411
  });
396
412
  }
397
- return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
413
+ return /* @__PURE__ */ React12.createElement(
398
414
  Table,
399
415
  {
400
416
  columns,
401
- expandable: { defaultExpandedRowKeys: ["0"] },
402
- dataSource
417
+ dataSource,
418
+ pagination: false,
419
+ bordered: true
403
420
  }
404
- ));
421
+ );
405
422
  };
406
423
  export {
407
424
  AddMoreTable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.11-Beta40",
3
+ "version": "0.0.11-Beta42",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",