datastake-daf 0.6.767 → 0.6.768

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.
Files changed (43) hide show
  1. package/dist/components/index.js +257 -196
  2. package/dist/pages/index.js +17468 -18460
  3. package/package.json +1 -1
  4. package/src/@daf/core/components/Dashboard/Map/ChainIcon/Markers/StakeholderMarker.js +5 -2
  5. package/src/@daf/core/components/Dashboard/Map/ChainIcon/index.js +67 -27
  6. package/src/@daf/core/components/Dashboard/Map/hook.js +26 -32
  7. package/src/@daf/core/components/Screens/BaseScreen/index.jsx +1 -1
  8. package/src/@daf/core/components/Screens/TableScreen/TablePageWithTabs/index.jsx +1 -1
  9. package/src/@daf/core/components/UI/MissingTagButton/index.jsx +36 -0
  10. package/src/@daf/pages/Dashboards/SupplyChain/components/SupplyChainMap/index.js +0 -2
  11. package/src/@daf/pages/Documents/config.js +0 -10
  12. package/src/@daf/pages/Documents/index.jsx +51 -108
  13. package/src/@daf/pages/Events/Activities/config.js +1 -11
  14. package/src/@daf/pages/Events/Activities/index.jsx +47 -105
  15. package/src/@daf/pages/Events/Incidents/config.js +1 -11
  16. package/src/@daf/pages/Events/Incidents/index.jsx +47 -105
  17. package/src/@daf/pages/Events/config.js +18 -34
  18. package/src/@daf/pages/Events/index.jsx +49 -111
  19. package/src/@daf/pages/Locations/MineSite/config.js +0 -10
  20. package/src/@daf/pages/Locations/MineSite/index.jsx +47 -105
  21. package/src/@daf/pages/Locations/config.js +4 -16
  22. package/src/@daf/pages/Locations/index.jsx +53 -110
  23. package/src/@daf/pages/Stakeholders/Operators/config.js +0 -10
  24. package/src/@daf/pages/Stakeholders/Operators/index.jsx +47 -105
  25. package/src/@daf/pages/Stakeholders/Workers/config.js +0 -10
  26. package/src/@daf/pages/Stakeholders/Workers/index.jsx +47 -105
  27. package/src/@daf/pages/Stakeholders/config.js +3 -15
  28. package/src/@daf/pages/Stakeholders/index.jsx +53 -109
  29. package/src/@daf/pages/TablePage/config.js +78 -0
  30. package/src/@daf/{core/components/Screens/TableScreen/TableWithTabsAndCreate → pages/TablePage}/create.jsx +6 -5
  31. package/src/@daf/pages/TablePage/hook.js +123 -0
  32. package/src/@daf/pages/TablePage/index.jsx +142 -0
  33. package/src/index.js +1 -0
  34. package/src/@daf/core/components/Screens/TableScreen/TableWithTabsAndCreate/index.jsx +0 -115
  35. package/src/@daf/pages/Documents/create.jsx +0 -105
  36. package/src/@daf/pages/Events/Activities/create.jsx +0 -104
  37. package/src/@daf/pages/Events/Incidents/create.jsx +0 -104
  38. package/src/@daf/pages/Events/create.jsx +0 -104
  39. package/src/@daf/pages/Locations/MineSite/create.jsx +0 -104
  40. package/src/@daf/pages/Locations/create.jsx +0 -104
  41. package/src/@daf/pages/Stakeholders/Operators/create.jsx +0 -104
  42. package/src/@daf/pages/Stakeholders/Workers/create.jsx +0 -104
  43. package/src/@daf/pages/Stakeholders/create.jsx +0 -105
@@ -1,11 +1,6 @@
1
- import React, { useMemo, useState, useEffect, useCallback } from 'react'
2
- import TablePageWithTabs from '../../../core/components/Screens/TableScreen/TablePageWithTabs/index.jsx'
1
+ import React from 'react'
3
2
  import { getColumns } from './columns.js';
4
- import { checkboxConfig, getFiltersConfig, filtersConfig, getFilterOptions } from './config.js';
5
- import { useGetQueryParams } from '../../../hooks/useGetQueryParams.js';
6
- import StakeholdersCreate from './create.jsx';
7
- import { displayMessage } from '../../../../helpers/messages.js';
8
- import { useFetchData } from '../../hook.js';
3
+ import TablePage from '../../TablePage/index.jsx';
9
4
 
10
5
  const WorkersTable = ({
11
6
  t = () => {},
@@ -38,105 +33,52 @@ const WorkersTable = ({
38
33
  applications = [],
39
34
  breadcrumbs = [],
40
35
  }) => {
41
- const [selectOptions, setSelectOptions] = useState();
42
- const [activeTab, setActiveTab] = useState('own');
43
-
44
- const columns = useMemo(() => getColumns({
45
- t,
46
- goTo,
47
- user,
48
- options,
49
- activeTab,
50
- getRedirectLink,
51
- theme,
52
- subject: 'workers',
53
- data,
54
- applications,
55
- }), [t, goTo, user, options, activeTab, getRedirectLink, theme, data, applications]);
56
-
57
- useFetchData({
58
- location,
59
- getData,
60
- activeTab,
61
- extendingFilters,
62
- subject: 'workers',
63
- })
64
-
65
- const selectFiltersConfig = useMemo(() => {
66
- return getFiltersConfig({t});
67
- }, [t]);
68
-
69
- useEffect(() => {
70
- setSelectOptions((prev) => ({
71
- ...prev,
72
- ...getFilterOptions(options, t),
73
- }))
74
- }, [options, t])
75
-
76
- const handleActiveTabChange = useCallback((value) => {
77
- setActiveTab(value);
78
- }, []);
79
-
80
36
  return (
81
- <TablePageWithTabs
82
- t={t}
83
- title={t("Workers")}
84
- breadCrumbs={breadcrumbs}
85
- location={location}
86
- loading={loading}
87
- goTo={goTo}
88
- defaultActiveTab={"own"}
89
- columns={columns}
90
- data={data}
91
- checkboxConfig={checkboxConfig}
92
- APP={APP}
93
- getApiBaseUrl={getApiBaseUrl}
94
- selectOptions={selectOptions}
95
- selectFiltersConfig={selectFiltersConfig}
96
- getRedirectLink={getRedirectLink}
97
- filtersConfig={filtersConfig}
98
- isMobile={isMobile}
99
- view="workers"
100
- getActiveTab={handleActiveTabChange}
101
- onDownload={() => {
102
- console.log("download");
103
- }}
104
- drawerTitle={t("Create Worker")}
105
- >
106
- {({onDrawerClose}) => (
107
- <StakeholdersCreate
108
- defaultData={createDefaultValues}
109
- t={t}
110
- goTo={goTo}
111
- user={user}
112
- APP={APP}
113
- getApiBaseUrl={getApiBaseUrl}
114
- getAppHeader={getAppHeader}
115
- getData={getFormData}
116
- saveData={saveFormData}
117
- loading={formLoading}
118
- onSubmitted={(type, m, data) => {
119
- if (data.datastakeId) {
120
- displayMessage(
121
- type,
122
- t("affirmations::subject-created-successfully") || m,
123
- );
124
- // goTo(`/app/edit/stakeholders/${data.datastakeId}`);
125
- goTo(`/app/edit/workers/${data.datastakeId}`)
126
- }
127
- }}
128
- onCancel={onDrawerClose}
129
- query={query}
130
- ajaxForms={ajaxForms}
131
- changeAjaxForms={changeAjaxForms}
132
- ajaxOptions={ajaxOptions}
133
- changeAjaxOptions={changeAjaxOptions}
134
- formData={formData}
135
- formValue={formValue}
136
- form={form}
137
- />
138
- )}
139
- </TablePageWithTabs>
37
+ <TablePage
38
+ t={t}
39
+ goTo={goTo}
40
+ user={user}
41
+ options={options}
42
+ getRedirectLink={getRedirectLink}
43
+ theme={theme}
44
+ loading={loading}
45
+ data={data}
46
+ isMobile={isMobile}
47
+ APP={APP}
48
+ location={location}
49
+ applications={applications}
50
+
51
+ subject="workers"
52
+ getData={getData}
53
+ getApiBaseUrl={getApiBaseUrl}
54
+ getAppHeader={getAppHeader}
55
+ getColumns={getColumns}
56
+ viewConfig={{
57
+ title: "Workers",
58
+ breadcrumbs: breadcrumbs,
59
+ createTitle: "Create Worker",
60
+ }}
61
+ extendingFilters={extendingFilters}
62
+ formConfig={{
63
+ getFormData,
64
+ saveFormData,
65
+ formLoading,
66
+ query,
67
+ ajaxForms,
68
+ changeAjaxForms,
69
+ ajaxOptions,
70
+ changeAjaxOptions,
71
+ formData,
72
+ formValue,
73
+ form,
74
+ namespace: "WORKERS",
75
+ view: ['scoping', 'new'],
76
+ scope: 'global',
77
+ formType: 'worker',
78
+ defaultValues: createDefaultValues,
79
+ }}
80
+ onDownload={() => console.log("download")}
81
+ />
140
82
  )
141
83
  }
142
84
 
@@ -1,8 +1,3 @@
1
- export const checkboxConfig = {
2
- name: 'Name',
3
- datastakeId: 'ID'
4
- }
5
-
6
1
  export const getFiltersConfig = ({t}) => {
7
2
  return {
8
3
  country: {
@@ -25,17 +20,10 @@ export const getFiltersConfig = ({t}) => {
25
20
  }
26
21
  }
27
22
 
28
- export const filtersConfig = {
29
- name: '',
30
- datastakeId: '',
31
- };
32
-
33
23
  export const getFilterOptions = (options, t) => {
34
- const { countries = [], category = [] } = options || {};
35
- const _default = {
24
+ const { countries = [], category = [], categoriesOptions = [] } = options || {};
25
+ return {
36
26
  country: countries,
37
- category: category,
27
+ category: categoriesOptions || category,
38
28
  }
39
-
40
- return _default;
41
29
  }
@@ -1,12 +1,6 @@
1
- import React, { useMemo, useState, useEffect, useCallback } from 'react'
2
- import TablePageWithTabs from '../../core/components/Screens/TableScreen/TablePageWithTabs/index.jsx'
1
+ import React from 'react'
3
2
  import { getColumns } from './columns.js';
4
- import { checkboxConfig, getFiltersConfig, filtersConfig, getFilterOptions } from './config.js';
5
- import { useGetQueryParams } from '../../hooks/useGetQueryParams.js';
6
- import StakeholdersCreate from './create.jsx';
7
- import { displayMessage } from '../../../helpers/messages.js';
8
- import DAFHeader from '../../core/components/Header/index.jsx';
9
- import { useFetchData } from '../hook.js';
3
+ import TablePage from '../TablePage/index.jsx';
10
4
 
11
5
  const StakeholdersTable = ({
12
6
  t = () => {},
@@ -38,109 +32,59 @@ const StakeholdersTable = ({
38
32
  subjectClear = () => {},
39
33
  breadcrumbs = [],
40
34
  extendingFilters = {},
35
+ createDefaultValues = {},
41
36
  }) => {
42
- const [selectOptions, setSelectOptions] = useState();
43
- const [activeTab, setActiveTab] = useState("own");
44
- const columns = useMemo(() => getColumns({
45
- t,
46
- goTo,
47
- user,
48
- options,
49
- activeTab,
50
- getRedirectLink,
51
- theme,
52
- subject: 'stakeholders',
53
- applications,
54
- }), [t, goTo, user, options, activeTab, getRedirectLink, theme, applications]);
55
-
56
- useFetchData({
57
- location,
58
- getData,
59
- activeTab,
60
- extendingFilters,
61
- subject: 'stakeholders',
62
- })
63
-
64
- const selectFiltersConfig = useMemo(() => {
65
- return getFiltersConfig({t});
66
- }, [t]);
67
-
68
- useEffect(() => {
69
- setSelectOptions((prev) => ({
70
- ...prev,
71
- ...getFilterOptions(options, t),
72
- }))
73
- }, [options, t])
74
-
75
- const handleActiveTabChange = useCallback((value) => {
76
- setActiveTab(value);
77
- }, []);
78
-
79
- useEffect(
80
- () => () => {
81
- subjectClear();
82
- },
83
- [],
84
- );
85
-
86
37
  return (
87
- <TablePageWithTabs
88
- t={t}
89
- title={t("Stakeholders")}
90
- breadCrumbs={breadcrumbs}
91
- location={location}
92
- loading={loading}
93
- goTo={goTo}
94
- defaultActiveTab={"own"}
95
- columns={columns}
96
- data={data}
97
- checkboxConfig={checkboxConfig}
98
- APP={APP}
99
- getApiBaseUrl={getApiBaseUrl}
100
- selectOptions={selectOptions}
101
- selectFiltersConfig={selectFiltersConfig}
102
- getRedirectLink={getRedirectLink}
103
- filtersConfig={filtersConfig}
104
- isMobile={isMobile}
105
- view="stakeholders"
106
- getActiveTab={handleActiveTabChange}
107
- onDownload={() => {
108
- console.log("download");
109
- }}
110
- drawerTitle={t("Create Stakeholder")}
111
- >
112
- {({onDrawerClose}) => (
113
- <StakeholdersCreate
114
- t={t}
115
- goTo={goTo}
116
- user={user}
117
- APP={APP}
118
- getApiBaseUrl={getApiBaseUrl}
119
- getAppHeader={getAppHeader}
120
- getData={getFormData}
121
- saveData={saveFormData}
122
- loading={formLoading}
123
- onSubmitted={(type, m, data) => {
124
- if (data.datastakeId) {
125
- displayMessage(
126
- type,
127
- t("affirmations::subject-created-successfully") || m,
128
- );
129
- goTo(`/app/edit/stakeholders/${data.datastakeId}`);
130
- }
131
- }}
132
- onCancel={onDrawerClose}
133
- query={query}
134
- ajaxForms={ajaxForms}
135
- changeAjaxForms={changeAjaxForms}
136
- ajaxOptions={ajaxOptions}
137
- changeAjaxOptions={changeAjaxOptions}
138
- formData={formData}
139
- formValue={formValue}
140
- form={form}
141
- />
142
- )}
143
- </TablePageWithTabs>
38
+ <TablePage
39
+ t={t}
40
+ goTo={goTo}
41
+ user={user}
42
+ options={options}
43
+ getRedirectLink={getRedirectLink}
44
+ theme={theme}
45
+ loading={loading}
46
+ data={data}
47
+ isMobile={isMobile}
48
+ APP={APP}
49
+ location={location}
50
+ applications={applications}
51
+
52
+ subject="stakeholders"
53
+ getData={getData}
54
+ getApiBaseUrl={getApiBaseUrl}
55
+ getAppHeader={getAppHeader}
56
+ subjectClear={subjectClear}
57
+ getColumns={getColumns}
58
+
59
+ viewConfig={{
60
+ title: "Stakeholders",
61
+ breadcrumbs: breadcrumbs,
62
+ createTitle: "Create Stakeholder",
63
+ }}
64
+
65
+ extendingFilters={extendingFilters}
66
+
67
+ formConfig={{
68
+ getFormData,
69
+ saveFormData,
70
+ formLoading,
71
+ query,
72
+ ajaxForms,
73
+ changeAjaxForms,
74
+ ajaxOptions,
75
+ changeAjaxOptions,
76
+ formData,
77
+ formValue,
78
+ form,
79
+ namespace: 'stakeholders',
80
+ view: 'scoping',
81
+ scope: 'create',
82
+ formType: 'stakeholder',
83
+ defaultValues: createDefaultValues,
84
+ }}
85
+
86
+ onDownload={() => console.log("download")}
87
+ />
144
88
  )
145
89
  }
146
90
 
@@ -0,0 +1,78 @@
1
+ import { getFiltersConfig as getFiltersConfigStakeholders, getFilterOptions as getFilterOptionsStakeholders } from '../Stakeholders/config';
2
+ import { getFiltersConfig as getFiltersConfigOperators, getFilterOptions as getFilterOptionsOperators } from '../Stakeholders/Operators/config';
3
+ import { getFiltersConfig as getFiltersConfigWorkers, getFilterOptions as getFilterOptionsWorkers } from '../Stakeholders/Workers/config';
4
+
5
+ import { getFiltersConfig as getFiltersConfigEvents, getFilterOptions as getFilterOptionsEvents } from '../Events/config';
6
+ import { getFiltersConfig as getFiltersConfigActivities, getFilterOptions as getFilterOptionsActivities } from '../Events/Activities/config';
7
+ import { getFiltersConfig as getFiltersConfigIncidents, getFilterOptions as getFilterOptionsIncidents } from '../Events/Incidents/config';
8
+
9
+ import { getFiltersConfig as getFiltersConfigLocations, getFilterOptions as getFilterOptionsLocations } from '../Locations/config';
10
+ import { getFiltersConfig as getFiltersConfigProductionSites, getFilterOptions as getFilterOptionsProductionSites } from '../Locations/MineSite/config';
11
+
12
+ import { getFiltersConfig as getFilterConfigDocuments, getFilterOptions as getFilterOptionsDocuments } from '../Documents/config';
13
+
14
+
15
+ export const getCheckboxConfig = ({ subject }) => {
16
+ return {
17
+ name: 'Name',
18
+ datastakeId: 'ID'
19
+ }
20
+ }
21
+
22
+ export const getSelectFiltersConfig = ({ subject }) => {
23
+ return {
24
+ name: '',
25
+ datastakeId: '',
26
+ }
27
+ };
28
+
29
+ const FILTER_REGISTRY = {
30
+ stakeholders: {
31
+ config: getFiltersConfigStakeholders,
32
+ options: getFilterOptionsStakeholders,
33
+ },
34
+ workers: {
35
+ config: getFiltersConfigWorkers,
36
+ options: getFilterOptionsWorkers,
37
+ },
38
+ operators: {
39
+ config: getFiltersConfigOperators,
40
+ options: getFilterOptionsOperators,
41
+ },
42
+ events: {
43
+ config: getFiltersConfigEvents,
44
+ options: getFilterOptionsEvents,
45
+ },
46
+ activities: {
47
+ config: getFiltersConfigActivities,
48
+ options: getFilterOptionsActivities,
49
+ },
50
+ incidents: {
51
+ config: getFiltersConfigIncidents,
52
+ options: getFilterOptionsIncidents,
53
+ },
54
+ locations: {
55
+ config: getFiltersConfigLocations,
56
+ options: getFilterOptionsLocations,
57
+ },
58
+ 'production-sites': {
59
+ config: getFiltersConfigProductionSites,
60
+ options: getFilterOptionsProductionSites,
61
+ },
62
+ documents: {
63
+ config: getFilterConfigDocuments,
64
+ options: getFilterOptionsDocuments,
65
+ },
66
+ };
67
+
68
+ const DEFAULT_SUBJECT = 'stakeholders';
69
+
70
+ export const getFiltersConfig = ({ t, subject }) => {
71
+ const registry = FILTER_REGISTRY[subject] || FILTER_REGISTRY[DEFAULT_SUBJECT];
72
+ return registry?.config({ t });
73
+ };
74
+
75
+ export const getFilterOptions = ({ t, subject, options }) => {
76
+ const registry = FILTER_REGISTRY[subject] || FILTER_REGISTRY[DEFAULT_SUBJECT];
77
+ return registry.options(options, t);
78
+ };
@@ -4,8 +4,8 @@ import { MessageTypes } from '../../../helpers/messages.js';
4
4
  import DynamicForm from '../../core/components/DynamicForm/index.jsx';
5
5
 
6
6
  const Create = ({
7
- namespace = 'stakeholders',
8
- view = 'scoping',
7
+ namespace,
8
+ view,
9
9
  edit = false,
10
10
  formData = {},
11
11
  loading = false,
@@ -27,7 +27,8 @@ const Create = ({
27
27
  changeAjaxOptions = () => {},
28
28
  getAppHeader = () => {},
29
29
  getApiBaseUrl = () => {},
30
- scope
30
+ scope,
31
+ formType
31
32
  }) => {
32
33
  let {
33
34
  form = {},
@@ -52,7 +53,7 @@ const Create = ({
52
53
  <div className="daf-create-form">
53
54
  <DynamicForm
54
55
  form={form}
55
- data={data}
56
+ data={{...defaultData, ...data}}
56
57
  showSaveAndNext={false}
57
58
  module={APP}
58
59
  onCancel={onCancel}
@@ -75,7 +76,7 @@ const Create = ({
75
76
  const newPayload = {
76
77
  ...defaultData,
77
78
  ...payloadData,
78
- form: 'stakeholder'
79
+ form: formType
79
80
  };
80
81
 
81
82
 
@@ -0,0 +1,123 @@
1
+ import { useState, useEffect, useCallback, useMemo } from 'react';
2
+ import { useGetQueryParams } from "../../hooks/useGetQueryParams.js";
3
+ import { getFiltersConfig, getFilterOptions, getCheckboxConfig, getSelectFiltersConfig } from './config.js';
4
+
5
+ export const useFetchData = ({
6
+ location,
7
+ getData,
8
+ activeTab,
9
+ extendingFilters,
10
+ subject,
11
+ }) => {
12
+ const { paginationQuery, searchParams, otherParams, sortBy, sortDir, } = useGetQueryParams({location});
13
+ useEffect(() => {
14
+ const cleanSearchParams = Object.fromEntries(
15
+ Object.entries(searchParams).filter(([_, value]) => value != null && value !== '')
16
+ );
17
+
18
+ const hasPagination = paginationQuery.skip != null || paginationQuery.take != null;
19
+
20
+ if (!hasPagination) {
21
+ return;
22
+ }
23
+
24
+ getData({
25
+ ...extendingFilters,
26
+ pagination: paginationQuery,
27
+ ...(Object.keys(otherParams).length > 0 && otherParams ),
28
+ ...(Object.keys(cleanSearchParams).length > 0 && { search: cleanSearchParams }),
29
+ tab: activeTab,
30
+ sortBy: {
31
+ [sortBy || "updatedAt"]: sortDir ? (sortDir === "ascend" ? 1 : -1) : -1,
32
+ },
33
+ }, subject)
34
+ }, [location.search, activeTab, JSON.stringify(extendingFilters)]);
35
+ }
36
+
37
+ export const useTablePage = ({
38
+ subject,
39
+ location,
40
+ getData,
41
+ getColumns,
42
+ extendingFilters,
43
+ options,
44
+ t,
45
+ goTo,
46
+ user,
47
+ getRedirectLink,
48
+ theme,
49
+ data,
50
+ applications,
51
+ subjectClear,
52
+ }) => {
53
+ const [selectOptions, setSelectOptions] = useState();
54
+ const [activeTab, setActiveTab] = useState("own");
55
+
56
+ useFetchData({
57
+ location,
58
+ getData,
59
+ activeTab,
60
+ extendingFilters: extendingFilters,
61
+ subject,
62
+ });
63
+
64
+ const columns = useMemo(() =>
65
+ getColumns({
66
+ t,
67
+ goTo,
68
+ user,
69
+ options,
70
+ activeTab,
71
+ getRedirectLink,
72
+ theme,
73
+ subject,
74
+ data,
75
+ applications,
76
+ }),
77
+ [t, goTo, user, options, activeTab, getRedirectLink, theme, data, applications, subject, getColumns]
78
+ );
79
+
80
+ const selectFiltersConfig = useMemo(() =>
81
+ getFiltersConfig({ t, subject }),
82
+ [t, subject, getFiltersConfig]
83
+ );
84
+
85
+ useEffect(() => {
86
+ setSelectOptions((prev) => ({
87
+ ...prev,
88
+ ...getFilterOptions({ t, subject, options }),
89
+ }));
90
+ }, [options, t, subject, getFilterOptions]);
91
+
92
+ const checkboxConfig = useMemo(() =>
93
+ getCheckboxConfig({ subject }),
94
+ [subject, getCheckboxConfig]
95
+ );
96
+
97
+ const _filtersConfig = useMemo(() => {
98
+ return getSelectFiltersConfig({ subject });
99
+ }, [subject, getSelectFiltersConfig]);
100
+
101
+ const handleActiveTabChange = useCallback((value) => {
102
+ setActiveTab(value);
103
+ }, []);
104
+
105
+ useEffect(
106
+ () => () => {
107
+ if (subjectClear && typeof subjectClear === 'function') {
108
+ subjectClear();
109
+ }
110
+ },
111
+ [subjectClear]
112
+ );
113
+
114
+ return {
115
+ activeTab,
116
+ selectOptions,
117
+ columns,
118
+ selectFiltersConfig,
119
+ handleActiveTabChange,
120
+ checkboxConfig,
121
+ _filtersConfig,
122
+ };
123
+ }