@apexcura/ui-components 0.0.11-Beta3 → 0.0.11-Beta31

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