datastake-daf 0.6.756 → 0.6.758
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 +61 -66
- package/dist/constants/index.js +26 -0
- package/dist/pages/index.js +47 -41
- package/dist/utils/index.js +346 -0
- package/package.json +1 -1
- package/rollup.config.js +20 -0
- package/src/@daf/core/components/EditForm/storyConfig2.js +866 -25029
- package/src/@daf/pages/Dashboards/SupplyChain/index.jsx +2 -2
- package/src/@daf/pages/Documents/index.jsx +2 -3
- package/src/@daf/pages/Events/Activities/index.jsx +2 -3
- package/src/@daf/pages/Events/Incidents/index.jsx +2 -3
- package/src/@daf/pages/Events/index.jsx +2 -3
- package/src/@daf/pages/Locations/MineSite/columns.js +7 -5
- package/src/@daf/pages/Locations/MineSite/index.jsx +5 -4
- package/src/@daf/pages/Locations/index.jsx +2 -3
- package/src/@daf/pages/Stakeholders/Operators/index.jsx +2 -2
- package/src/@daf/pages/Stakeholders/Workers/index.jsx +2 -3
- package/src/@daf/pages/Stakeholders/index.jsx +2 -3
- package/src/@daf/pages/Summary/Minesite/index.jsx +2 -0
- package/src/@daf/pages/Summary/Operator/index.jsx +3 -1
- package/src/constants/breadCrumbs.js +20 -0
- package/src/constants.js +1 -0
- package/src/helpers/breadCrumbs.js +347 -0
- package/src/utils.js +3 -1
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
|
|
2
|
+
export const buildBreadCrumbs = ({
|
|
3
|
+
config,
|
|
4
|
+
items,
|
|
5
|
+
t,
|
|
6
|
+
breadCrumbsLabels,
|
|
7
|
+
id,
|
|
8
|
+
getRedirectLink,
|
|
9
|
+
createOnClick,
|
|
10
|
+
goTo,
|
|
11
|
+
view,
|
|
12
|
+
skipInteractions = false,
|
|
13
|
+
}) => {
|
|
14
|
+
const pathConfig = config.path || [];
|
|
15
|
+
|
|
16
|
+
pathConfig.forEach((pathItem) => {
|
|
17
|
+
if (typeof pathItem === 'string') {
|
|
18
|
+
items.push({
|
|
19
|
+
label: t(breadCrumbsLabels[pathItem]),
|
|
20
|
+
onClick: () => {},
|
|
21
|
+
});
|
|
22
|
+
} else if (typeof pathItem === 'object') {
|
|
23
|
+
const { key, link, useRedirect } = pathItem;
|
|
24
|
+
|
|
25
|
+
if (key === 'id' && id) {
|
|
26
|
+
const resolvedLink = typeof link === 'function' ? link(id) : link;
|
|
27
|
+
const finalLink = useRedirect ? getRedirectLink(resolvedLink) : resolvedLink;
|
|
28
|
+
|
|
29
|
+
items.push({
|
|
30
|
+
label: id,
|
|
31
|
+
onClick: skipInteractions ? () => {} : (finalLink ? createOnClick(() => goTo(finalLink)) : () => {}),
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
const resolvedLink = typeof link === 'function' ? link(view, id) : link;
|
|
35
|
+
const finalLink = resolvedLink && useRedirect ? getRedirectLink(resolvedLink) : resolvedLink;
|
|
36
|
+
|
|
37
|
+
items.push({
|
|
38
|
+
label: t(breadCrumbsLabels[key]),
|
|
39
|
+
onClick: skipInteractions ? () => {} : (finalLink ? createOnClick(() => goTo(finalLink)) : () => {}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (config.includeId && id && id !== 'user') {
|
|
46
|
+
items.push({ label: id, onClick: () => {} });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (config.suffix) {
|
|
50
|
+
config.suffix.forEach((suffixItem) => {
|
|
51
|
+
items.push({
|
|
52
|
+
label: t(breadCrumbsLabels[suffixItem]),
|
|
53
|
+
onClick: () => {},
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const renderBreadCrumbs = ({
|
|
60
|
+
t = () => {},
|
|
61
|
+
goTo = () => {},
|
|
62
|
+
view,
|
|
63
|
+
isAnalysis = false,
|
|
64
|
+
isEdit = false,
|
|
65
|
+
isView = false,
|
|
66
|
+
isDataStore = false,
|
|
67
|
+
id,
|
|
68
|
+
addedItems = [],
|
|
69
|
+
changeNotificationState,
|
|
70
|
+
breadCrumbConfig = {},
|
|
71
|
+
breadCrumbsLabels = {},
|
|
72
|
+
getRedirectLink = () => {},
|
|
73
|
+
condition,
|
|
74
|
+
conditionFallback = 'show-non-interactive', // 'show-non-interactive' | 'hide' | 'show-simplified'
|
|
75
|
+
}) => {
|
|
76
|
+
const items = [];
|
|
77
|
+
|
|
78
|
+
const createOnClick = (callback) => {
|
|
79
|
+
if (!callback) return () => {};
|
|
80
|
+
|
|
81
|
+
return () => {
|
|
82
|
+
if (changeNotificationState) {
|
|
83
|
+
changeNotificationState({ onYes: callback });
|
|
84
|
+
} else {
|
|
85
|
+
callback();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const evaluateCondition = (cond, context) => {
|
|
91
|
+
if (cond === undefined) return true; // No condition = always pass
|
|
92
|
+
if (typeof cond === 'function') return cond(context); // Function condition
|
|
93
|
+
return Boolean(cond); // Boolean condition
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const config = breadCrumbConfig[view];
|
|
97
|
+
|
|
98
|
+
console.log({config, breadCrumbConfig, breadCrumbsLabels, condition})
|
|
99
|
+
|
|
100
|
+
if (config) {
|
|
101
|
+
const conditionContext = {
|
|
102
|
+
isDataStore,
|
|
103
|
+
isAnalysis,
|
|
104
|
+
isEdit,
|
|
105
|
+
isView,
|
|
106
|
+
id,
|
|
107
|
+
view,
|
|
108
|
+
t,
|
|
109
|
+
goTo,
|
|
110
|
+
getRedirectLink,
|
|
111
|
+
changeNotificationState,
|
|
112
|
+
addedItems,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const externalConditionPassed = evaluateCondition(condition, conditionContext);
|
|
116
|
+
const configConditionPassed = evaluateCondition(config.condition, conditionContext);
|
|
117
|
+
|
|
118
|
+
const shouldShowBreadcrumbs = externalConditionPassed && configConditionPassed;
|
|
119
|
+
|
|
120
|
+
if (!configConditionPassed) {
|
|
121
|
+
if (config.fallback) {
|
|
122
|
+
buildBreadCrumbs({
|
|
123
|
+
config: config.fallback,
|
|
124
|
+
items,
|
|
125
|
+
t,
|
|
126
|
+
breadCrumbsLabels,
|
|
127
|
+
id,
|
|
128
|
+
getRedirectLink,
|
|
129
|
+
createOnClick,
|
|
130
|
+
goTo,
|
|
131
|
+
view,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
} else if (!externalConditionPassed) {
|
|
135
|
+
if (config.fallback) {
|
|
136
|
+
// Use config fallback when prop condition fails
|
|
137
|
+
buildBreadCrumbs({
|
|
138
|
+
config: config.fallback,
|
|
139
|
+
items,
|
|
140
|
+
t,
|
|
141
|
+
breadCrumbsLabels,
|
|
142
|
+
id,
|
|
143
|
+
getRedirectLink,
|
|
144
|
+
createOnClick,
|
|
145
|
+
goTo,
|
|
146
|
+
view,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
switch (conditionFallback) {
|
|
151
|
+
case 'hide':
|
|
152
|
+
break;
|
|
153
|
+
case 'show-simplified':{
|
|
154
|
+
const simplifiedConfig = {
|
|
155
|
+
...config,
|
|
156
|
+
path: config.path.slice(0, 2),
|
|
157
|
+
includeId: false,
|
|
158
|
+
suffix: undefined,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
buildBreadCrumbs({
|
|
162
|
+
config: simplifiedConfig,
|
|
163
|
+
items,
|
|
164
|
+
t,
|
|
165
|
+
breadCrumbsLabels,
|
|
166
|
+
id,
|
|
167
|
+
getRedirectLink,
|
|
168
|
+
createOnClick,
|
|
169
|
+
goTo,
|
|
170
|
+
view,
|
|
171
|
+
});
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'show-non-interactive':
|
|
175
|
+
default:
|
|
176
|
+
buildBreadCrumbs({
|
|
177
|
+
config,
|
|
178
|
+
items,
|
|
179
|
+
t,
|
|
180
|
+
breadCrumbsLabels,
|
|
181
|
+
id,
|
|
182
|
+
getRedirectLink,
|
|
183
|
+
createOnClick,
|
|
184
|
+
goTo,
|
|
185
|
+
view,
|
|
186
|
+
skipInteractions: true,
|
|
187
|
+
});
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
buildBreadCrumbs({
|
|
193
|
+
config,
|
|
194
|
+
items,
|
|
195
|
+
t,
|
|
196
|
+
breadCrumbsLabels,
|
|
197
|
+
id,
|
|
198
|
+
getRedirectLink,
|
|
199
|
+
createOnClick,
|
|
200
|
+
goTo,
|
|
201
|
+
view,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
if (isView) {
|
|
208
|
+
items.push({ label: t(breadCrumbsLabels.details) });
|
|
209
|
+
} else if (isEdit) {
|
|
210
|
+
items.push({ label: t(breadCrumbsLabels.edit) });
|
|
211
|
+
} else if (isAnalysis) {
|
|
212
|
+
items.push({ label: t(breadCrumbsLabels.summary) });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
items.push(...addedItems);
|
|
216
|
+
|
|
217
|
+
return items.filter((v) => !!v.label);
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Breadcrumbs Config Helper
|
|
222
|
+
|
|
223
|
+
// 1.Simple static path
|
|
224
|
+
// 'country-overview': {
|
|
225
|
+
// path: ['analysis', 'country-overview'],
|
|
226
|
+
// }
|
|
227
|
+
// Result: Analysis > Country Overview
|
|
228
|
+
// Neither is clickable
|
|
229
|
+
|
|
230
|
+
// 2.Clickable Parents with Links
|
|
231
|
+
// 'mines': {
|
|
232
|
+
// path: [
|
|
233
|
+
// 'modules', // Not clickable
|
|
234
|
+
// { key: 'mines', link: '/app/mines' } // Clickable, navigates to /app/mines
|
|
235
|
+
// ],
|
|
236
|
+
// }
|
|
237
|
+
// Result: Modules > Mines (clickable)
|
|
238
|
+
|
|
239
|
+
// 3.Include ID at the end
|
|
240
|
+
// 'partners': {
|
|
241
|
+
// path: ['modules', { key: 'partners', link: '/app/partners', useRedirect: true }],
|
|
242
|
+
// includeId: true, // ← ID will be added at the end
|
|
243
|
+
// }
|
|
244
|
+
// With id='ABC123':
|
|
245
|
+
// Result: Modules > Partners (clickable) > ABC123 (not clickable)
|
|
246
|
+
|
|
247
|
+
// 4.Dynamic Id in the middle
|
|
248
|
+
// 'mine-evaluation': {
|
|
249
|
+
// path: [
|
|
250
|
+
// 'modules',
|
|
251
|
+
// { key: 'mines', link: '/app/mines' },
|
|
252
|
+
// { key: 'id', link: (id) => `/app/mines/${id}` }, // ← ID here
|
|
253
|
+
// 'evaluation',
|
|
254
|
+
// ],
|
|
255
|
+
// }
|
|
256
|
+
// With id='MINE-456':
|
|
257
|
+
// Result: Modules > Mines > MINE-456 (clickable to /app/mines/MINE-456) > Evaluation
|
|
258
|
+
|
|
259
|
+
// 5. Dynamic Links using functions
|
|
260
|
+
// 'producers': {
|
|
261
|
+
// path: [
|
|
262
|
+
// 'modules',
|
|
263
|
+
// {
|
|
264
|
+
// key: 'producers',
|
|
265
|
+
// link: (view) => `/app/${view}`, // ← Uses 'view' parameter
|
|
266
|
+
// useRedirect: true
|
|
267
|
+
// }
|
|
268
|
+
// ],
|
|
269
|
+
// includeId: true,
|
|
270
|
+
// }
|
|
271
|
+
// With view='producers':
|
|
272
|
+
// Result: Modules > Producers (navigates to /app/producers)
|
|
273
|
+
|
|
274
|
+
// 6.use Redirect link
|
|
275
|
+
// 'settings': {
|
|
276
|
+
// path: [
|
|
277
|
+
// {
|
|
278
|
+
// key: 'settings',
|
|
279
|
+
// link: '/app/view/settings',
|
|
280
|
+
// useRedirect: true // ← Wraps with getRedirectLink()
|
|
281
|
+
// }
|
|
282
|
+
// ],
|
|
283
|
+
// }
|
|
284
|
+
// Navigation will use getRedirectLink('/app/view/settings')
|
|
285
|
+
|
|
286
|
+
// 7.Conditional Rendering
|
|
287
|
+
// 'entities': {
|
|
288
|
+
// condition: (opts) => opts.isDataStore, // ← Only shows if isDataStore=true
|
|
289
|
+
// path: [
|
|
290
|
+
// 'data',
|
|
291
|
+
// { key: 'data-store', link: '/app/data-store', useRedirect: true },
|
|
292
|
+
// { key: 'entities', link: '/app/data-store/entities', useRedirect: true },
|
|
293
|
+
// ],
|
|
294
|
+
// }
|
|
295
|
+
// With isDataStore=false: No breadcrumbs shown
|
|
296
|
+
// With isDataStore=true: Data > Store > Entities
|
|
297
|
+
|
|
298
|
+
// 8.Conditional Fallback
|
|
299
|
+
// 'locations': {
|
|
300
|
+
// condition: (opts) => opts.isDataStore,
|
|
301
|
+
// path: [
|
|
302
|
+
// 'data',
|
|
303
|
+
// { key: 'data-store', link: '/app/data-store', useRedirect: true },
|
|
304
|
+
// { key: 'locations', link: '/app/data-store/locations', useRedirect: true },
|
|
305
|
+
// ],
|
|
306
|
+
// fallback: { // ← Alternative when condition is false
|
|
307
|
+
// path: [
|
|
308
|
+
// 'modules',
|
|
309
|
+
// 'linkedSubjects',
|
|
310
|
+
// { key: 'locations', link: '/app/locations', useRedirect: true },
|
|
311
|
+
// ],
|
|
312
|
+
// includeId: true,
|
|
313
|
+
// },
|
|
314
|
+
// }
|
|
315
|
+
// isDataStore=true: Data > Store > Locations
|
|
316
|
+
// isDataStore=false: Modules > Associated Information > Locations > {id}
|
|
317
|
+
|
|
318
|
+
// 9. Suffix items
|
|
319
|
+
// 'mine-monitoring': {
|
|
320
|
+
// path: [
|
|
321
|
+
// 'modules',
|
|
322
|
+
// { key: 'mines', link: '/app/mines' }
|
|
323
|
+
// ],
|
|
324
|
+
// includeId: true,
|
|
325
|
+
// suffix: ['visits'], // ← Added at the end
|
|
326
|
+
// }
|
|
327
|
+
// With id='MINE-789':
|
|
328
|
+
// Result: Modules > Mines > MINE-789 > Visits
|
|
329
|
+
|
|
330
|
+
// 10. Complex multi level path
|
|
331
|
+
// 'monitoringReport': {
|
|
332
|
+
// path: [
|
|
333
|
+
// 'modules', // Static label
|
|
334
|
+
// { key: 'mines', link: '/app/mines' }, // Clickable parent
|
|
335
|
+
// { key: 'id', link: (id) => `/app/mines/${id}` }, // Dynamic ID with link
|
|
336
|
+
// 'monitoringReport', // Static label at end
|
|
337
|
+
// ],
|
|
338
|
+
// }
|
|
339
|
+
// With id='MINE-999':
|
|
340
|
+
// Result: Modules > Mines (→/app/mines) > MINE-999 (→/app/mines/MINE-999) > Executive Monitoring Report
|
|
341
|
+
|
|
342
|
+
// 11. Access multiple options in condition
|
|
343
|
+
// 'custom-view': {
|
|
344
|
+
// condition: (opts) => opts.isDataStore && opts.isEdit && opts.id,
|
|
345
|
+
// path: ['data', 'custom'],
|
|
346
|
+
// }
|
|
347
|
+
// Available in opts: { isDataStore, isAnalysis, isEdit, isView, id, view }
|
package/src/utils.js
CHANGED
|
@@ -58,4 +58,6 @@ export {
|
|
|
58
58
|
buildActionWidgetsConfig,
|
|
59
59
|
buildKeyIndicatorsConfig,
|
|
60
60
|
buildBreadcrumbs
|
|
61
|
-
} from './@daf/utils/adminConfigBuilders.js'
|
|
61
|
+
} from './@daf/utils/adminConfigBuilders.js'
|
|
62
|
+
|
|
63
|
+
export { renderBreadCrumbs, buildBreadCrumbs as buildBreadCrumbsHelper } from './helpers/breadCrumbs.js'
|