datastake-daf 0.6.780 → 0.6.781
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 +314 -369
- package/dist/pages/index.js +232 -2049
- 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/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
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { useMemo, useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
export const useViewPermissions = ({
|
|
4
|
-
data,
|
|
5
|
-
id,
|
|
6
|
-
namespaceOverrides = {
|
|
7
|
-
supportedNamespaces: {},
|
|
8
|
-
canEdit: {},
|
|
9
|
-
},
|
|
10
|
-
namespace,
|
|
11
|
-
user,
|
|
12
|
-
push,
|
|
13
|
-
getRedirectLink,
|
|
14
|
-
namespaceConfig,
|
|
15
|
-
APP,
|
|
16
|
-
viewConfig,
|
|
17
|
-
}) => {
|
|
18
|
-
const baseNamespaceKeys = Object.keys(namespaceConfig);
|
|
19
|
-
|
|
20
|
-
const baseSupportedNamespaces = baseNamespaceKeys.reduce((acc, key) => {
|
|
21
|
-
acc[key] = () => true;
|
|
22
|
-
return acc;
|
|
23
|
-
}, {});
|
|
24
|
-
|
|
25
|
-
const isSupportedNamespaces = useMemo(
|
|
26
|
-
() => ({
|
|
27
|
-
...baseSupportedNamespaces,
|
|
28
|
-
...namespaceOverrides.supportedNamespaces,
|
|
29
|
-
}),
|
|
30
|
-
[data, id],
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const isSupported =
|
|
34
|
-
typeof isSupportedNamespaces[namespace] === "function"
|
|
35
|
-
? isSupportedNamespaces[namespace]() &&
|
|
36
|
-
viewConfig.supportedNamespaces[APP] &&
|
|
37
|
-
namespaceConfig.supportedNamespaces[APP].includes(namespace)
|
|
38
|
-
: namespaceConfig.supportedNamespaces[APP] && namespaceConfig.supportedNamespaces[APP].includes(namespace);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const isUserData = () => {
|
|
42
|
-
return data && data.authorId && user?.company?.id === data.authorId;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const canEdit = useMemo(() => {
|
|
46
|
-
const baseCanEditAction = baseNamespaceKeys.reduce((acc, key) => {
|
|
47
|
-
acc[key] = () => isUserData();
|
|
48
|
-
return acc;
|
|
49
|
-
}, {});
|
|
50
|
-
|
|
51
|
-
const canEditAction = {
|
|
52
|
-
...baseCanEditAction,
|
|
53
|
-
...namespaceOverrides.canEdit,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return canEditAction[namespace] ? canEditAction[namespace]() : false;
|
|
57
|
-
}, [namespace, data, user]);
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (data) {
|
|
61
|
-
if (typeof isSupportedNamespaces[namespace] === "function") {
|
|
62
|
-
if (!isSupportedNamespaces[namespace]()) {
|
|
63
|
-
push(getRedirectLink(`/app`));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}, [data, namespace]);
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
isSupportedNamespaces,
|
|
71
|
-
canEdit,
|
|
72
|
-
isSupported,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import React, { useMemo, useState } 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
|
-
|
|
17
|
-
const View = ({
|
|
18
|
-
push,
|
|
19
|
-
getRedirectLink,
|
|
20
|
-
allData,
|
|
21
|
-
ajaxForms,
|
|
22
|
-
changeAjaxForms,
|
|
23
|
-
t,
|
|
24
|
-
namespaceConfiguaration,
|
|
25
|
-
params,
|
|
26
|
-
pathname,
|
|
27
|
-
search,
|
|
28
|
-
searchParams,
|
|
29
|
-
setSearchParams,
|
|
30
|
-
mode="app",
|
|
31
|
-
APP,
|
|
32
|
-
viewConfig,
|
|
33
|
-
partners,
|
|
34
|
-
setSelectedPartners,
|
|
35
|
-
user,
|
|
36
|
-
serviceMap,
|
|
37
|
-
actionMap,
|
|
38
|
-
goBack,
|
|
39
|
-
breadcrumbs,
|
|
40
|
-
theme,
|
|
41
|
-
buttonActions,
|
|
42
|
-
generatePath,
|
|
43
|
-
getApiBaseUrl,
|
|
44
|
-
getAppHeader,
|
|
45
|
-
// ADD CALLBACK TO GET THE CURRENT NAMESPACE CONFIG
|
|
46
|
-
}) => {
|
|
47
|
-
const getNamespaceConfig = (namespace) => namespaceConfiguaration[namespace];
|
|
48
|
-
const [openRecordsModal, setOpenRecordsModal] = useState(false);
|
|
49
|
-
|
|
50
|
-
// HANDLES THE URL PARAMS FOR THE VIEW PAGE
|
|
51
|
-
const {
|
|
52
|
-
namespace,
|
|
53
|
-
id,
|
|
54
|
-
group,
|
|
55
|
-
subsection,
|
|
56
|
-
source,
|
|
57
|
-
setSource,
|
|
58
|
-
sourceUrl,
|
|
59
|
-
version,
|
|
60
|
-
setVersion,
|
|
61
|
-
versionUrl,
|
|
62
|
-
goBackFromSource,
|
|
63
|
-
getEditLink,
|
|
64
|
-
match,
|
|
65
|
-
} = useViewUrlParams({
|
|
66
|
-
params,
|
|
67
|
-
push,
|
|
68
|
-
pathname,
|
|
69
|
-
search,
|
|
70
|
-
searchParams,
|
|
71
|
-
setSearchParams,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const namespaceConfig = useMemo(() => getNamespaceConfig(namespace), [namespace]);
|
|
75
|
-
|
|
76
|
-
// PREPARES THE FORM FOR THE VIEW PAGE
|
|
77
|
-
const {
|
|
78
|
-
form,
|
|
79
|
-
data,
|
|
80
|
-
groups,
|
|
81
|
-
linkingForms,
|
|
82
|
-
loading,
|
|
83
|
-
setLoading,
|
|
84
|
-
notFound,
|
|
85
|
-
} = usePrepareForm({
|
|
86
|
-
namespaceConfig,
|
|
87
|
-
allData,
|
|
88
|
-
id,
|
|
89
|
-
namespace,
|
|
90
|
-
t,
|
|
91
|
-
mode,
|
|
92
|
-
APP,
|
|
93
|
-
viewConfig,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const { canEdit, isSupported } = useViewPermissions({
|
|
97
|
-
data,
|
|
98
|
-
id,
|
|
99
|
-
namespace,
|
|
100
|
-
user,
|
|
101
|
-
push,
|
|
102
|
-
getRedirectLink,
|
|
103
|
-
namespaceConfig: namespaceConfiguaration,
|
|
104
|
-
APP,
|
|
105
|
-
viewConfig,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const groupForm = useMemo(() => {
|
|
109
|
-
const gF = form[group] || {};
|
|
110
|
-
if (subsection) {
|
|
111
|
-
const sectionForms = groupSubsections(gF);
|
|
112
|
-
if (sectionForms[subsection]) {
|
|
113
|
-
return sectionForms[subsection];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return gF;
|
|
117
|
-
}, [form, group, subsection]);
|
|
118
|
-
|
|
119
|
-
const { submitSubject, isDisabled, submitLoading, isPublished } = useSubmitSubject({
|
|
120
|
-
namespace,
|
|
121
|
-
data,
|
|
122
|
-
serviceMap,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const { pageActions, extraPageActions } = useViewActions({
|
|
126
|
-
namespace,
|
|
127
|
-
data,
|
|
128
|
-
isSupported,
|
|
129
|
-
canEdit,
|
|
130
|
-
versionUrl,
|
|
131
|
-
sourceUrl,
|
|
132
|
-
getEditLink,
|
|
133
|
-
submitSubject,
|
|
134
|
-
isDisabled,
|
|
135
|
-
setOpenRecordsModal,
|
|
136
|
-
goBackFromSource,
|
|
137
|
-
push,
|
|
138
|
-
getRedirectLink,
|
|
139
|
-
t,
|
|
140
|
-
viewConfig,
|
|
141
|
-
buttonActions,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const action = useMemo(() => actionMap[namespaceConfig?.action], [namespaceConfig?.action]);
|
|
145
|
-
|
|
146
|
-
const namespaceGet = {
|
|
147
|
-
[namespace]: () => {
|
|
148
|
-
return action({
|
|
149
|
-
namespace: namespaceConfig.namespace,
|
|
150
|
-
module: APP,
|
|
151
|
-
view: namespaceConfig.view,
|
|
152
|
-
...(namespaceConfig.scope && { scope: namespaceConfig.scope }),
|
|
153
|
-
datastakeId: id,
|
|
154
|
-
version,
|
|
155
|
-
source,
|
|
156
|
-
})
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
useCallToGetData({
|
|
161
|
-
namespaceConfig,
|
|
162
|
-
namespace,
|
|
163
|
-
allData,
|
|
164
|
-
id,
|
|
165
|
-
isSupported,
|
|
166
|
-
namespaceGet,
|
|
167
|
-
source,
|
|
168
|
-
version,
|
|
169
|
-
user,
|
|
170
|
-
setLoading,
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
const extraLinking = useMemo(() => {
|
|
174
|
-
return null;
|
|
175
|
-
}, [namespace, match, data]);
|
|
176
|
-
|
|
177
|
-
const sourceOptions = useMemo(() => {
|
|
178
|
-
return partners.map((partner) => {
|
|
179
|
-
const isOwnData = partner.id === user?.company?.id;
|
|
180
|
-
|
|
181
|
-
return {
|
|
182
|
-
label: partner.nickName,
|
|
183
|
-
value: partner.id,
|
|
184
|
-
avatar: isOwnData ? <span>OWN</span> : undefined,
|
|
185
|
-
background: isOwnData ? theme.colorPrimary7 : undefined,
|
|
186
|
-
color: isOwnData ? "white" : undefined,
|
|
187
|
-
};
|
|
188
|
-
});
|
|
189
|
-
}, [partners, user]);
|
|
190
|
-
|
|
191
|
-
const actionButtons = useMemo(() => {
|
|
192
|
-
return groupForm?.template === "linkingSubjects"
|
|
193
|
-
? pageActions.filter((v) => v.key !== "edit")
|
|
194
|
-
: pageActions;
|
|
195
|
-
}, [groupForm, pageActions]);
|
|
196
|
-
|
|
197
|
-
if(!isSupported || notFound || loading) {
|
|
198
|
-
return <Loading />
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return (
|
|
202
|
-
<>
|
|
203
|
-
<div className={"daf-view-form"}>
|
|
204
|
-
<Header
|
|
205
|
-
title={data?.name || ""}
|
|
206
|
-
breadcrumbs={breadcrumbs}
|
|
207
|
-
goBackTo={goBack}
|
|
208
|
-
actionButtons={actionButtons}
|
|
209
|
-
extraButtons={extraPageActions}
|
|
210
|
-
addedHeaderFirst
|
|
211
|
-
addedHeader={
|
|
212
|
-
<div className="flex flex-row gap-4" style={{ marginRight: 8 }}>
|
|
213
|
-
<Multiselect
|
|
214
|
-
options={[...sourceOptions]}
|
|
215
|
-
isAvatarGroup
|
|
216
|
-
selectionType="checkbox"
|
|
217
|
-
key={partners?.length}
|
|
218
|
-
canUnselectLast={false}
|
|
219
|
-
onChange={(selected) => {
|
|
220
|
-
setSelectedPartners((prev) => ({
|
|
221
|
-
...prev,
|
|
222
|
-
partners: selected,
|
|
223
|
-
loading: false,
|
|
224
|
-
}));
|
|
225
|
-
}}
|
|
226
|
-
dropDownWidth={200}
|
|
227
|
-
defaultSelected={(partners || []).map((p) => p.id) || []}
|
|
228
|
-
/>
|
|
229
|
-
</div>
|
|
230
|
-
}
|
|
231
|
-
/>
|
|
232
|
-
<div className="view-content">
|
|
233
|
-
<ViewFormNavigation
|
|
234
|
-
mod={APP}
|
|
235
|
-
data={data}
|
|
236
|
-
match={match}
|
|
237
|
-
form={form}
|
|
238
|
-
group={group}
|
|
239
|
-
subsection={subsection}
|
|
240
|
-
search={search}
|
|
241
|
-
goTo={push}
|
|
242
|
-
getRedirectLink={getRedirectLink}
|
|
243
|
-
generatePath={generatePath}
|
|
244
|
-
params={params}
|
|
245
|
-
/>
|
|
246
|
-
{groupForm.template ? (<></>) : (
|
|
247
|
-
<ViewForm
|
|
248
|
-
form={groupForm}
|
|
249
|
-
data={data || {}}
|
|
250
|
-
groupConfig={groups || {}}
|
|
251
|
-
linkingData={(data || {}).linking || {}}
|
|
252
|
-
linkingForms={linkingForms || {}}
|
|
253
|
-
ajaxOptions={[]}
|
|
254
|
-
extraLinking={extraLinking}
|
|
255
|
-
t={t}
|
|
256
|
-
app={APP}
|
|
257
|
-
ajaxForms={ajaxForms}
|
|
258
|
-
language={user?.language}
|
|
259
|
-
changeAjaxForms={changeAjaxForms}
|
|
260
|
-
getApiBaseUrl={getApiBaseUrl}
|
|
261
|
-
getAppHeader={getAppHeader}
|
|
262
|
-
user={user}
|
|
263
|
-
/>
|
|
264
|
-
)}
|
|
265
|
-
</div>
|
|
266
|
-
</div>
|
|
267
|
-
{openRecordsModal && (
|
|
268
|
-
<Records
|
|
269
|
-
open={openRecordsModal}
|
|
270
|
-
onClose={() => setOpenRecordsModal(false)}
|
|
271
|
-
t={t}
|
|
272
|
-
sourceOptions={[]}
|
|
273
|
-
versionOptions={[]}
|
|
274
|
-
id={params?.id}
|
|
275
|
-
subject={namespace}
|
|
276
|
-
onSubmit={(values) => {
|
|
277
|
-
setSource(values?.source);
|
|
278
|
-
setVersion(values?.version);
|
|
279
|
-
}}
|
|
280
|
-
/>
|
|
281
|
-
)}
|
|
282
|
-
</>
|
|
283
|
-
)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export default View
|