datastake-daf 0.6.101 → 0.6.102

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.101",
3
+ "version": "0.6.102",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -30,8 +30,6 @@ export default function AjaxSubGroup({
30
30
  const { t } = useEditContext();
31
31
  const isAjaxModal = useMemo(() => !!form?.meta?.namespace, [form]);
32
32
 
33
- console.log({form, options, k, excludedKeys, values, i, formTitles, data});
34
-
35
33
  const formScope = useMemo(() => {
36
34
  const val = form.meta.formScope;
37
35
  let toReturn = val;
@@ -0,0 +1,106 @@
1
+ import React, { useMemo } from 'react';
2
+ import useAjaxModal from '../utils/useAjaxModal';
3
+ import { handleDataLinkWithTableKeys } from './dataLinkHandler';
4
+
5
+ const AjaxSubGroup = ({
6
+ config,
7
+ value,
8
+ allData,
9
+ level,
10
+ t,
11
+ rootForm,
12
+ user,
13
+ getApiBaseUrl = () => {},
14
+ getAppHeader = () => {},
15
+ app,
16
+ TreeNodeComponent
17
+ }) => {
18
+ const isAjaxModal = useMemo(() => !!config?.meta?.namespace, [config]);
19
+
20
+ const ajaxModalValues = useAjaxModal({
21
+ name: config?.label || 'ajaxSubGroup',
22
+ user,
23
+ namespace: config?.meta?.namespace,
24
+ skipFetch: config?.meta?.skipFetch,
25
+ isAjaxModal,
26
+ formScope: config?.meta?.formScope || 'modal',
27
+ APP: app,
28
+ apiBaseUrl: getApiBaseUrl(),
29
+ _getAppHeader: getAppHeader,
30
+ });
31
+
32
+ const ajaxForm = ajaxModalValues?.form;
33
+
34
+ console.log({ajaxForm});
35
+
36
+ if (ajaxModalValues.isFetching) {
37
+ return (
38
+ <div className="ajax-subgroup-loading" style={{ padding: '20px', textAlign: 'center' }}>
39
+ <span>Loading form configuration...</span>
40
+ </div>
41
+ );
42
+ }
43
+
44
+ const formInputs = Object.values(ajaxForm || {})[0] || {};
45
+ console.log({formInputs})
46
+
47
+ const sortedRecords = value.sort((a, b) => {
48
+ const yearA = parseInt(a.meta?.year || '0');
49
+ const yearB = parseInt(b.meta?.year || '0');
50
+ return yearB - yearA;
51
+ });
52
+
53
+ const children = [];
54
+
55
+ sortedRecords.forEach((record, recordIndex) => {
56
+ const year = record.meta?.year || 'Unknown Year';
57
+
58
+ const fieldKeys = Object.keys(formInputs)
59
+ .filter((inputKey) => {
60
+ const metadataKeys = ['id', 'label', 'position', 'subTitle'];
61
+ if (metadataKeys.includes(inputKey)) {
62
+ return false;
63
+ }
64
+
65
+ const excludedKeys = config?.meta?.excludedKeysView || [];
66
+ return !excludedKeys.includes(inputKey);
67
+ })
68
+ .sort((a, b) => {
69
+ const positionA = formInputs[a]?.position || 0;
70
+ const positionB = formInputs[b]?.position || 0;
71
+ return positionA - positionB;
72
+ });
73
+
74
+ const yearInputs = {};
75
+ fieldKeys.forEach(inputKey => {
76
+ yearInputs[inputKey] = formInputs[inputKey];
77
+ });
78
+
79
+ children.push(
80
+ <TreeNodeComponent
81
+ key={`year-${year}`}
82
+ nodeKey={`year-${year}`}
83
+ config={{
84
+ label: year,
85
+ type: 'header',
86
+ inputs: yearInputs,
87
+ meta: { code: record.datastakeId || '' }
88
+ }}
89
+ value={record}
90
+ level={level + 1}
91
+ isLast={recordIndex === sortedRecords.length - 1}
92
+ t={t}
93
+ rootForm={rootForm}
94
+ allData={record}
95
+ user={user}
96
+ getApiBaseUrl={getApiBaseUrl}
97
+ getAppHeader={getAppHeader}
98
+ app={app}
99
+ />
100
+ );
101
+ });
102
+
103
+ return children;
104
+ };
105
+
106
+ export default AjaxSubGroup;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import AjaxSubGroup from './AjaxSubGroup';
3
+
4
+ export const handleAjaxSubGroupChildren = (props) => {
5
+ if (props.config?.type !== 'ajaxSubGroup' || !Array.isArray(props.value)) {
6
+ return null;
7
+ }
8
+
9
+ return [
10
+ <AjaxSubGroup key="ajax-subgroup" {...props} />
11
+ ];
12
+ };
@@ -19,8 +19,7 @@ export const handleDataLinkGroupWithTableKeys = ({
19
19
  if (!(config.type === 'dataLinkGroup' || config.type === 'dataLink')) {
20
20
  return null;
21
21
  }
22
- console.log({app})
23
-
22
+
24
23
  if (inputConfig?.type !== 'dataLink' || !inputConfig?.meta?.tableKeys) {
25
24
  const parentInputKeys = Object.keys(config.inputs || {});
26
25
  const isHandledBySiblingDataLink = parentInputKeys.some(otherInputKey => {
@@ -41,10 +40,6 @@ export const handleDataLinkGroupWithTableKeys = ({
41
40
  return null;
42
41
  }
43
42
 
44
- if (!(value && typeof value === 'object')) {
45
- return null;
46
- }
47
-
48
43
  const tableKeys = inputConfig.meta.tableKeys;
49
44
  const additionalTableKeys = config.meta?.additionalTableKeys || [];
50
45
  const allTableKeys = [...new Set([...tableKeys, ...additionalTableKeys])];
@@ -88,6 +83,14 @@ export const handleDataLinkGroupWithTableKeys = ({
88
83
  const inputs = {};
89
84
  const values = {};
90
85
 
86
+ const uploadTypeFields = ['documents', 'links', 'pictures', 'videos'];
87
+ const uploadTypeLabels = {
88
+ 'documents': 'File',
89
+ 'links': 'Link',
90
+ 'pictures': 'Image',
91
+ 'videos': 'Video'
92
+ };
93
+
91
94
  tableKeys
92
95
  .filter(tableKey => tableKey !== 'datastakeId')
93
96
  .forEach(tableKey => {
@@ -96,7 +99,9 @@ export const handleDataLinkGroupWithTableKeys = ({
96
99
  if (formInputConfig) {
97
100
  inputs[tableKey] = {
98
101
  ...formInputConfig,
99
- label: formInputConfig.label || formInputConfig.tableLabel || tableKey
102
+ label: uploadTypeFields.includes(tableKey)
103
+ ? uploadTypeLabels[tableKey]
104
+ : (formInputConfig.label || formInputConfig.tableLabel || tableKey)
100
105
  };
101
106
 
102
107
  if (formInputConfig.label && typeof formInputConfig.label === 'object') {
@@ -113,13 +118,14 @@ export const handleDataLinkGroupWithTableKeys = ({
113
118
  }
114
119
  }
115
120
  }
116
- inputs[tableKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || tableKey;
121
+ inputs[tableKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] ||
122
+ (uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey);
117
123
  }
118
124
 
119
125
  values[tableKey] = item?.[tableKey];
120
126
  } else {
121
127
  inputs[tableKey] = {
122
- label: tableKey,
128
+ label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey,
123
129
  type: inputConfig?.type
124
130
  };
125
131
  values[tableKey] = item?.[tableKey];
@@ -138,7 +144,9 @@ export const handleDataLinkGroupWithTableKeys = ({
138
144
 
139
145
  inputs[fieldKey] = {
140
146
  ...formInputConfig,
141
- label: formInputConfig.label || formInputConfig.tableLabel || fieldKey
147
+ label: uploadTypeFields.includes(fieldKey)
148
+ ? uploadTypeLabels[fieldKey]
149
+ : (formInputConfig.label || formInputConfig.tableLabel || fieldKey)
142
150
  };
143
151
 
144
152
  if (formInputConfig.label && typeof formInputConfig.label === 'object') {
@@ -155,7 +163,8 @@ export const handleDataLinkGroupWithTableKeys = ({
155
163
  }
156
164
  }
157
165
  }
158
- inputs[fieldKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || fieldKey;
166
+ inputs[fieldKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] ||
167
+ (uploadTypeFields.includes(fieldKey) ? uploadTypeLabels[fieldKey] : fieldKey);
159
168
  }
160
169
 
161
170
  values[fieldKey] = item?.[fieldKey];
@@ -173,9 +182,9 @@ export const handleDataLinkGroupWithTableKeys = ({
173
182
  return (
174
183
  <TreeNodeComponent
175
184
  key={`${inputKey}-${itemIndex}`}
176
- nodeKey={datastakeIdValue || `Unknown ID ${itemIndex + 1}`}
185
+ nodeKey={datastakeIdValue || t(`No ID ${itemIndex + 1}`)}
177
186
  config={{
178
- label: datastakeIdValue || `Unknown ID ${itemIndex + 1}`,
187
+ label: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
179
188
  type: 'custom-datalink-group',
180
189
  inputs: inputs
181
190
  }}
@@ -199,9 +208,9 @@ export const handleDataLinkGroupWithTableKeys = ({
199
208
  return (
200
209
  <TreeNodeComponent
201
210
  key={`${inputKey}-group`}
202
- nodeKey={datastakeIdValue || 'Unknown ID'}
211
+ nodeKey={datastakeIdValue || t('No ID')}
203
212
  config={{
204
- label: datastakeIdValue || 'Unknown ID',
213
+ label: datastakeIdValue || t('No ID'),
205
214
  type: 'custom-datalink-group',
206
215
  inputs: inputs
207
216
  }}
@@ -1,5 +1,6 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import useAjaxModal from '../utils/useAjaxModal';
3
+ import { processConditionalTableKeys } from '../utils/fieldData';
3
4
 
4
5
  export const handleDataLinkWithTableKeys = ({
5
6
  inputConfig,
@@ -15,14 +16,9 @@ export const handleDataLinkWithTableKeys = ({
15
16
  app,
16
17
  TreeNodeComponent
17
18
  }) => {
18
-
19
19
  if (inputConfig?.type !== 'dataLink' || !inputConfig?.meta?.tableKeys) {
20
20
  return null;
21
21
  }
22
-
23
- if (!(value && typeof value === 'object')) {
24
- return null;
25
- }
26
22
 
27
23
  const tableKeys = inputConfig.meta.tableKeys;
28
24
  const isAjaxModal = useMemo(() => !!inputConfig?.meta?.namespace, [inputConfig]);
@@ -45,15 +41,36 @@ export const handleDataLinkWithTableKeys = ({
45
41
  const inputs = {};
46
42
  const values = {};
47
43
 
48
- tableKeys
44
+ const uploadTypeFields = ['documents', 'links', 'pictures', 'videos'];
45
+ const uploadTypeLabels = {
46
+ 'documents': 'File',
47
+ 'links': 'Link',
48
+ 'pictures': 'Image',
49
+ 'videos': 'Video'
50
+ };
51
+
52
+ const isUploadFieldEmpty = (fieldKey, itemToCheck) => {
53
+ if (uploadTypeFields.includes(fieldKey)) {
54
+ const itemValue = itemToCheck?.[fieldKey];
55
+ return itemValue === undefined || itemValue === null || (Array.isArray(itemValue) && itemValue.length === 0);
56
+ }
57
+ return false;
58
+ };
59
+
60
+ const processedTableKeys = processConditionalTableKeys(tableKeys, item);
61
+
62
+ processedTableKeys
49
63
  .filter(tableKey => tableKey !== 'datastakeId')
64
+ .filter(tableKey => !isUploadFieldEmpty(tableKey, item))
50
65
  .forEach(tableKey => {
51
66
  const formInputConfig = dataLinkForm?.[tableKey] || dataLinkForm?.['identification']?.[tableKey];
52
67
 
53
68
  if (formInputConfig) {
54
69
  inputs[tableKey] = {
55
70
  ...formInputConfig,
56
- label: formInputConfig.label || formInputConfig.tableLabel || tableKey
71
+ label: uploadTypeFields.includes(tableKey)
72
+ ? uploadTypeLabels[tableKey]
73
+ : (formInputConfig.label || formInputConfig.tableLabel || tableKey)
57
74
  };
58
75
 
59
76
  if (formInputConfig.label && typeof formInputConfig.label === 'object') {
@@ -70,13 +87,14 @@ export const handleDataLinkWithTableKeys = ({
70
87
  }
71
88
  }
72
89
  }
73
- inputs[tableKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || tableKey;
90
+ inputs[tableKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] ||
91
+ (uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey);
74
92
  }
75
93
 
76
94
  values[tableKey] = item?.[tableKey];
77
95
  } else {
78
96
  inputs[tableKey] = {
79
- label: tableKey,
97
+ label: uploadTypeFields.includes(tableKey) ? uploadTypeLabels[tableKey] : tableKey,
80
98
  type: inputConfig?.type
81
99
  };
82
100
  values[tableKey] = item?.[tableKey];
@@ -85,7 +103,13 @@ export const handleDataLinkWithTableKeys = ({
85
103
 
86
104
  if (dataLinkForm?.identification && typeof dataLinkForm.identification === 'object') {
87
105
  Object.keys(dataLinkForm.identification)
88
- .filter(fieldKey => fieldKey !== 'datastakeId' && !tableKeys.includes(fieldKey))
106
+ .filter(fieldKey => {
107
+ if (uploadTypeFields.includes(fieldKey)) {
108
+ return !isUploadFieldEmpty(fieldKey, item);
109
+ }
110
+ return true;
111
+ })
112
+ .filter(fieldKey => fieldKey !== 'datastakeId' && !processedTableKeys.includes(fieldKey))
89
113
  .filter(fieldKey => {
90
114
  const formInputConfig = dataLinkForm.identification[fieldKey];
91
115
  return formInputConfig && typeof formInputConfig === 'object' && !Array.isArray(formInputConfig);
@@ -95,9 +119,10 @@ export const handleDataLinkWithTableKeys = ({
95
119
 
96
120
  inputs[fieldKey] = {
97
121
  ...formInputConfig,
98
- label: formInputConfig.label || formInputConfig.tableLabel || fieldKey
122
+ label: uploadTypeFields.includes(fieldKey)
123
+ ? uploadTypeLabels[fieldKey]
124
+ : (formInputConfig.label || formInputConfig.tableLabel || fieldKey)
99
125
  };
100
-
101
126
  if (formInputConfig.label && typeof formInputConfig.label === 'object') {
102
127
  const dynamicLabelKeys = Object.keys(formInputConfig.label);
103
128
  let resolvedLabel = null;
@@ -112,7 +137,8 @@ export const handleDataLinkWithTableKeys = ({
112
137
  }
113
138
  }
114
139
  }
115
- inputs[fieldKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] || fieldKey;
140
+ inputs[fieldKey].label = resolvedLabel || Object.values(formInputConfig.label)[0] ||
141
+ (uploadTypeFields.includes(fieldKey) ? uploadTypeLabels[fieldKey] : fieldKey);
116
142
  }
117
143
 
118
144
  values[fieldKey] = item?.[fieldKey];
@@ -127,12 +153,16 @@ export const handleDataLinkWithTableKeys = ({
127
153
  const datastakeIdValue = item?.datastakeId;
128
154
  const { inputs, values } = createInputsAndValues(item);
129
155
 
156
+ if (Object.keys(inputs).length === 0) {
157
+ return null;
158
+ }
159
+
130
160
  return (
131
161
  <TreeNodeComponent
132
162
  key={`${inputKey}-${itemIndex}`}
133
- nodeKey={datastakeIdValue || `Unknown ID ${itemIndex + 1}`}
163
+ nodeKey={datastakeIdValue || t(`No ID ${itemIndex + 1}`)}
134
164
  config={{
135
- label: datastakeIdValue || `Unknown ID ${itemIndex + 1}`,
165
+ label: datastakeIdValue || t(`No ID ${itemIndex + 1}`),
136
166
  type: 'custom-datalink',
137
167
  inputs: inputs
138
168
  }}
@@ -153,12 +183,16 @@ export const handleDataLinkWithTableKeys = ({
153
183
  const datastakeIdValue = value?.datastakeId;
154
184
  const { inputs, values } = createInputsAndValues(value);
155
185
 
186
+ if (Object.keys(inputs).length === 0) {
187
+ return null;
188
+ }
189
+
156
190
  return (
157
191
  <TreeNodeComponent
158
192
  key={`${inputKey}-single`}
159
- nodeKey={datastakeIdValue || 'Unknown ID'}
193
+ nodeKey={datastakeIdValue || t('No ID')}
160
194
  config={{
161
- label: datastakeIdValue || 'Unknown ID',
195
+ label: datastakeIdValue || t('No ID'),
162
196
  type: 'custom-datalink',
163
197
  inputs: inputs
164
198
  }}