datastake-daf 0.6.104 → 0.6.105

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.
@@ -3,7 +3,7 @@ import axios from 'axios';
3
3
  import { getToken } from '../../../../../helpers/Token';
4
4
  import { findOptions } from '../../../../../helpers/StringHelper';
5
5
 
6
- export const ajaxSelectFieldData = async (value, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app) => {
6
+ export const ajaxSelectFieldData = async (value, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app, formValues = {}) => {
7
7
  const url = getApiBaseUrl();
8
8
 
9
9
  const queryOptionsApps = ["kota", "nashiriki", "straatos"];
@@ -30,23 +30,35 @@ export const ajaxSelectFieldData = async (value, config, getApiBaseUrl = () => {
30
30
  let filters = {};
31
31
 
32
32
  if (methodWithFilters.includes('(') && methodWithFilters.includes(')')) {
33
- method = methodWithFilters.split('(')[0];
34
-
35
- const filtersMatch = methodWithFilters.match(/\((.*)\)/s);
36
- if (filtersMatch && filtersMatch[1]) {
37
- try {
38
- filters = JSON.parse(filtersMatch[1]);
39
- } catch (error) {
40
- console.error('Error parsing filters:', error);
41
- filters = {};
42
- }
33
+ method = methodWithFilters.split('(')[0];
34
+
35
+ const filtersMatch = methodWithFilters.match(/\((.*)\)/s);
36
+ if (filtersMatch && filtersMatch[1]) {
37
+ try {
38
+ const parsedFilters = JSON.parse(filtersMatch[1]);
39
+
40
+ filters = {};
41
+ Object.keys(parsedFilters).forEach(filterKey => {
42
+ const fieldName = parsedFilters[filterKey];
43
+ const formValue = formValues[fieldName];
44
+
45
+ if (formValue !== undefined &&
46
+ formValue !== null &&
47
+ formValue !== '' &&
48
+ formValue !== fieldName) {
49
+ filters[filterKey] = formValue;
50
+ }
51
+ });
52
+ } catch (error) {
53
+ console.error('Error parsing filters:', error);
54
+ filters = {};
43
55
  }
44
56
  }
45
-
57
+ }
46
58
  try {
47
59
  const response = await axios.post(
48
60
  endpoint,
49
- {
61
+ {
50
62
  entity,
51
63
  method: method,
52
64
  mapper: JSON.parse(mapper),
@@ -73,13 +85,13 @@ export const ajaxSelectFieldData = async (value, config, getApiBaseUrl = () => {
73
85
  }
74
86
  }
75
87
 
76
- export const AjaxSelectRenderer = ({ value, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app }) => {
88
+ export const AjaxSelectRenderer = ({ value, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app, formValues = {} }) => {
77
89
  const [displayValue, setDisplayValue] = useState('Loading...');
78
90
 
79
91
  useEffect(() => {
80
92
  const fetchData = async () => {
81
93
  try {
82
- const data = await ajaxSelectFieldData(value, config, getApiBaseUrl, getAppHeader, app);
94
+ const data = await ajaxSelectFieldData(value, config, getApiBaseUrl, getAppHeader, app, formValues);
83
95
 
84
96
  if (Array.isArray(data) && data.length > 0) {
85
97
  const option = findOptions(value, data);
@@ -98,7 +110,7 @@ export const AjaxSelectRenderer = ({ value, config, getApiBaseUrl = () => {}, ge
98
110
  } else {
99
111
  setDisplayValue(value || 'No configuration');
100
112
  }
101
- }, [value, config, getApiBaseUrl]);
113
+ }, [value, config, getApiBaseUrl, formValues]);
102
114
 
103
115
  return <span>{displayValue}</span>;
104
116
  };
@@ -72,7 +72,7 @@ export const processConditionalTableKeys = (tableKeys, item) => {
72
72
  return processedKeys;
73
73
  };
74
74
 
75
- export const renderFieldData = (type, value, user, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app, allValues) => {
75
+ export const renderFieldData = (type, value, user, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app, allValues, formValues = {}) => {
76
76
  switch(type) {
77
77
  case 'year':
78
78
  return value !== '-' ? renderDateFormatted(value, 'YYYY', 'en') : '-';
@@ -92,7 +92,14 @@ export const renderFieldData = (type, value, user, config, getApiBaseUrl = () =>
92
92
  return option.join(', ');
93
93
  }
94
94
  case 'ajaxSelect':
95
- return <AjaxSelectRenderer value={value} config={config} getApiBaseUrl={getApiBaseUrl} getAppHeader={getAppHeader} app={app} />;
95
+ return <AjaxSelectRenderer
96
+ value={value}
97
+ config={config}
98
+ getApiBaseUrl={getApiBaseUrl}
99
+ getAppHeader={getAppHeader}
100
+ app={app}
101
+ formValues={formValues}
102
+ />;
96
103
  case 'percentage':
97
104
  return `${value} %`;
98
105
  case 'geolocation': {
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { renderFieldData } from './fieldData';
3
3
 
4
- export const renderValue = ({ value, hasChildren, config, user, getApiBaseUrl = () => {}, getAppHeader = () => {}, app }) => {
4
+ export const renderValue = ({ value, hasChildren, config, user, getApiBaseUrl = () => {}, getAppHeader = () => {}, app, allData = {} }) => {
5
5
  if (config?.type === 'groupInputs') {
6
6
  if (!config?.inputs) return null;
7
7
 
@@ -28,7 +28,7 @@ export const renderValue = ({ value, hasChildren, config, user, getApiBaseUrl =
28
28
  return String(inputValue);
29
29
  }
30
30
  }).filter(val => val !== '');
31
-
31
+ console.log({allData})
32
32
  const combinedValue = values.join(' ');
33
33
  return combinedValue ? <span className="tree-value groupInputs-type">{combinedValue}</span> : <span className="tree-value empty">-</span>;
34
34
  }
@@ -59,7 +59,7 @@ export const renderValue = ({ value, hasChildren, config, user, getApiBaseUrl =
59
59
  cssClass += ' empty';
60
60
  }
61
61
 
62
- displayValue = renderFieldData(fieldType, displayValue, user, config, getApiBaseUrl, getAppHeader, app, value);
62
+ displayValue = renderFieldData(fieldType, displayValue, user, config, getApiBaseUrl, getAppHeader, app, value, allData);
63
63
 
64
64
  return <span className={cssClass}>{displayValue}</span>;
65
65
  };