datastake-daf 0.6.781 → 0.6.783
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 +383 -317
- package/dist/pages/index.js +2577 -258
- package/dist/utils/index.js +13 -0
- package/package.json +1 -1
- package/src/@daf/core/components/Dashboard/Map/ChainIcon/Markers/StakeholderMarker.js +9 -76
- package/src/@daf/core/components/Dashboard/Map/ChainIcon/index.js +116 -8
- package/src/@daf/core/components/Dashboard/Map/ChainIcon/utils.js +73 -17
- package/src/@daf/core/components/Dashboard/Map/helper.js +1 -0
- package/src/@daf/core/components/Dashboard/Map/hook.js +64 -29
- package/src/@daf/core/components/Dashboard/Map/style.js +20 -5
- package/src/@daf/pages/Summary/Activities/PlantingCycle/components/CycleOutcomes/index.jsx +1 -1
- package/src/@daf/pages/Summary/Activities/PlantingCycle/components/PlantingLocations/index.jsx +2 -2
- package/src/@daf/pages/Template/components/LinkingTemplate/columns.js +95 -0
- package/src/@daf/pages/Template/components/LinkingTemplate/config.js +75 -0
- package/src/@daf/pages/Template/components/LinkingTemplate/index.jsx +119 -0
- package/src/@daf/pages/Template/index.jsx +19 -0
- package/src/@daf/pages/View/hooks/useCallToGetData.js +73 -0
- package/src/@daf/pages/View/hooks/usePrepareForm.js +86 -0
- package/src/@daf/pages/View/hooks/useSubmitSubject.js +40 -0
- package/src/@daf/pages/View/hooks/useViewActions.js +83 -0
- package/src/@daf/pages/View/hooks/useViewPermissions.js +74 -0
- package/src/@daf/pages/View/hooks/useViewUrlParams.js +93 -0
- package/src/@daf/pages/View/index.jsx +325 -0
- package/src/@daf/utils/object.js +3 -1
- package/src/pages.js +4 -1
- package/src/utils.js +1 -1
- package/dist/style/datastake/mapbox-gl.css +0 -330
- package/src/@daf/hooks/useViewFormUrlParams.js +0 -84
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useMemo } from "react";
|
|
2
|
+
|
|
3
|
+
export const useViewUrlParams = ({
|
|
4
|
+
params,
|
|
5
|
+
push,
|
|
6
|
+
pathname,
|
|
7
|
+
search,
|
|
8
|
+
searchParams,
|
|
9
|
+
setSearchParams,
|
|
10
|
+
}) => {
|
|
11
|
+
const [namespace, setNamespace] = useState(params?.namespace);
|
|
12
|
+
const [id, setId] = useState(params?.id);
|
|
13
|
+
const [group, setGroup] = useState(params?.group);
|
|
14
|
+
const [subsection, setSubSection] = useState(params?.subsection);
|
|
15
|
+
const sourceUrl = searchParams.get("source");
|
|
16
|
+
const versionUrl = searchParams.get("version");
|
|
17
|
+
const [source, setSource] = useState(sourceUrl || null);
|
|
18
|
+
const [version, setVersion] = useState(versionUrl || null);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if ((id && params.id !== id) || (namespace && namespace !== params.namespace)) {
|
|
22
|
+
setGroup(undefined);
|
|
23
|
+
setSubSection(undefined);
|
|
24
|
+
// setSubGroup(undefined);
|
|
25
|
+
} else {
|
|
26
|
+
setGroup(params.group);
|
|
27
|
+
setSubSection(params.subsection);
|
|
28
|
+
// setSubGroup(params.subgroup);
|
|
29
|
+
}
|
|
30
|
+
setNamespace(params.namespace);
|
|
31
|
+
setId(params.id);
|
|
32
|
+
}, [params]);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (source && version) {
|
|
36
|
+
const newParams = new URLSearchParams(searchParams);
|
|
37
|
+
newParams.set("source", source);
|
|
38
|
+
newParams.set("version", version);
|
|
39
|
+
setSearchParams(newParams);
|
|
40
|
+
}
|
|
41
|
+
}, [source, version]);
|
|
42
|
+
|
|
43
|
+
const goBackFromSource = useCallback(() => {
|
|
44
|
+
const params = new URLSearchParams(searchParams);
|
|
45
|
+
params.delete("source");
|
|
46
|
+
params.delete("version");
|
|
47
|
+
setSearchParams(params);
|
|
48
|
+
setVersion(null);
|
|
49
|
+
setSource(null);
|
|
50
|
+
}, [searchParams, setSearchParams]);
|
|
51
|
+
|
|
52
|
+
const getEditLink = useCallback((srcId) => {
|
|
53
|
+
const r = new RegExp(`\/view\/`);
|
|
54
|
+
const [previous, extra] = pathname.split(r);
|
|
55
|
+
|
|
56
|
+
if (srcId) {
|
|
57
|
+
push(`${previous}/edit/${extra}?sourceId=${srcId}`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (search) {
|
|
62
|
+
push(`${previous}/edit/${extra}${search}`);
|
|
63
|
+
} else {
|
|
64
|
+
push(`${previous}/edit/${extra}`);
|
|
65
|
+
}
|
|
66
|
+
}, [pathname, search, push]);
|
|
67
|
+
|
|
68
|
+
const match = useMemo(
|
|
69
|
+
() => ({
|
|
70
|
+
params,
|
|
71
|
+
path: pathname,
|
|
72
|
+
}),
|
|
73
|
+
[params, pathname],
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
namespace,
|
|
78
|
+
id,
|
|
79
|
+
group,
|
|
80
|
+
subsection,
|
|
81
|
+
params,
|
|
82
|
+
source,
|
|
83
|
+
setSource,
|
|
84
|
+
sourceUrl,
|
|
85
|
+
version,
|
|
86
|
+
setVersion,
|
|
87
|
+
versionUrl,
|
|
88
|
+
goBackFromSource,
|
|
89
|
+
getEditLink,
|
|
90
|
+
match,
|
|
91
|
+
search,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import React, { useMemo, useState, useEffect } from 'react'
|
|
2
|
+
import { useViewUrlParams } from './hooks/useViewUrlParams.js'
|
|
3
|
+
import { usePrepareForm } from './hooks/usePrepareForm.js'
|
|
4
|
+
import { useViewPermissions } from './hooks/useViewPermissions.js'
|
|
5
|
+
import { useSubmitSubject } from './hooks/useSubmitSubject.js'
|
|
6
|
+
import { useCallToGetData } from './hooks/useCallToGetData.js'
|
|
7
|
+
import { useViewActions } from './hooks/useViewActions.js'
|
|
8
|
+
|
|
9
|
+
import { groupSubsections } from '../../../@daf/core/components/ViewForm/helper.js'
|
|
10
|
+
import Loading from '../../../@daf/core/components/Loading/index.jsx'
|
|
11
|
+
import Header from '../../../@daf/core/components/Header/index.jsx'
|
|
12
|
+
import Multiselect from '../../../@daf/core/components/Select/MultiSelect/index.jsx'
|
|
13
|
+
import ViewFormNavigation from '../../../@daf/core/components/ViewForm/navigation.jsx'
|
|
14
|
+
import ViewForm from '../../../@daf/core/components/ViewForm/content.jsx'
|
|
15
|
+
import Records from '../../../@daf/core/components/ViewForm/components/Records/index.jsx'
|
|
16
|
+
import { Template } from '../Template/index.jsx'
|
|
17
|
+
|
|
18
|
+
const View = ({
|
|
19
|
+
push,
|
|
20
|
+
getRedirectLink,
|
|
21
|
+
allData,
|
|
22
|
+
ajaxForms,
|
|
23
|
+
changeAjaxForms,
|
|
24
|
+
t,
|
|
25
|
+
namespaceConfiguration,
|
|
26
|
+
params,
|
|
27
|
+
pathname,
|
|
28
|
+
search,
|
|
29
|
+
searchParams,
|
|
30
|
+
setSearchParams,
|
|
31
|
+
mode="app",
|
|
32
|
+
APP,
|
|
33
|
+
viewConfig,
|
|
34
|
+
partners,
|
|
35
|
+
setSelectedPartners,
|
|
36
|
+
user,
|
|
37
|
+
serviceMap,
|
|
38
|
+
actionMap,
|
|
39
|
+
goBack,
|
|
40
|
+
breadcrumbs,
|
|
41
|
+
theme,
|
|
42
|
+
buttonActions,
|
|
43
|
+
generatePath,
|
|
44
|
+
getApiBaseUrl,
|
|
45
|
+
getAppHeader,
|
|
46
|
+
location,
|
|
47
|
+
isMobile,
|
|
48
|
+
linkingTemplateContextData,
|
|
49
|
+
addData,
|
|
50
|
+
options,
|
|
51
|
+
getSubjectsDetails,
|
|
52
|
+
// ADD CALLBACK TO GET THE CURRENT NAMESPACE CONFIG
|
|
53
|
+
}) => {
|
|
54
|
+
const getNamespaceConfig = (namespace) => namespaceConfiguration?.[namespace] || {};
|
|
55
|
+
const [openRecordsModal, setOpenRecordsModal] = useState(false);
|
|
56
|
+
|
|
57
|
+
// HANDLES THE URL PARAMS FOR THE VIEW PAGE
|
|
58
|
+
const {
|
|
59
|
+
namespace,
|
|
60
|
+
id,
|
|
61
|
+
group,
|
|
62
|
+
subsection,
|
|
63
|
+
source,
|
|
64
|
+
setSource,
|
|
65
|
+
sourceUrl,
|
|
66
|
+
version,
|
|
67
|
+
setVersion,
|
|
68
|
+
versionUrl,
|
|
69
|
+
goBackFromSource,
|
|
70
|
+
getEditLink,
|
|
71
|
+
match,
|
|
72
|
+
} = useViewUrlParams({
|
|
73
|
+
params,
|
|
74
|
+
push,
|
|
75
|
+
pathname,
|
|
76
|
+
search,
|
|
77
|
+
searchParams,
|
|
78
|
+
setSearchParams,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const namespaceConfig = useMemo(() => getNamespaceConfig(namespace), [namespace]);
|
|
82
|
+
|
|
83
|
+
// PREPARES THE FORM FOR THE VIEW PAGE
|
|
84
|
+
const {
|
|
85
|
+
form,
|
|
86
|
+
data,
|
|
87
|
+
groups,
|
|
88
|
+
linkingForms,
|
|
89
|
+
loading,
|
|
90
|
+
setLoading,
|
|
91
|
+
notFound,
|
|
92
|
+
} = usePrepareForm({
|
|
93
|
+
namespaceConfig,
|
|
94
|
+
allData,
|
|
95
|
+
id,
|
|
96
|
+
namespace,
|
|
97
|
+
t,
|
|
98
|
+
mode,
|
|
99
|
+
APP,
|
|
100
|
+
viewConfig,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const { canEdit, isSupported } = useViewPermissions({
|
|
104
|
+
data,
|
|
105
|
+
id,
|
|
106
|
+
namespace,
|
|
107
|
+
user,
|
|
108
|
+
push,
|
|
109
|
+
getRedirectLink,
|
|
110
|
+
namespaceConfig: namespaceConfiguration,
|
|
111
|
+
APP,
|
|
112
|
+
viewConfig,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const groupForm = useMemo(() => {
|
|
116
|
+
const gF = form[group] || {};
|
|
117
|
+
if (subsection) {
|
|
118
|
+
const sectionForms = groupSubsections(gF);
|
|
119
|
+
if (sectionForms[subsection]) {
|
|
120
|
+
return sectionForms[subsection];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return gF;
|
|
124
|
+
}, [form, group, subsection]);
|
|
125
|
+
|
|
126
|
+
const { submitSubject, isDisabled, submitLoading, isPublished } = useSubmitSubject({
|
|
127
|
+
namespace,
|
|
128
|
+
data,
|
|
129
|
+
serviceMap,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const { pageActions, extraPageActions } = useViewActions({
|
|
133
|
+
namespace,
|
|
134
|
+
data,
|
|
135
|
+
isSupported,
|
|
136
|
+
canEdit,
|
|
137
|
+
versionUrl,
|
|
138
|
+
sourceUrl,
|
|
139
|
+
getEditLink,
|
|
140
|
+
submitSubject,
|
|
141
|
+
isDisabled,
|
|
142
|
+
setOpenRecordsModal,
|
|
143
|
+
goBackFromSource,
|
|
144
|
+
push,
|
|
145
|
+
getRedirectLink,
|
|
146
|
+
t,
|
|
147
|
+
viewConfig,
|
|
148
|
+
buttonActions,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if(namespace && id && namespaceConfig && typeof getSubjectsDetails === 'function') {
|
|
153
|
+
getSubjectsDetails({
|
|
154
|
+
namespace,
|
|
155
|
+
id,
|
|
156
|
+
namespaceConfig,
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
}, [namespace, id, namespaceConfig])
|
|
160
|
+
|
|
161
|
+
const action = useMemo(() => actionMap?.[namespaceConfig?.action], [namespaceConfig?.action, actionMap]);
|
|
162
|
+
|
|
163
|
+
const namespaceGet = {
|
|
164
|
+
[namespace]: () => {
|
|
165
|
+
return action?.({
|
|
166
|
+
namespace: namespaceConfig?.namespace,
|
|
167
|
+
module: APP,
|
|
168
|
+
view: namespaceConfig?.view,
|
|
169
|
+
...(namespaceConfig?.scope && { scope: namespaceConfig.scope }),
|
|
170
|
+
datastakeId: id,
|
|
171
|
+
version,
|
|
172
|
+
source,
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
useCallToGetData({
|
|
178
|
+
namespaceConfig,
|
|
179
|
+
namespace,
|
|
180
|
+
allData,
|
|
181
|
+
id,
|
|
182
|
+
isSupported,
|
|
183
|
+
namespaceGet,
|
|
184
|
+
source,
|
|
185
|
+
version,
|
|
186
|
+
user,
|
|
187
|
+
setLoading,
|
|
188
|
+
APP
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
const extraLinking = useMemo(() => {
|
|
192
|
+
return null;
|
|
193
|
+
}, [namespace, match, data]);
|
|
194
|
+
|
|
195
|
+
const sourceOptions = useMemo(() => {
|
|
196
|
+
return partners.map((partner) => {
|
|
197
|
+
const isOwnData = partner.id === user?.company?.id;
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
label: partner.nickName,
|
|
201
|
+
value: partner.id,
|
|
202
|
+
avatar: isOwnData ? <span>OWN</span> : undefined,
|
|
203
|
+
background: isOwnData ? theme.colorPrimary7 : undefined,
|
|
204
|
+
color: isOwnData ? "white" : undefined,
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
}, [partners, user]);
|
|
208
|
+
|
|
209
|
+
const actionButtons = useMemo(() => {
|
|
210
|
+
return groupForm?.template === "linkingSubjects"
|
|
211
|
+
? pageActions.filter((v) => v.key !== "edit")
|
|
212
|
+
: pageActions;
|
|
213
|
+
}, [groupForm, pageActions]);
|
|
214
|
+
|
|
215
|
+
if(!isSupported || notFound) {
|
|
216
|
+
return <Loading />
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<>
|
|
221
|
+
<div className={"daf-view-form"}>
|
|
222
|
+
<Header
|
|
223
|
+
title={data?.name || ""}
|
|
224
|
+
breadcrumbs={breadcrumbs}
|
|
225
|
+
goBackTo={goBack}
|
|
226
|
+
actionButtons={actionButtons}
|
|
227
|
+
extraButtons={extraPageActions}
|
|
228
|
+
addedHeaderFirst
|
|
229
|
+
addedHeader={
|
|
230
|
+
<div className="flex flex-row gap-4" style={{ marginRight: 8 }}>
|
|
231
|
+
<Multiselect
|
|
232
|
+
options={[...sourceOptions]}
|
|
233
|
+
isAvatarGroup
|
|
234
|
+
selectionType="checkbox"
|
|
235
|
+
key={partners?.length}
|
|
236
|
+
canUnselectLast={false}
|
|
237
|
+
onChange={(selected) => {
|
|
238
|
+
setSelectedPartners((prev) => ({
|
|
239
|
+
...prev,
|
|
240
|
+
partners: selected,
|
|
241
|
+
loading: false,
|
|
242
|
+
}));
|
|
243
|
+
}}
|
|
244
|
+
dropDownWidth={200}
|
|
245
|
+
defaultSelected={(partners || []).map((p) => p.id) || []}
|
|
246
|
+
/>
|
|
247
|
+
</div>
|
|
248
|
+
}
|
|
249
|
+
/>
|
|
250
|
+
<div className="view-content">
|
|
251
|
+
<ViewFormNavigation
|
|
252
|
+
mod={APP}
|
|
253
|
+
data={data}
|
|
254
|
+
match={match}
|
|
255
|
+
form={form}
|
|
256
|
+
group={group}
|
|
257
|
+
subsection={subsection}
|
|
258
|
+
search={search}
|
|
259
|
+
goTo={push}
|
|
260
|
+
getRedirectLink={getRedirectLink}
|
|
261
|
+
generatePath={generatePath}
|
|
262
|
+
params={params}
|
|
263
|
+
/>
|
|
264
|
+
{groupForm.template ? (<Template
|
|
265
|
+
namespace={namespace}
|
|
266
|
+
conf={{
|
|
267
|
+
mod: APP,
|
|
268
|
+
group: group,
|
|
269
|
+
form: groupForm,
|
|
270
|
+
data: data[group] ? data[group] : data || {},
|
|
271
|
+
allData: data,
|
|
272
|
+
linkingForms: linkingForms || {},
|
|
273
|
+
linkingData: data.linking || {},
|
|
274
|
+
match,
|
|
275
|
+
canEdit: isSupported && canEdit,
|
|
276
|
+
mode,
|
|
277
|
+
user: user,
|
|
278
|
+
t: t,
|
|
279
|
+
location: location,
|
|
280
|
+
isMobile: isMobile,
|
|
281
|
+
linkingTemplateContextData: linkingTemplateContextData,
|
|
282
|
+
addData: addData,
|
|
283
|
+
options: options,
|
|
284
|
+
}}
|
|
285
|
+
/>) : (
|
|
286
|
+
<ViewForm
|
|
287
|
+
form={groupForm}
|
|
288
|
+
data={data || {}}
|
|
289
|
+
groupConfig={groups || {}}
|
|
290
|
+
linkingData={(data || {}).linking || {}}
|
|
291
|
+
linkingForms={linkingForms || {}}
|
|
292
|
+
ajaxOptions={[]}
|
|
293
|
+
extraLinking={extraLinking}
|
|
294
|
+
t={t}
|
|
295
|
+
app={APP}
|
|
296
|
+
ajaxForms={ajaxForms}
|
|
297
|
+
language={user?.language}
|
|
298
|
+
changeAjaxForms={changeAjaxForms}
|
|
299
|
+
getApiBaseUrl={getApiBaseUrl}
|
|
300
|
+
getAppHeader={getAppHeader}
|
|
301
|
+
user={user}
|
|
302
|
+
/>
|
|
303
|
+
)}
|
|
304
|
+
</div>
|
|
305
|
+
</div>
|
|
306
|
+
{openRecordsModal && (
|
|
307
|
+
<Records
|
|
308
|
+
open={openRecordsModal}
|
|
309
|
+
onClose={() => setOpenRecordsModal(false)}
|
|
310
|
+
t={t}
|
|
311
|
+
sourceOptions={[]}
|
|
312
|
+
versionOptions={[]}
|
|
313
|
+
id={params?.id}
|
|
314
|
+
subject={namespace}
|
|
315
|
+
onSubmit={(values) => {
|
|
316
|
+
setSource(values?.source);
|
|
317
|
+
setVersion(values?.version);
|
|
318
|
+
}}
|
|
319
|
+
/>
|
|
320
|
+
)}
|
|
321
|
+
</>
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export default View
|
package/src/@daf/utils/object.js
CHANGED
package/src/pages.js
CHANGED
|
@@ -19,4 +19,7 @@ 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';
|
|
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';
|
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 } from './@daf/utils/object'
|
|
30
|
+
export { convertUndefinedToNull, hasKeyInObject, removeKeysFromObject } from './@daf/utils/object'
|
|
31
31
|
|
|
32
32
|
export { default as ErrorFormat, formatErrors } from './helpers/ErrorFormater'
|
|
33
33
|
|