datastake-daf 0.6.738 → 0.6.740

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.
@@ -5,15 +5,121 @@ export const checkboxConfig = {
5
5
 
6
6
  export const getFiltersConfig = ({t}) => {
7
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,
8
+ country: {
9
+ type: 'select',
10
+ label: 'Country',
11
+ placeholder: (t) => `${t('Filter by')} ${t('Country').toLowerCase()}`,
12
+ style: { flex: 1 },
13
+ labelStyle: { flex: 1 },
14
+ getLabel: (option) => option.label,
15
+ getValue: (option) => option.value,
15
16
  },
16
- }
17
+ administrativeLevel1: {
18
+ type: 'ajaxSelect',
19
+ label: ({ t = (s) => s, options = {}, filters = {}, language = 'en' }) => {
20
+ const { administrativeLevel1 } = options;
21
+
22
+ if (administrativeLevel1) {
23
+ if (options.country) {
24
+ const _item = administrativeLevel1[filters.country];
25
+ if (_item) {
26
+ if (_item[language]) {
27
+ return _item[language]
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ return t('Province');
34
+ },
35
+ placeholder: (t) => `${t('Filter by')} ${t('Province').toLowerCase()}`,
36
+ filters: (data) => ({
37
+ country: data.country,
38
+ level: 'level_1',
39
+ }),
40
+ show: (data) => !data.country,
41
+ disabled: (data) => !data.country,
42
+ mapper: { label: "name", value: "id" },
43
+ method: 'getOptions',
44
+ entity: 'AdministrativeLevel',
45
+ style: { flex: 1 },
46
+ labelStyle: { flex: 1 },
47
+ },
48
+ administrativeLevel2: {
49
+ type: 'ajaxSelect',
50
+ label: ({ t = (s) => s, options = {}, filters = {}, language = 'en' }) => {
51
+ const { administrativeLevel2 } = options;
52
+
53
+ if (administrativeLevel2) {
54
+ if (options.country) {
55
+ const _item = administrativeLevel2[filters.country];
56
+ if (_item) {
57
+ if (_item[language]) {
58
+ return _item[language]
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ return t('Province');
65
+ },
66
+ show: (data) => !(data.country && data.administrativeLevel1),
67
+ placeholder: (t) => `${t('Filter by')} ${t('Territory').toLowerCase()}`,
68
+ filters: (data) => ({
69
+ country: data.country,
70
+ level: 'level_2',
71
+ administrativeLevel1: data.administrativeLevel1,
72
+ }),
73
+ disabled: (data) => !(data.country && data.administrativeLevel1),
74
+ mapper: { label: "name", value: "id" },
75
+ method: 'getOptions',
76
+ entity: 'AdministrativeLevel',
77
+ style: { flex: 1 },
78
+ labelStyle: { flex: 1 },
79
+ },
80
+ subCategory: {
81
+ type: 'select',
82
+ label: 'Sub Category',
83
+ placeholder: (t) => `${t('Filter by')} ${t('Sub Category').toLowerCase()}`,
84
+ style: { flex: 1 },
85
+ labelStyle: { flex: 1 },
86
+ getLabel: (option) => option.label,
87
+ getValue: (option) => option.value,
88
+ filterOptions: (val) => {
89
+ if (val) {
90
+ const { option, filters } = val
91
+ if (filters && option) {
92
+ const { filters: optionFilters } = option;
93
+ if (Array.isArray(optionFilters) && optionFilters.length) {
94
+ const { value, condition } = optionFilters[0];
95
+ if (condition === 'includes') {
96
+ return value.includes('corporation');
97
+ }
98
+ }
99
+ }
100
+ }
101
+ return true;
102
+ },
103
+ },
104
+ positionInTheMineralSupplyChain: {
105
+ type: 'select',
106
+ label: 'Position',
107
+ placeholder: (t) => `${t('Filter by')} ${t('Position').toLowerCase()}`,
108
+ style: { flex: 1 },
109
+ labelStyle: { flex: 1 },
110
+ getLabel: (option) => option.label,
111
+ getValue: (option) => option.value,
112
+ },
113
+ status: {
114
+ type: "select",
115
+ label: "Status",
116
+ placeholder: (t) => `${t("Filter by")} ${t("Status").toLowerCase()}`,
117
+ style: { flex: 1 },
118
+ labelStyle: { fley: 1 },
119
+ getLabel: (option) => option.label,
120
+ getValue: (option) => option.value,
121
+ },
122
+ }
17
123
  }
18
124
 
19
125
  export const filtersConfig = {
@@ -22,9 +128,35 @@ export const filtersConfig = {
22
128
  };
23
129
 
24
130
  export const getFilterOptions = (options, t) => {
25
- const { countries } = options || {};
131
+ const {
132
+ statusOptions = [],
133
+ categoryOptions = [],
134
+ countries = [],
135
+ subCategory = [],
136
+ subCategoriesOptions,
137
+ stakeholderCategoryOptions,
138
+ stakeholderSubCategoriesOptions,
139
+ administrativeLevel1,
140
+ administrativeLevel2,
141
+ } = options || {};
142
+ console.log({options})
143
+
26
144
  const _default = {
145
+ category: stakeholderCategoryOptions || categoryOptions,
27
146
  country: countries,
147
+ administrativeLevel1,
148
+ administrativeLevel2,
149
+ subCategory: subCategoriesOptions,
150
+ status: [
151
+ {
152
+ value: "submitted",
153
+ label: "Submitted",
154
+ },
155
+ {
156
+ value: "private",
157
+ label: "Private",
158
+ },
159
+ ],
28
160
  }
29
161
 
30
162
  return _default;
@@ -51,7 +51,7 @@ const StakeholdersCreate = ({
51
51
  <div className="daf-create-form">
52
52
  <DynamicForm
53
53
  form={form}
54
- data={data}
54
+ data={{...defaultData, ...data}}
55
55
  showSaveAndNext={false}
56
56
  module={APP}
57
57
  onCancel={onCancel}
@@ -33,6 +33,7 @@ const OperatorsTable = ({
33
33
  formValue = {},
34
34
  form = {},
35
35
  extendingFilters = {},
36
+ createDefaultValues = {},
36
37
  }) => {
37
38
  const [selectOptions, setSelectOptions] = useState();
38
39
  const [activeTab, setActiveTab] = useState();
@@ -61,21 +62,18 @@ const OperatorsTable = ({
61
62
  }, [otherParams, extendingFilters])
62
63
 
63
64
  useEffect(() => {
64
- console.log("fetching data")
65
65
  getData({
66
66
  pagination: paginationQuery,
67
- ...(Object.keys(filters).length > 0 && { filters: filters }),
68
67
  ...(Object.keys(searchParams).length > 0 && { search: searchParams }),
68
+ ...otherParams,
69
69
  tab: activeTab,
70
70
  sortBy: {
71
71
  [sortBy || "updatedAt"]: sortDir ? (sortDir === "ascend" ? 1 : -1) : -1,
72
- }
72
+ },
73
+ ...extendingFilters
73
74
  }, 'operators')
74
- console.log("data fetched")
75
75
  }, [location.search, activeTab, JSON.stringify(extendingFilters)]);
76
76
 
77
- console.log({data})
78
-
79
77
  const selectFiltersConfig = useMemo(() => {
80
78
  return getFiltersConfig({t});
81
79
  }, [t]);
@@ -119,6 +117,7 @@ const OperatorsTable = ({
119
117
  >
120
118
  {({onDrawerClose}) => (
121
119
  <StakeholdersCreate
120
+ defaultData={createDefaultValues}
122
121
  t={t}
123
122
  goTo={goTo}
124
123
  user={user}
@@ -23,7 +23,7 @@ class OperatorService extends BaseService {
23
23
 
24
24
  getForm(scope = "create", language = "en") {
25
25
  return this.apiGet({
26
- url: `/forms/${namespaceEnums["operators"]}`,
26
+ url: `/forms/stakeholder`,
27
27
  isApp: true,
28
28
  params: { scope, language },
29
29
  });