datastake-daf 0.6.780 → 0.6.782
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/components/index.js +298 -351
- package/dist/pages/index.js +235 -2052
- package/dist/style/datastake/mapbox-gl.css +330 -0
- package/dist/utils/index.js +0 -13
- package/package.json +1 -1
- package/src/@daf/core/components/Dashboard/Map/ChainIcon/Markers/StakeholderMarker.js +76 -9
- package/src/@daf/core/components/Dashboard/Map/ChainIcon/index.js +8 -116
- package/src/@daf/core/components/Dashboard/Map/ChainIcon/utils.js +17 -73
- package/src/@daf/core/components/Dashboard/Map/helper.js +0 -1
- package/src/@daf/core/components/Dashboard/Map/hook.js +29 -64
- package/src/@daf/core/components/Dashboard/Map/style.js +5 -20
- package/src/@daf/hooks/useViewFormUrlParams.js +84 -0
- package/src/@daf/pages/Summary/Activities/PlantingCycle/components/CycleOutcomes/index.jsx +1 -1
- package/src/@daf/pages/Summary/Activities/PlantingCycle/components/PlantingLocations/index.jsx +168 -163
- package/src/@daf/utils/object.js +1 -3
- package/src/pages.js +1 -4
- package/src/utils.js +1 -1
- package/src/@daf/pages/View/hooks/useCallToGetData.js +0 -73
- package/src/@daf/pages/View/hooks/usePrepareForm.js +0 -86
- package/src/@daf/pages/View/hooks/useSubmitSubject.js +0 -40
- package/src/@daf/pages/View/hooks/useViewActions.js +0 -83
- package/src/@daf/pages/View/hooks/useViewPermissions.js +0 -75
- package/src/@daf/pages/View/hooks/useViewUrlParams.js +0 -93
- package/src/@daf/pages/View/index.jsx +0 -286
package/src/@daf/pages/Summary/Activities/PlantingCycle/components/PlantingLocations/index.jsx
CHANGED
|
@@ -6,171 +6,176 @@ import CustomIcon from '../../../../../../../../src/@daf/core/components/Icon/Cu
|
|
|
6
6
|
import { renderDateFormatted } from '../../../../../../../../src/helpers/Forms';
|
|
7
7
|
|
|
8
8
|
const PlantingLocations = ({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
id,
|
|
10
|
+
getSummaryDetail,
|
|
11
|
+
loading = false,
|
|
12
|
+
t = (s) => s
|
|
13
13
|
}) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
14
|
+
const defaultConfig = useMemo(
|
|
15
|
+
() => ({
|
|
16
|
+
basepath: "planting-cycle",
|
|
17
|
+
url: `/summary/${id}/locations`,
|
|
18
|
+
stop: !id,
|
|
19
|
+
}),
|
|
20
|
+
[id],
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const customGetData = useMemo(() => {
|
|
24
|
+
if (getSummaryDetail && id) {
|
|
25
|
+
return ({ url, params = {} }) => {
|
|
26
|
+
const match = url.match(/\/summary\/[^/]+\/(.+)/);
|
|
27
|
+
if (match) {
|
|
28
|
+
const [, type] = match;
|
|
29
|
+
return getSummaryDetail(id, type, params);
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Invalid URL format: ${url}`);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}, [getSummaryDetail, id]);
|
|
36
|
+
|
|
37
|
+
const { loading: plantingLocationsLoading, data: plantingLocationsData } = useWidgetFetch({
|
|
38
|
+
config: defaultConfig,
|
|
39
|
+
getData: customGetData
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const mappedData = useMemo(() => {
|
|
44
|
+
if (!plantingLocationsData || !plantingLocationsData.events) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { locations = [], events } = plantingLocationsData;
|
|
49
|
+
|
|
50
|
+
// Filter events that have valid GPS coordinates
|
|
51
|
+
const eventsWithGPS = events.filter(event =>
|
|
52
|
+
event.locationCheckArrival &&
|
|
53
|
+
event.locationCheckArrival.latitude &&
|
|
54
|
+
event.locationCheckArrival.longitude
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return eventsWithGPS.map((event, index) => {
|
|
58
|
+
const locationCheckArrival = event.locationCheckArrival;
|
|
59
|
+
|
|
60
|
+
const matchingLocation = locations.find(location =>
|
|
61
|
+
locationCheckArrival.name === location.name ||
|
|
62
|
+
locationCheckArrival._id === location.id ||
|
|
63
|
+
location.id === locationCheckArrival._id
|
|
64
|
+
) || locations[0];
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
const area = matchingLocation?.perimeter ? matchingLocation.perimeter.map(coord =>
|
|
68
|
+
Array.isArray(coord) && coord.length >= 2
|
|
69
|
+
? [coord[1], coord[0]]
|
|
70
|
+
: coord
|
|
71
|
+
) : null;
|
|
72
|
+
|
|
73
|
+
// Only include area if it has at least 3 valid coordinates
|
|
74
|
+
const validArea = area && Array.isArray(area) && area.length >= 3 ? area : null;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
const gps = {
|
|
78
|
+
latitude: locationCheckArrival.latitude,
|
|
79
|
+
longitude: locationCheckArrival.longitude
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const color = "#15FFFFB2"
|
|
84
|
+
|
|
85
|
+
const locationName = matchingLocation?.name || locationCheckArrival.name || 'Planting Location';
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
_id: locationCheckArrival._id || event._id || {},
|
|
89
|
+
area: validArea,
|
|
90
|
+
color: color,
|
|
91
|
+
datastakeId: `LOC-${String(index + 1).padStart(9, '0')}`,
|
|
92
|
+
gps: gps,
|
|
93
|
+
id: matchingLocation?.id || locationCheckArrival._id || `event-${index}`,
|
|
94
|
+
name: event.name || t("Activity Start"),
|
|
95
|
+
date: event.date,
|
|
96
|
+
subTitle: event.date ? renderDateFormatted(event.date, "DD MMM YY") : locationName,
|
|
97
|
+
plotName: locationName,
|
|
98
|
+
territoryTitle: locationName,
|
|
99
|
+
type: 'Planting Location'
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
}, [plantingLocationsData, t]);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<section>
|
|
106
|
+
<Widget
|
|
107
|
+
title={t("Planting Locations")}
|
|
108
|
+
className="no-px h-w-btn-header no-pt-body no-p-body no-pb-body"
|
|
109
|
+
style={{ height: '100%', display: 'flex', flexDirection: 'column' }}
|
|
110
|
+
>
|
|
111
|
+
<MineSiteMap
|
|
112
|
+
data={mappedData}
|
|
113
|
+
link={false}
|
|
114
|
+
style={{ height: '100%', width: '100%' }}
|
|
115
|
+
maxZoom={18}
|
|
116
|
+
isSatellite={true}
|
|
117
|
+
onClickLink={() => { }}
|
|
118
|
+
onFilterChange={() => { }}
|
|
119
|
+
primaryLink
|
|
120
|
+
showSider={false}
|
|
121
|
+
renderTooltipForLocation={(data) => {
|
|
122
|
+
const coordinates = data.gps?.latitude && data.gps?.longitude
|
|
123
|
+
? convertDMS(data.gps.latitude, data.gps.longitude)
|
|
124
|
+
: null;
|
|
125
|
+
|
|
126
|
+
if (!coordinates) {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const iconColor = "#016C6E"; // Activity Start color
|
|
131
|
+
|
|
132
|
+
return [
|
|
133
|
+
{
|
|
134
|
+
label: t("Coordinates"),
|
|
135
|
+
value: (
|
|
136
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '6px', flexWrap: 'nowrap' }}>
|
|
137
|
+
{/* Latitude icon (vertical) */}
|
|
138
|
+
<div style={{ display: 'flex', alignItems: 'center' }}>
|
|
139
|
+
<CustomIcon
|
|
140
|
+
name="SpacingHeight"
|
|
141
|
+
width={14}
|
|
142
|
+
height={14}
|
|
143
|
+
color={iconColor}
|
|
144
|
+
/>
|
|
145
|
+
<span style={{ fontWeight: 600, marginLeft: '4px' }}>{coordinates[0]}</span>
|
|
146
|
+
</div>
|
|
147
|
+
{/* Longitude icon (horizontal) */}
|
|
148
|
+
<div style={{ display: 'flex', alignItems: 'center' }}>
|
|
149
|
+
<CustomIcon
|
|
150
|
+
name="SpacingWidth"
|
|
151
|
+
width={14}
|
|
152
|
+
height={14}
|
|
153
|
+
color={iconColor}
|
|
154
|
+
/>
|
|
155
|
+
<span style={{ fontWeight: 600, marginLeft: '4px' }}>{coordinates[1]}</span>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
),
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
}}
|
|
162
|
+
renderTooltipForTerritory={(data) => {
|
|
163
|
+
return [
|
|
164
|
+
{
|
|
165
|
+
label: t("Plot Name"),
|
|
166
|
+
value: data.plotName || data.name || "--",
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
}}
|
|
170
|
+
renderTooltipTags={() => { }}
|
|
171
|
+
type="location-territory"
|
|
172
|
+
/>
|
|
173
|
+
</Widget>
|
|
174
|
+
</section>
|
|
175
|
+
);
|
|
173
176
|
};
|
|
174
177
|
|
|
175
178
|
export default PlantingLocations;
|
|
176
179
|
|
|
180
|
+
|
|
181
|
+
|
package/src/@daf/utils/object.js
CHANGED
package/src/pages.js
CHANGED
|
@@ -19,7 +19,4 @@ export { default as TablePage } from './@daf/pages/TablePage/index.jsx';
|
|
|
19
19
|
export { default as OperatorSummary } from './@daf/pages/Summary/Operator/index.jsx';
|
|
20
20
|
export { default as RestorationActivitySummary } from './@daf/pages/Summary/Activities/Restoration/index.jsx';
|
|
21
21
|
export { default as PlantingCycleSummary } from './@daf/pages/Summary/Activities/PlantingCycle/index.jsx';
|
|
22
|
-
export { default as MineSummary } from './@daf/pages/Summary/Minesite/index.jsx';
|
|
23
|
-
|
|
24
|
-
// View
|
|
25
|
-
export { default as View } from './@daf/pages/View/index.jsx';
|
|
22
|
+
export { default as MineSummary } from './@daf/pages/Summary/Minesite/index.jsx';
|
package/src/utils.js
CHANGED
|
@@ -27,7 +27,7 @@ export { default as locales } from './constants/locales/index.js';
|
|
|
27
27
|
|
|
28
28
|
export { getTagColor } from "./@daf/utils/productTag.js";
|
|
29
29
|
|
|
30
|
-
export { convertUndefinedToNull
|
|
30
|
+
export { convertUndefinedToNull } from './@daf/utils/object'
|
|
31
31
|
|
|
32
32
|
export { default as ErrorFormat, formatErrors } from './helpers/ErrorFormater'
|
|
33
33
|
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { useRef, useEffect } from "react";
|
|
2
|
-
import { hasKeyInObject } from "../../../../@daf/utils/object.js";
|
|
3
|
-
import { getNkey } from "../../../../@daf/core/components/ViewForm/helper.js";
|
|
4
|
-
|
|
5
|
-
export const useCallToGetData = ({
|
|
6
|
-
namespaceConfig,
|
|
7
|
-
namespace,
|
|
8
|
-
allData,
|
|
9
|
-
id,
|
|
10
|
-
isSupported,
|
|
11
|
-
namespaceGet,
|
|
12
|
-
source,
|
|
13
|
-
version,
|
|
14
|
-
user,
|
|
15
|
-
setLoading,
|
|
16
|
-
APP,
|
|
17
|
-
}) => {
|
|
18
|
-
const isFirstRender = useRef(true);
|
|
19
|
-
|
|
20
|
-
const callToGetData = (_doCall = false) => {
|
|
21
|
-
const dKey = namespaceConfig.dataKey;
|
|
22
|
-
const nKey = `${APP}-${getNkey(namespace)}`;
|
|
23
|
-
const doCall = _doCall
|
|
24
|
-
? true
|
|
25
|
-
: hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey)
|
|
26
|
-
? allData[dKey][nKey]?.data?.datastakeId !== id
|
|
27
|
-
: true;
|
|
28
|
-
if (doCall) {
|
|
29
|
-
if (isSupported) {
|
|
30
|
-
namespaceGet[namespace]();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (isFirstRender.current) {
|
|
37
|
-
isFirstRender.current = false;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
callToGetData(true);
|
|
41
|
-
}, [source, version]);
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
callToGetData(true);
|
|
45
|
-
}, [id, namespace, user.language]);
|
|
46
|
-
|
|
47
|
-
const onStorageUpdate = (e) => {
|
|
48
|
-
const { key, newValue } = e;
|
|
49
|
-
if (key === `${id}-loading` && newValue) {
|
|
50
|
-
setLoading(newValue);
|
|
51
|
-
}
|
|
52
|
-
if (key === `${id}-updated` && newValue) {
|
|
53
|
-
setLoading(true);
|
|
54
|
-
callToGetData();
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
window.addEventListener("storage", onStorageUpdate);
|
|
60
|
-
return () => {
|
|
61
|
-
window.removeEventListener("storage", onStorageUpdate);
|
|
62
|
-
};
|
|
63
|
-
}, []);
|
|
64
|
-
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
setLoading(true);
|
|
67
|
-
}, [namespace]);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
callToGetData,
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from "react";
|
|
2
|
-
import { hasKeyInObject } from "../../../../@daf/utils/object.js";
|
|
3
|
-
|
|
4
|
-
export const usePrepareForm = ({
|
|
5
|
-
namespaceConfig,
|
|
6
|
-
allData,
|
|
7
|
-
id,
|
|
8
|
-
namespace,
|
|
9
|
-
t,
|
|
10
|
-
mode,
|
|
11
|
-
APP,
|
|
12
|
-
viewConfig,
|
|
13
|
-
}) => {
|
|
14
|
-
const [form, setForm] = useState({});
|
|
15
|
-
const [data, setData] = useState({});
|
|
16
|
-
const [groups, setGroups] = useState({});
|
|
17
|
-
const [linkingForms, setLinkingForms] = useState({});
|
|
18
|
-
const [loading, setLoading] = useState(true);
|
|
19
|
-
const [notFound, setNotFound] = useState(false);
|
|
20
|
-
|
|
21
|
-
const prepareForm = (currentView) => {
|
|
22
|
-
const dKey = namespaceConfig.dataKey;
|
|
23
|
-
const nKey = `${APP}-${currentView}`;
|
|
24
|
-
|
|
25
|
-
if (hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey)) {
|
|
26
|
-
const {
|
|
27
|
-
form = {},
|
|
28
|
-
data = {},
|
|
29
|
-
config = {},
|
|
30
|
-
linkingForms = {},
|
|
31
|
-
} = JSON.parse(JSON.stringify(allData[dKey][nKey] || {}));
|
|
32
|
-
|
|
33
|
-
if (data.datastakeId === id || id === "user") {
|
|
34
|
-
if (viewConfig.linkingSubjects.includes(namespace)) {
|
|
35
|
-
setForm({
|
|
36
|
-
...form,
|
|
37
|
-
linking: {
|
|
38
|
-
position: 100,
|
|
39
|
-
excludeFromEdit: true,
|
|
40
|
-
label: t("Linked Subjects"),
|
|
41
|
-
template: "linkingSubjects",
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
setForm(form);
|
|
46
|
-
}
|
|
47
|
-
setData(data);
|
|
48
|
-
setGroups(config.groups || {});
|
|
49
|
-
setLinkingForms(linkingForms);
|
|
50
|
-
setLoading(false);
|
|
51
|
-
setNotFound(false);
|
|
52
|
-
} else if (!data.id) {
|
|
53
|
-
if (mode === "proxy") {
|
|
54
|
-
window.location.reload();
|
|
55
|
-
} else {
|
|
56
|
-
setLoading(false);
|
|
57
|
-
setNotFound(true);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const getCertainData = allData[namespaceConfig.dataKey];
|
|
64
|
-
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
if(namespace && namespaceConfig) {
|
|
67
|
-
prepareForm(namespaceConfig.view);
|
|
68
|
-
}
|
|
69
|
-
}, [getCertainData, namespaceConfig]);
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
form,
|
|
73
|
-
setForm,
|
|
74
|
-
data,
|
|
75
|
-
setData,
|
|
76
|
-
groups,
|
|
77
|
-
setGroups,
|
|
78
|
-
linkingForms,
|
|
79
|
-
setLinkingForms,
|
|
80
|
-
loading,
|
|
81
|
-
setLoading,
|
|
82
|
-
notFound,
|
|
83
|
-
setNotFound,
|
|
84
|
-
prepareForm,
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback } from "react";
|
|
2
|
-
|
|
3
|
-
export const submitSubjectData = async (namespace, data, serviceMap) => {
|
|
4
|
-
const service = serviceMap[namespace];
|
|
5
|
-
if (!service) {
|
|
6
|
-
throw new Error(`No service found for namespace: ${namespace}`);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const response = await service.submitStep(
|
|
10
|
-
data,
|
|
11
|
-
data.datastakeId || data.id
|
|
12
|
-
);
|
|
13
|
-
return response.data;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const useSubmitSubject = ({namespace, data, serviceMap}) => {
|
|
17
|
-
const [isDisabled, setIsDisabled] = useState(false);
|
|
18
|
-
const [loading, setLoading] = useState(false);
|
|
19
|
-
const [isPublished, setIsPublished] = useState(false);
|
|
20
|
-
|
|
21
|
-
const submitSubject = useCallback(async () => {
|
|
22
|
-
try {
|
|
23
|
-
setLoading(true);
|
|
24
|
-
const response = await submitSubjectData(namespace, data, serviceMap);
|
|
25
|
-
setIsDisabled(response.published);
|
|
26
|
-
setIsPublished(response.published);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
console.error("Submit error:", error);
|
|
29
|
-
} finally {
|
|
30
|
-
setLoading(false);
|
|
31
|
-
}
|
|
32
|
-
}, [namespace, data]);
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
submitSubject,
|
|
36
|
-
isDisabled,
|
|
37
|
-
submitLoading: loading,
|
|
38
|
-
isPublished,
|
|
39
|
-
};
|
|
40
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
export const useViewActions = ({
|
|
4
|
-
namespace,
|
|
5
|
-
data,
|
|
6
|
-
isSupported,
|
|
7
|
-
canEdit,
|
|
8
|
-
versionUrl,
|
|
9
|
-
sourceUrl,
|
|
10
|
-
getEditLink,
|
|
11
|
-
submitSubject,
|
|
12
|
-
isDisabled,
|
|
13
|
-
setOpenRecordsModal,
|
|
14
|
-
goBackFromSource,
|
|
15
|
-
push,
|
|
16
|
-
getRedirectLink,
|
|
17
|
-
t,
|
|
18
|
-
viewConfig,
|
|
19
|
-
buttonActions,
|
|
20
|
-
}) => {
|
|
21
|
-
const [pageActions, setPageActions] = useState([]);
|
|
22
|
-
const [extraPageActions, setExtraPageActions] = useState([]);
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
const actions = [];
|
|
26
|
-
const extraActions = [];
|
|
27
|
-
|
|
28
|
-
if (!isSupported) {
|
|
29
|
-
setPageActions([]);
|
|
30
|
-
setExtraPageActions([]);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (canEdit) {
|
|
35
|
-
if (viewConfig.namespacesWithoutActionButtons.includes(namespace)) {
|
|
36
|
-
if (viewConfig.editOnlyButton.includes(namespace)) {
|
|
37
|
-
if (versionUrl && sourceUrl) {
|
|
38
|
-
actions.push(buttonActions.createBackButton(t, goBackFromSource));
|
|
39
|
-
} else {
|
|
40
|
-
actions.push(buttonActions.createEditButton(t, getEditLink));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
if (versionUrl && sourceUrl) {
|
|
45
|
-
actions.push(buttonActions.createBackButton(t, goBackFromSource));
|
|
46
|
-
} else {
|
|
47
|
-
actions.push(buttonActions.createSubmitButton(t, submitSubject, isDisabled, data));
|
|
48
|
-
actions.push(buttonActions.createEditButton(t, getEditLink));
|
|
49
|
-
// actions.push(createRecordsButton(t, setOpenRecordsModal));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (viewConfig.summaryNamespaces.includes(namespace)) {
|
|
55
|
-
extraActions.push(
|
|
56
|
-
buttonActions.createSummaryButton(t, namespace, data, push, getRedirectLink)
|
|
57
|
-
);
|
|
58
|
-
extraActions.push(
|
|
59
|
-
buttonActions.createRecordsButton(t, setOpenRecordsModal)
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
setPageActions(actions);
|
|
64
|
-
setExtraPageActions(extraActions);
|
|
65
|
-
}, [
|
|
66
|
-
namespace,
|
|
67
|
-
data,
|
|
68
|
-
isSupported,
|
|
69
|
-
canEdit,
|
|
70
|
-
versionUrl,
|
|
71
|
-
sourceUrl,
|
|
72
|
-
isDisabled,
|
|
73
|
-
t,
|
|
74
|
-
getEditLink,
|
|
75
|
-
submitSubject,
|
|
76
|
-
goBackFromSource,
|
|
77
|
-
setOpenRecordsModal,
|
|
78
|
-
push,
|
|
79
|
-
getRedirectLink,
|
|
80
|
-
]);
|
|
81
|
-
|
|
82
|
-
return { pageActions, extraPageActions };
|
|
83
|
-
};
|