@maro-tech/card 0.2.8 → 0.2.9

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.
@@ -707,19 +707,24 @@ class TableComponent {
707
707
  this.emitAction(event.action, event.row);
708
708
  }
709
709
  onCellChange(event) {
710
- const config = this.editableColumns().find((item) => item.key === event.column.key);
711
- if (!config?.api)
710
+ const config = this.editableColumn(event.column.key);
711
+ if (!config)
712
712
  return;
713
+ const editAction = Array.isArray(event.row['actions'])
714
+ ? event.row['actions'].find((action) => String(action.id || '') === 'edit')
715
+ : undefined;
716
+ const formId = String(editAction?.formId || '').trim();
717
+ const api = config.api || (formId
718
+ ? `/api/${encodeURIComponent(formId)}`
719
+ : `/api/crud/${encodeURIComponent(this.tableName())}/${encodeURIComponent(String(event.row['id'] || ''))}`);
713
720
  this.emitAction({
714
721
  id: `edit:${config.key}`,
715
722
  label: 'Зберегти',
716
723
  type: 'api',
717
- api: config.api,
724
+ api,
718
725
  method: config.method || 'PATCH',
719
726
  payload: {
720
- ...event.row,
721
727
  ...(config.payload || {}),
722
- id: event.row['id'],
723
728
  [config.bindKey || config.key]: event.value,
724
729
  },
725
730
  }, event.row);
@@ -783,10 +788,9 @@ class TableComponent {
783
788
  });
784
789
  }
785
790
  setColumns() {
786
- const editable = this.editableColumns();
787
791
  this.columnsSignal.set(this.sourceColumns.filter((column) => !column['hidden']).map((column) => {
788
792
  const key = String(column['id'] || '');
789
- const config = editable.find((item) => item.key === key);
793
+ const config = this.editableConfig(column);
790
794
  return {
791
795
  key,
792
796
  labelKey: String(column['label'] || key),
@@ -796,12 +800,14 @@ class TableComponent {
796
800
  sortable: true,
797
801
  link: column['link'],
798
802
  editable: !!config,
799
- editableCondition: String(this.config?.props?.['editableCondition'] || config?.['condition'] || ''),
803
+ editableCondition: String(config?.['condition'] || ''),
800
804
  editor: config?.editor,
801
805
  bindKey: config?.bindKey || key,
802
806
  options: config?.options || [],
803
807
  data: config?.data,
804
- dataParams: config?.dataParams,
808
+ dataParams: config?.dataParams
809
+ ? resolveTemplateValue(config.dataParams, this.data, { interpolate: true })
810
+ : undefined,
805
811
  placeholder: config?.placeholder,
806
812
  };
807
813
  }));
@@ -870,11 +876,25 @@ class TableComponent {
870
876
  tableName() {
871
877
  return String(this.config?.props?.['table'] || this.config?.props?.['entity'] || '').trim();
872
878
  }
873
- editableColumns() {
874
- const value = this.config?.props?.['editableColumns'];
875
- return Array.isArray(value)
876
- ? value.filter((item) => !!item && typeof item === 'object' && !!String(item.key || '').trim())
877
- : [];
879
+ editableConfig(column) {
880
+ const value = column['editable'];
881
+ if (value === true) {
882
+ const key = String(column['id'] || '');
883
+ return {
884
+ key,
885
+ bindKey: key,
886
+ editor: column['data'] ? 'select' : 'text',
887
+ data: column['data'],
888
+ };
889
+ }
890
+ return value && typeof value === 'object' && !Array.isArray(value)
891
+ ? value
892
+ : undefined;
893
+ }
894
+ editableColumn(key) {
895
+ const column = this.sourceColumns.find((item) => String(item['id'] || '') === key);
896
+ const config = column ? this.editableConfig(column) : undefined;
897
+ return config ? { ...config, key } : undefined;
878
898
  }
879
899
  tableEndpoint(table) {
880
900
  const params = new URLSearchParams({