@apexcura/ui-components 0.0.11-Beta24 → 0.0.11-Beta25

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
@@ -376,63 +376,77 @@ var AddMoreTable = (props) => {
376
376
  const onHandleRows = () => {
377
377
  const lastRow = rows[rows.length - 1];
378
378
  const newId = lastRow ? lastRow.id + 1 : 1;
379
- let newRow;
380
- if (lastRow && lastRow.variable_data && lastRow.variable_data.length > 0) {
381
- const lastVariable = lastRow.variable_data[lastRow.variable_data.length - 1];
382
- const newVariableId = lastVariable.id.id + 1;
383
- newRow = {
384
- ...lastRow,
385
- id: newId,
386
- variable_data: [
387
- ...lastRow.variable_data,
388
- {
389
- id: { id: newVariableId },
390
- Route: { label: "Route", element: "single-select", type: "text" },
391
- Dose: { label: "Dose", element: "single-select", type: "text" },
392
- Frequency: { label: "Frequency", element: "single-select", type: "text" },
393
- When: { label: "When", element: "textarea", type: "text" },
394
- Duration: { label: "Duration", element: "textarea", type: "text" },
395
- Instructions: { label: "Instructions", element: "textarea", type: "text" }
396
- }
397
- ]
398
- };
399
- } else {
400
- newRow = {
401
- ...lastRow,
402
- id: newId
403
- };
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;
404
392
  }
405
393
  setRows((prevData) => [...prevData, newRow]);
406
394
  };
407
395
  const onHandleDelete = (index) => {
408
- const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
409
- setRows(remainingRows);
396
+ if (rows.length > 1) {
397
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
398
+ setRows(remainingRows);
399
+ }
410
400
  };
411
- const onAddVariableData = (rowIndex) => {
412
- setRows((prevRows) => {
413
- return prevRows.map((row, index) => {
414
- if (index === rowIndex && row.variable_data && row.variable_data.length > 0) {
415
- const lastVariable = row.variable_data[row.variable_data.length - 1];
416
- const newVariableId = lastVariable.id.id + 1;
417
- return {
418
- ...row,
419
- variable_data: [
420
- ...row.variable_data,
421
- {
422
- id: { id: newVariableId },
423
- Route: { label: "Route", element: "single-select", type: "text" },
424
- Dose: { label: "Dose", element: "single-select", type: "text" },
425
- Frequency: { label: "Frequency", element: "single-select", type: "text" },
426
- When: { label: "When", element: "textarea", type: "text" },
427
- Duration: { label: "Duration", element: "textarea", type: "text" },
428
- Instructions: { label: "Instructions", element: "textarea", type: "text" }
429
- }
430
- ]
431
- };
432
- }
433
- return row;
434
- });
435
- });
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: "delete", plus: "plus" }
438
+ };
439
+ const updatedVariableData = [...row.variable_data, newVariableData].map((item, index, array) => ({
440
+ ...item,
441
+ icons: { delete: "delete", plus: index === array.length - 1 ? "plus" : void 0 }
442
+ }));
443
+ return {
444
+ ...row,
445
+ variable_data: updatedVariableData
446
+ };
447
+ }
448
+ return row;
449
+ }));
436
450
  };
437
451
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
438
452
  title: eachHeadEl.label,
@@ -455,11 +469,14 @@ var AddMoreTable = (props) => {
455
469
  rowElements[eachRow.label] = renderInputElement(eachRow);
456
470
  }
457
471
  if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
458
- eachRow.variable_data.forEach((variable) => {
472
+ eachRow.variable_data.forEach((variable, varIndex) => {
459
473
  Object.entries(variable).forEach(([key, value]) => {
460
474
  if (value && value.element && value.label) {
461
475
  rowElements[value.label] = renderInputElement(value);
462
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) }, "delete"), varIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ import_react13.default.createElement("button", { onClick: () => onHandleVariableData(eachRow.id) }, "plus"));
479
+ }
463
480
  });
464
481
  });
465
482
  }
@@ -468,7 +485,7 @@ var AddMoreTable = (props) => {
468
485
  "#": index + 1,
469
486
  ...eachRow,
470
487
  ...rowElements,
471
- 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)), /* @__PURE__ */ import_react13.default.createElement("button", { onClick: () => onAddVariableData(index) }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ import_react13.default.createElement("button", { onClick: onHandleRows }, /* @__PURE__ */ import_react13.default.createElement(import_icons2.PlusOutlined, null)))
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)))
472
489
  };
473
490
  });
474
491
  if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
package/dist/index.mjs CHANGED
@@ -329,63 +329,77 @@ var AddMoreTable = (props) => {
329
329
  const onHandleRows = () => {
330
330
  const lastRow = rows[rows.length - 1];
331
331
  const newId = lastRow ? lastRow.id + 1 : 1;
332
- let newRow;
333
- if (lastRow && lastRow.variable_data && lastRow.variable_data.length > 0) {
334
- const lastVariable = lastRow.variable_data[lastRow.variable_data.length - 1];
335
- const newVariableId = lastVariable.id.id + 1;
336
- newRow = {
337
- ...lastRow,
338
- id: newId,
339
- variable_data: [
340
- ...lastRow.variable_data,
341
- {
342
- id: { id: newVariableId },
343
- Route: { label: "Route", element: "single-select", type: "text" },
344
- Dose: { label: "Dose", element: "single-select", type: "text" },
345
- Frequency: { label: "Frequency", element: "single-select", type: "text" },
346
- When: { label: "When", element: "textarea", type: "text" },
347
- Duration: { label: "Duration", element: "textarea", type: "text" },
348
- Instructions: { label: "Instructions", element: "textarea", type: "text" }
349
- }
350
- ]
351
- };
352
- } else {
353
- newRow = {
354
- ...lastRow,
355
- id: newId
356
- };
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;
357
345
  }
358
346
  setRows((prevData) => [...prevData, newRow]);
359
347
  };
360
348
  const onHandleDelete = (index) => {
361
- const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
362
- setRows(remainingRows);
349
+ if (rows.length > 1) {
350
+ const remainingRows = rows.filter((eachRow) => eachRow.id !== index);
351
+ setRows(remainingRows);
352
+ }
363
353
  };
364
- const onAddVariableData = (rowIndex) => {
365
- setRows((prevRows) => {
366
- return prevRows.map((row, index) => {
367
- if (index === rowIndex && row.variable_data && row.variable_data.length > 0) {
368
- const lastVariable = row.variable_data[row.variable_data.length - 1];
369
- const newVariableId = lastVariable.id.id + 1;
370
- return {
371
- ...row,
372
- variable_data: [
373
- ...row.variable_data,
374
- {
375
- id: { id: newVariableId },
376
- Route: { label: "Route", element: "single-select", type: "text" },
377
- Dose: { label: "Dose", element: "single-select", type: "text" },
378
- Frequency: { label: "Frequency", element: "single-select", type: "text" },
379
- When: { label: "When", element: "textarea", type: "text" },
380
- Duration: { label: "Duration", element: "textarea", type: "text" },
381
- Instructions: { label: "Instructions", element: "textarea", type: "text" }
382
- }
383
- ]
384
- };
385
- }
386
- return row;
387
- });
388
- });
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: "delete", plus: "plus" }
391
+ };
392
+ const updatedVariableData = [...row.variable_data, newVariableData].map((item, index, array) => ({
393
+ ...item,
394
+ icons: { delete: "delete", plus: index === array.length - 1 ? "plus" : void 0 }
395
+ }));
396
+ return {
397
+ ...row,
398
+ variable_data: updatedVariableData
399
+ };
400
+ }
401
+ return row;
402
+ }));
389
403
  };
390
404
  const columns = thead && thead.length > 0 ? thead.map((eachHeadEl) => ({
391
405
  title: eachHeadEl.label,
@@ -408,11 +422,14 @@ var AddMoreTable = (props) => {
408
422
  rowElements[eachRow.label] = renderInputElement(eachRow);
409
423
  }
410
424
  if (eachRow.variable_data && Array.isArray(eachRow.variable_data)) {
411
- eachRow.variable_data.forEach((variable) => {
425
+ eachRow.variable_data.forEach((variable, varIndex) => {
412
426
  Object.entries(variable).forEach(([key, value]) => {
413
427
  if (value && value.element && value.label) {
414
428
  rowElements[value.label] = renderInputElement(value);
415
429
  }
430
+ if (key === "icons") {
431
+ rowElements[`icons_${varIndex}`] = /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("button", { onClick: () => onHandleDelete(eachRow.id) }, "delete"), varIndex === eachRow.variable_data.length - 1 && /* @__PURE__ */ React12.createElement("button", { onClick: () => onHandleVariableData(eachRow.id) }, "plus"));
432
+ }
416
433
  });
417
434
  });
418
435
  }
@@ -421,7 +438,7 @@ var AddMoreTable = (props) => {
421
438
  "#": index + 1,
422
439
  ...eachRow,
423
440
  ...rowElements,
424
- actions: /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("button", { onClick: () => onHandleDelete(eachRow.id) }, /* @__PURE__ */ React12.createElement(DeleteOutlined, null)), /* @__PURE__ */ React12.createElement("button", { onClick: () => onAddVariableData(index) }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)), index === rows.length - 1 && /* @__PURE__ */ React12.createElement("button", { onClick: onHandleRows }, /* @__PURE__ */ React12.createElement(PlusOutlined, null)))
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)))
425
442
  };
426
443
  });
427
444
  if (!columns.some((col) => isColumnType(col) && col.dataIndex === "actions")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.11-Beta24",
3
+ "version": "0.0.11-Beta25",
4
4
  "description": "Apex cura React components library",
5
5
  "keywords": [
6
6
  "apex cura",