datastake-daf 0.6.732 → 0.6.734

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.
@@ -0,0 +1,150 @@
1
+ import React from 'react';
2
+ import { Tooltip } from 'antd';
3
+ import { findOptions } from '../../../../../helpers/StringHelper.js';
4
+ import { renderDateFormatted } from '../../../../../helpers/Forms.js';
5
+ import CustomIcon from '../../../../core/components/Icon/CustomIcon.jsx';
6
+ import AvatarGroup from '../../../../core/components/AvatarGroup/index.jsx';
7
+
8
+ const getLinkValue = (value, linkingObject) => {
9
+ if(linkingObject && linkingObject?.[value]) {
10
+ return linkingObject?.[value]?.name;
11
+ }
12
+ return null;
13
+ }
14
+
15
+ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink, theme, subject, data}) => [
16
+ {
17
+ dataIndex: 'datastakeId',
18
+ title: t('ID'),
19
+ ellipsis: true,
20
+ show: true,
21
+ render: (v, all) => {
22
+ if (all.empty) {
23
+ return <div className="daf-default-cell" />
24
+ }
25
+
26
+ return <Tooltip title={v}>{v}</Tooltip>;
27
+ },
28
+ },
29
+ {
30
+ dataIndex: 'name',
31
+ title: t('Name'),
32
+ ellipsis: true,
33
+ show: true,
34
+ render: (v, all) => {
35
+ if (all.empty) {
36
+ return <div className="daf-default-cell" />
37
+ }
38
+
39
+ return <Tooltip title={v}>{v}</Tooltip>;
40
+ },
41
+ },
42
+ {
43
+ dataIndex: 'category',
44
+ title: t('Category'),
45
+ ellipsis: true,
46
+ show: true,
47
+ render: (v, all) => {
48
+ if (all.empty) {
49
+ return <div className="daf-default-cell" />
50
+ }
51
+
52
+ const category = findOptions(v, data?.options?.locationCategories);
53
+
54
+ return category ? <Tooltip title={category}>{category}</Tooltip> : '-';
55
+ },
56
+ },
57
+ {
58
+ dataIndex: 'country',
59
+ title: t('Country'),
60
+ ellipsis: true,
61
+ show: true,
62
+ render: (v, all) => {
63
+ if (all.empty) {
64
+ return <div className="daf-default-cell" />
65
+ }
66
+
67
+ const country = findOptions(v, options?.countries);
68
+
69
+ return country ? <Tooltip title={country}>{country}</Tooltip> : '-';
70
+ },
71
+ },
72
+ {
73
+ dataIndex: 'administrativeLevel1',
74
+ title: t('Region'),
75
+ ellipsis: true,
76
+ show: true,
77
+ render: (v, all) => {
78
+ if (all.empty) {
79
+ return <div className="daf-default-cell" />
80
+ }
81
+
82
+ const region = getLinkValue(v, all?.linking?.SCL);
83
+
84
+ return region ? <Tooltip title={region}>{region}</Tooltip> : '-';
85
+ },
86
+ },
87
+ {
88
+ dataIndex: 'administrativeLevel2',
89
+ title: t('District'),
90
+ ellipsis: true,
91
+ show: true,
92
+ render: (v, all) => {
93
+ if (all.empty) {
94
+ return <div className="daf-default-cell" />
95
+ }
96
+
97
+ const district = getLinkValue(v, all?.linking?.SCL);
98
+
99
+ return district ? <Tooltip title={district}>{district}</Tooltip> : '-';
100
+ },
101
+ },
102
+ {
103
+ title: t("Last Update"),
104
+ dataIndex: "updatedAt",
105
+ key: "updatedAt",
106
+ width: 125,
107
+ render: (date, all) => {
108
+ if (all.empty) {
109
+ return <div className="daf-default-cell" />;
110
+ }
111
+
112
+ const _date = date ? renderDateFormatted(date, "DD MMM YYYY", user?.language || 'en') : "-";
113
+ return <Tooltip title={_date}>{_date}</Tooltip>;
114
+ },
115
+ ellipsis: true,
116
+ },
117
+ {
118
+ title: t("Sources"),
119
+ dataIndex: "sources",
120
+ key: "sources",
121
+ show: activeTab !== "own",
122
+ render: (val, all) => {
123
+ if (all.empty) {
124
+ return <div className="daf-default-cell" />;
125
+ }
126
+
127
+ console.log({val, all})
128
+
129
+ return <AvatarGroup items={val}></AvatarGroup>;
130
+ },
131
+ },
132
+ {
133
+ id: 'actions',
134
+ title: "",
135
+ width: 60,
136
+ render: (_, all) => {
137
+ if (all.empty) {
138
+ return <div className="daf-default-cell" />;
139
+ }
140
+
141
+ const link = `/app/view/${subject}/${all.datastakeId}`;
142
+
143
+ return <div style={{ display: "flex", justifyContent: "center" }}>
144
+ <a href={getRedirectLink(link)}>
145
+ <CustomIcon name="Link" size={15} color={theme.baseGray70} />
146
+ </a>
147
+ </div>;
148
+ }
149
+ }
150
+ ].filter((column) => column.show !== false);
@@ -0,0 +1,31 @@
1
+ export const checkboxConfig = {
2
+ name: 'Name',
3
+ datastakeId: 'ID'
4
+ }
5
+
6
+ export const getFiltersConfig = ({t}) => {
7
+ return {
8
+ country: {
9
+ type: 'select',
10
+ placeholder: t('Country'),
11
+ style: { flex: 1 },
12
+ labelStyle: { flex: 1 },
13
+ getLabel: (option) => option.label,
14
+ getValue: (option) => option.value,
15
+ },
16
+ }
17
+ }
18
+
19
+ export const filtersConfig = {
20
+ name: '',
21
+ datastakeId: '',
22
+ };
23
+
24
+ export const getFilterOptions = (options, t) => {
25
+ const { countries } = options || {};
26
+ const _default = {
27
+ country: countries,
28
+ }
29
+
30
+ return _default;
31
+ }
@@ -0,0 +1,104 @@
1
+ import React, { useEffect} from 'react'
2
+ import { message } from 'antd';
3
+ import { MessageTypes } from '../../../../../helpers/messages.js';
4
+ import DynamicForm from '../../../../core/components/DynamicForm/index.jsx';
5
+
6
+ const StakeholdersCreate = ({
7
+ namespace = 'locations',
8
+ view = 'scoping',
9
+ edit = false,
10
+ formData = {},
11
+ loading = false,
12
+ onSubmitted = () => {},
13
+ onCancel = () => {},
14
+ getData = () => {},
15
+ saveData = () => {},
16
+ form: formConfig = {},
17
+ formValue = {},
18
+ defaultData = {},
19
+ user = {},
20
+ APP,
21
+ query,
22
+ goTo = () => {},
23
+ t = () => {},
24
+ ajaxForms = {},
25
+ changeAjaxForms = () => {},
26
+ ajaxOptions = {},
27
+ changeAjaxOptions = () => {},
28
+ getAppHeader = () => {},
29
+ getApiBaseUrl = () => {},
30
+ }) => {
31
+ let {
32
+ form = {},
33
+ data = defaultData || {},
34
+ } = !edit ? (formData[`${APP}-${view}`] || {}) : {
35
+ form: formConfig,
36
+ data: formValue
37
+ };
38
+
39
+ useEffect(() => {
40
+ if (Object.keys(form).length === 0 && !formData[`${APP}-${view}`]) {
41
+ if (!edit) {
42
+ getData({ namespace, module: APP, view, scope: 'global' });
43
+ } else {
44
+ form = formConfig;
45
+ data = formValue;
46
+ }
47
+ }
48
+ }, [edit, user?.language]);
49
+
50
+ return (
51
+ <div className="daf-create-form">
52
+ <DynamicForm
53
+ form={form}
54
+ data={data}
55
+ showSaveAndNext={false}
56
+ module={APP}
57
+ onCancel={onCancel}
58
+ isCreate
59
+ t={t}
60
+ excludedKeys={["title"]}
61
+ user={user}
62
+ ajaxForms={ajaxForms}
63
+ ajaxOptions={ajaxOptions}
64
+ getAppHeader={getAppHeader}
65
+ getApiBaseUrl={getApiBaseUrl}
66
+ changeAjaxOptions={changeAjaxOptions}
67
+ app={APP}
68
+ query={query}
69
+ goTo={goTo}
70
+ changeAjaxForms={changeAjaxForms}
71
+ submit={(payload, setSelectedFormNext) => {
72
+ const payloadData = { ...payload, module: APP, namespace };
73
+
74
+ const newPayload = {
75
+ ...defaultData,
76
+ ...payloadData,
77
+ form: 'location'
78
+ };
79
+
80
+ const callback = (type, m, data) => {
81
+ if (setSelectedFormNext) {
82
+ setSelectedFormNext();
83
+ }
84
+ if (type === MessageTypes.SUCCESS) {
85
+ if (onSubmitted) onSubmitted(type, m, data);
86
+ } else {
87
+ message.error(m);
88
+ }
89
+ };
90
+
91
+ saveData(
92
+ !data && !data.id ? newPayload : Object.assign(newPayload, { id: data.id }),
93
+ callback,
94
+ );
95
+ }}
96
+ isFormDisabled={() => {
97
+ return !data || !data.typeOfEvent;
98
+ }}
99
+ />
100
+ </div>
101
+ )
102
+ }
103
+
104
+ export default StakeholdersCreate
@@ -0,0 +1,143 @@
1
+ import React, { useMemo, useState, useEffect, useCallback } from 'react'
2
+ import TablePageWithTabs from '../../../pages/TablePageWithTabs/index.jsx'
3
+ 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
+
9
+ const LocationsTable = ({
10
+ t = () => {},
11
+ goTo = () => {},
12
+ user = {},
13
+ options = {},
14
+ getRedirectLink = () => {},
15
+ theme = {},
16
+ loading = false,
17
+ data = {},
18
+ isMobile,
19
+ APP,
20
+ location,
21
+ getData = () => {},
22
+ getApiBaseUrl = () => {},
23
+ getAppHeader = () => {},
24
+ getFormData = () => {},
25
+ saveFormData = () => {},
26
+ formLoading = false,
27
+ query = {},
28
+ ajaxForms = {},
29
+ changeAjaxForms = () => {},
30
+ ajaxOptions = {},
31
+ changeAjaxOptions = () => {},
32
+ formData = {},
33
+ formValue = {},
34
+ form = {},
35
+ }) => {
36
+ const [selectOptions, setSelectOptions] = useState();
37
+ const [activeTab, setActiveTab] = useState();
38
+
39
+ const columns = useMemo(() => getColumns({
40
+ t,
41
+ goTo,
42
+ user,
43
+ options,
44
+ activeTab,
45
+ getRedirectLink,
46
+ theme,
47
+ subject: 'locations',
48
+ data,
49
+ }), [t, goTo, user, options, activeTab, getRedirectLink, theme, data]);
50
+
51
+ const breadCrumbs = [];
52
+
53
+ const { paginationQuery, searchParams, otherParams } = useGetQueryParams({location});
54
+
55
+ useEffect(() => {
56
+ getData({
57
+ pagination: paginationQuery,
58
+ ...(Object.keys(otherParams).length > 0 && { filters: otherParams }),
59
+ ...(Object.keys(searchParams).length > 0 && { search: searchParams }),
60
+ tab: activeTab,
61
+ }, 'locations')
62
+ }, [paginationQuery, otherParams, searchParams, activeTab]);
63
+
64
+ console.log({data})
65
+
66
+ const selectFiltersConfig = useMemo(() => {
67
+ return getFiltersConfig({t});
68
+ }, [t]);
69
+
70
+ useEffect(() => {
71
+ setSelectOptions((prev) => ({
72
+ ...prev,
73
+ ...getFilterOptions(options, t),
74
+ }))
75
+ }, [options, t])
76
+
77
+ const handleActiveTabChange = useCallback((value) => {
78
+ setActiveTab(value);
79
+ }, []);
80
+
81
+ return (
82
+ <TablePageWithTabs
83
+ t={t}
84
+ title={t("Locations")}
85
+ breadCrumbs={breadCrumbs}
86
+ location={location}
87
+ loading={loading}
88
+ goTo={goTo}
89
+ defaultActiveTab={"all"}
90
+ columns={columns}
91
+ data={data}
92
+ checkboxConfig={checkboxConfig}
93
+ APP={APP}
94
+ getApiBaseUrl={getApiBaseUrl}
95
+ selectOptions={selectOptions}
96
+ selectFiltersConfig={selectFiltersConfig}
97
+ getRedirectLink={getRedirectLink}
98
+ filtersConfig={filtersConfig}
99
+ isMobile={isMobile}
100
+ view="locations"
101
+ getActiveTab={handleActiveTabChange}
102
+ onDownload={() => {
103
+ console.log("download");
104
+ }}
105
+ drawerTitle={t("Create Location")}
106
+ >
107
+ {({onDrawerClose}) => (
108
+ <StakeholdersCreate
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/locations')
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>
140
+ )
141
+ }
142
+
143
+ export default LocationsTable
@@ -10,7 +10,7 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
10
10
  dataIndex: 'datastakeId',
11
11
  title: t('ID'),
12
12
  ellipsis: true,
13
- show: true,
13
+ show: true,
14
14
  render: (v, all) => {
15
15
  if (all.empty) {
16
16
  return <div className="daf-default-cell" />
@@ -78,9 +78,9 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
78
78
  },
79
79
  },
80
80
  {
81
- title: t("Date"),
82
- dataIndex: "date",
83
- key: "date",
81
+ title: t("Last Update"),
82
+ dataIndex: "updatedAt",
83
+ key: "updatedAt",
84
84
  width: 125,
85
85
  render: (date, all) => {
86
86
  if (all.empty) {
@@ -74,7 +74,9 @@ const StakeholdersCreate = ({
74
74
  const newPayload = {
75
75
  ...defaultData,
76
76
  ...payloadData,
77
+ form: 'stakeholder'
77
78
  };
79
+
78
80
 
79
81
  const callback = (type, m, data) => {
80
82
  if (setSelectedFormNext) {
@@ -43,7 +43,7 @@ const StakeholdersTable = ({
43
43
  activeTab,
44
44
  getRedirectLink,
45
45
  theme,
46
- subject: 'stakeholder'
46
+ subject: 'stakeholders'
47
47
  }), [t, goTo, user, options, activeTab, getRedirectLink, theme]);
48
48
 
49
49
  const breadCrumbs = [];
@@ -108,9 +108,6 @@ const StakeholdersTable = ({
108
108
  APP={APP}
109
109
  getApiBaseUrl={getApiBaseUrl}
110
110
  getAppHeader={getAppHeader}
111
- defaultData={{
112
- economicSector: 'miningMineralTrade'
113
- }}
114
111
  getData={getFormData}
115
112
  saveData={saveFormData}
116
113
  loading={formLoading}
@@ -120,7 +117,7 @@ const StakeholdersTable = ({
120
117
  type,
121
118
  t("affirmations::subject-created-successfully") || m,
122
119
  );
123
- goTo(`/app/edit/stakeholders/${data.datastakeId}`);
120
+ goTo(`/app/stakeholders`);
124
121
  }
125
122
  }}
126
123
  onCancel={onDrawerClose}
@@ -25,6 +25,8 @@ function Identification({
25
25
  [t],
26
26
  );
27
27
 
28
+ console.log({identificationData: data})
29
+
28
30
  const chartConfig = useIdentification({ data, theme, options });
29
31
 
30
32
  return (
@@ -24,7 +24,7 @@ function TradeRelationships({goTo, t = () => {}, options = {}, hardcodedData = [
24
24
 
25
25
  const { data, loading } = useWidgetFetch({config: fetchConfig});
26
26
 
27
- const mappedData = mapDataForChainOfCustody(Object.keys(data)?.length > 0 ? data : hardcodedData, options?.category ?? [], goTo);
27
+ const mappedData = mapDataForChainOfCustody(Object.keys(data)?.length > 0 ? data : hardcodedData, options, goTo);
28
28
 
29
29
  return (
30
30
  <Widget
@@ -64,6 +64,9 @@ function MineSites({
64
64
  [activeTab, selectedPartners],
65
65
  );
66
66
 
67
+ console.log({activeTab})
68
+ console.log({dataFetchConfig})
69
+
67
70
  const { data, loading, setData } = useWidgetFetch({config: dataFetchConfig});
68
71
 
69
72
  const tabs = useMemo(() => getTabs(t), [t]);
@@ -45,14 +45,15 @@ const mapIcon = (category) => {
45
45
  const leftBackground = theme.colorPrimary3;
46
46
  const rightBackground = theme.colorPrimary6;
47
47
 
48
- export const mapDataForChainOfCustody = (data = {}, options = [], goTo = () => {}) => {
48
+ export const mapDataForChainOfCustody = (data = {}, options = {}, goTo = () => {}) => {
49
49
  const mapChildren = (items, type, parentId, isDirect = true) => {
50
- return (items ?? []).map((item) => ({
50
+ return (items ?? []).map((item) => {
51
+ return {
51
52
  id: item.id,
52
53
  number: 0,
53
54
  name: item.name,
54
55
  sources: parentId ? [parentId] : [],
55
- subTitle: findOptions(item.category, options),
56
+ subTitle: findOptions(item?.category, options?.categoriesOptions),
56
57
  leftIcon: type === "client" ? rightIcon : leftIcon,
57
58
  leftBackground: type === "client" ? rightBackground : leftBackground,
58
59
  topIcon: mapIcon(item.category),
@@ -62,14 +63,14 @@ export const mapDataForChainOfCustody = (data = {}, options = [], goTo = () => {
62
63
  goTo(`/app/partners?datastakeId=${item.id}`);
63
64
  }
64
65
  },
65
- }));
66
+ }});
66
67
  };
67
68
 
68
69
  return {
69
70
  id: data.id,
70
71
  number: 0,
71
72
  name: data.name,
72
- subTitle: findOptions(data.category, options),
73
+ subTitle: findOptions(data?.category, options?.categoriesOptions),
73
74
  leftIcon: middleIcon,
74
75
  leftBackground: theme.colorPrimary10,
75
76
  topIcon: mapIcon(data.category),
@@ -42,7 +42,7 @@ class LinkedSubjectsService extends BaseService {
42
42
  const _namespace = getNamespace(namespace);
43
43
 
44
44
  return this.apiGet({
45
- url: `/${_namespace}/associated-information`,
45
+ url: `/${_namespace}`,
46
46
  isApp: true,
47
47
  params: query,
48
48
  signal,
package/src/pages.js CHANGED
@@ -4,4 +4,5 @@ export { default as UserDashboard } from './@daf/pages/dashboards/UserDashboard/
4
4
  export { default as StakeholdersTable } from './@daf/pages/dashboards/AllInformation/Stakeholders/index.jsx';
5
5
 
6
6
  // Pages
7
- export { default as TablePageWithTabs } from './@daf/pages/pages/TablePageWithTabs/index.jsx';
7
+ export { default as TablePageWithTabs } from './@daf/pages/pages/TablePageWithTabs/index.jsx';
8
+ export { default as LocationsTable } from './@daf/pages/dashboards/AllInformation/Locations/index.jsx';