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