datastake-daf 0.6.351 → 0.6.352

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.
@@ -55628,6 +55628,7 @@ const getNameByLevel = (data, level) => {
55628
55628
  const entry = Object.values(data || {}).find(item => item.level === level);
55629
55629
  return entry;
55630
55630
  };
55631
+
55631
55632
  const getColumns$3 = ({
55632
55633
  t,
55633
55634
  goTo = () => {},
@@ -56261,6 +56262,21 @@ function LocationTable(_ref) {
56261
56262
  });
56262
56263
  }
56263
56264
 
56265
+ const mapToSelectOptions = (items, valueKey, selectOptions, optionKey, customMapper = null) => {
56266
+ return items.map(item => {
56267
+ if (customMapper) {
56268
+ return customMapper(item);
56269
+ }
56270
+ const value = item?.[valueKey] || "-";
56271
+ const optionsList = selectOptions?.[optionKey] || [];
56272
+ const foundOption = optionsList.find(option => option.value === value);
56273
+ return {
56274
+ label: foundOption?.label || value,
56275
+ value: value
56276
+ };
56277
+ }).filter((option, index, self) => index === self.findIndex(o => o.value === option.value));
56278
+ };
56279
+
56264
56280
  const getColumns$1 = ({
56265
56281
  t,
56266
56282
  selectOptions,
@@ -56443,12 +56459,7 @@ function CombineSubjectsModal({
56443
56459
  className: "flex-1",
56444
56460
  name: "id",
56445
56461
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
56446
- options: selectedSubjects.map(subject => {
56447
- return {
56448
- label: location?.datastakeId || "-",
56449
- value: location?.datastakeId || "-"
56450
- };
56451
- }),
56462
+ options: mapToSelectOptions(selectedSubjects, "datastakeId", selectOptions, null),
56452
56463
  placeholder: t("ID")
56453
56464
  })
56454
56465
  }), /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
@@ -56461,24 +56472,14 @@ function CombineSubjectsModal({
56461
56472
  className: "flex-1",
56462
56473
  name: "category",
56463
56474
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
56464
- options: selectedSubjects.map(location => {
56465
- return {
56466
- label: (selectOptions?.category || []).find(option => option.value === location?.category)?.label || location?.category || "-",
56467
- value: location?.category || "-"
56468
- };
56469
- }).filter((option, index, self) => index === self.findIndex(o => o.value === option.value)),
56475
+ options: mapToSelectOptions(selectedSubjects, "category", selectOptions, "category"),
56470
56476
  placeholder: t("Category")
56471
56477
  })
56472
56478
  }), /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
56473
56479
  className: "flex-1",
56474
56480
  name: "country",
56475
56481
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
56476
- options: selectedSubjects.map(location => {
56477
- return {
56478
- label: (selectOptions?.country || []).find(option => option.value === location?.country)?.label || location?.country || "-",
56479
- value: location?.country || "-"
56480
- };
56481
- }).filter((option, index, self) => index === self.findIndex(o => o.value === option.value)),
56482
+ options: mapToSelectOptions(selectedSubjects, "country", selectOptions, "country"),
56482
56483
  placeholder: t("admin::country")
56483
56484
  })
56484
56485
  }), entity.includes("locations") && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
@@ -56487,26 +56488,26 @@ function CombineSubjectsModal({
56487
56488
  name: "administrativeLevel1",
56488
56489
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
56489
56490
  placeholder: t("Province"),
56490
- options: selectedSubjects.map(location => {
56491
- const _data = getNameByLevel(location?.linking?.SCL, "level_1");
56491
+ options: mapToSelectOptions(selectedSubjects, null, selectOptions, null, subject => {
56492
+ const _data = getNameByLevel(subject?.linking?.SCL, "level_1");
56492
56493
  return {
56493
56494
  label: _data?.name || "-",
56494
56495
  value: _data?.id || "-"
56495
56496
  };
56496
- }).filter((option, index, self) => index === self.findIndex(o => o.value === option.value))
56497
+ })
56497
56498
  })
56498
56499
  }), /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
56499
56500
  className: "flex-1",
56500
56501
  name: "administrativeLevel2",
56501
56502
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
56502
56503
  placeholder: t("Territory"),
56503
- options: selectedSubjects.map(location => {
56504
- const _data = getNameByLevel(location?.linking?.SCL, "level_2");
56504
+ options: mapToSelectOptions(selectedSubjects, null, selectOptions, null, subject => {
56505
+ const _data = getNameByLevel(subject?.linking?.SCL, "level_2");
56505
56506
  return {
56506
56507
  label: _data?.name || "-",
56507
56508
  value: _data?.id || "-"
56508
56509
  };
56509
- }).filter((option, index, self) => index === self.findIndex(o => o.value === option.value))
56510
+ })
56510
56511
  })
56511
56512
  })]
56512
56513
  })]
@@ -56545,7 +56546,7 @@ function SubjectsTable(_ref) {
56545
56546
  const {
56546
56547
  token
56547
56548
  } = useToken();
56548
- const [combineLocationVisible, setCombineLocationVisible] = React.useState(false);
56549
+ const [isCombineModalOpen, setIsModalOpen] = React.useState(false);
56549
56550
  const {
56550
56551
  filter,
56551
56552
  activeTab,
@@ -56598,7 +56599,7 @@ function SubjectsTable(_ref) {
56598
56599
  headerTitle: headerTitle,
56599
56600
  actionButton: [{
56600
56601
  icon: "Merge",
56601
- onClick: () => setCombineLocationVisible(true),
56602
+ onClick: () => setIsModalOpen(true),
56602
56603
  tooltip: t("admin::merge-subjects"),
56603
56604
  disabled: selectedSubjects.length < 2
56604
56605
  }],
@@ -56652,13 +56653,13 @@ function SubjectsTable(_ref) {
56652
56653
  onChange: filter.onTableChange
56653
56654
  })]
56654
56655
  }), /*#__PURE__*/jsxRuntime.jsx(CombineSubjectsModal, {
56655
- isOpen: combineLocationVisible,
56656
+ isOpen: isCombineModalOpen,
56656
56657
  t: t,
56657
56658
  onClose: () => {
56658
- setCombineLocationVisible(false);
56659
+ setIsModalOpen(false);
56659
56660
  },
56660
56661
  onSuccess: data => {
56661
- setCombineLocationVisible(false);
56662
+ setIsModalOpen(false);
56662
56663
  setLoading(true);
56663
56664
  if (typeof mergeSubjectsFunction === 'function') {
56664
56665
  mergeSubjectsFunction(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.351",
3
+ "version": "0.6.352",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -0,0 +1,79 @@
1
+ import { findOptions } from "../../../../../../../helpers/StringHelper.js";
2
+ import { Tooltip } from "antd";
3
+ import { getNameByLevel } from "../../AdminTables/SubjectsTable/helper.js";
4
+
5
+ export const getColumns = ({ t, selectOptions, module, entity }) => {
6
+ return [
7
+ {
8
+ title: t("admin::organisation_id"),
9
+ dataIndex: "datastakeId",
10
+ key: "datastakeId",
11
+ show: true,
12
+ render: (value, all) => {
13
+ return <Tooltip title={value}>{value}</Tooltip>;
14
+ },
15
+ },
16
+ {
17
+ title: t("Name"),
18
+ dataIndex: "name",
19
+ key: "name",
20
+ show: true,
21
+ render: (value, all) => {
22
+ return <Tooltip title={value}>{value}</Tooltip>;
23
+ },
24
+ },
25
+ {
26
+ title: t("Category"),
27
+ dataIndex: "category",
28
+ key: "category",
29
+ show: true,
30
+ render: (value, all) => {
31
+ const label = findOptions(value, selectOptions?.category);
32
+ return <Tooltip title={label}>{label}</Tooltip>;
33
+ },
34
+ },
35
+ {
36
+ title: t("Country"),
37
+ dataIndex: "country",
38
+ key: "country",
39
+ show: true,
40
+ render: (value, all) => {
41
+ const label = findOptions(value, selectOptions?.country);
42
+ return <Tooltip title={label}>{label}</Tooltip>;
43
+ },
44
+ },
45
+ {
46
+ title: t("Province"),
47
+ dataIndex: "administrativeLevel1",
48
+ key: "administrativeLevel1",
49
+ ellipsis: true,
50
+ show: entity.includes("locations"),
51
+ render: (value, all) => {
52
+ let label;
53
+ if(all?.administrativeLevel1 && value === all?.administrativeLevel1) {
54
+ label = all?.linking?.SCL?.[value]?.name
55
+ } else {
56
+ label = getNameByLevel(all?.linking?.SCL, "level_1")?.name
57
+ }
58
+
59
+ return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
60
+ },
61
+ },
62
+ {
63
+ title: t("Territory"),
64
+ dataIndex: "administrativeLevel2",
65
+ key: "administrativeLevel2",
66
+ show: entity.includes("locations"),
67
+ render: (value, all) => {
68
+ let label;
69
+ if(all?.administrativeLevel2 && value === all?.administrativeLevel2) {
70
+ label = all?.linking?.SCL?.[value]?.name
71
+ } else {
72
+ label = getNameByLevel(all?.linking?.SCL, "level_2")?.name
73
+ }
74
+
75
+ return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
76
+ },
77
+ },
78
+ ].filter((c) => c?.show);
79
+ };
@@ -1,79 +1,21 @@
1
- import { findOptions } from "../../../../../../../helpers/StringHelper.js";
2
- import { Tooltip } from "antd";
3
- import { getNameByLevel } from "../../AdminTables/SubjectsTable/helper.js";
4
-
5
- export const getColumns = ({ t, selectOptions, module, entity }) => {
6
- return [
7
- {
8
- title: t("admin::organisation_id"),
9
- dataIndex: "datastakeId",
10
- key: "datastakeId",
11
- show: true,
12
- render: (value, all) => {
13
- return <Tooltip title={value}>{value}</Tooltip>;
14
- },
15
- },
16
- {
17
- title: t("Name"),
18
- dataIndex: "name",
19
- key: "name",
20
- show: true,
21
- render: (value, all) => {
22
- return <Tooltip title={value}>{value}</Tooltip>;
23
- },
24
- },
25
- {
26
- title: t("Category"),
27
- dataIndex: "category",
28
- key: "category",
29
- show: true,
30
- render: (value, all) => {
31
- const label = findOptions(value, selectOptions?.category);
32
- return <Tooltip title={label}>{label}</Tooltip>;
33
- },
34
- },
35
- {
36
- title: t("Country"),
37
- dataIndex: "country",
38
- key: "country",
39
- show: true,
40
- render: (value, all) => {
41
- const label = findOptions(value, selectOptions?.country);
42
- return <Tooltip title={label}>{label}</Tooltip>;
43
- },
44
- },
45
- {
46
- title: t("Province"),
47
- dataIndex: "administrativeLevel1",
48
- key: "administrativeLevel1",
49
- ellipsis: true,
50
- show: entity.includes("locations"),
51
- render: (value, all) => {
52
- let label;
53
- if(all?.administrativeLevel1 && value === all?.administrativeLevel1) {
54
- label = all?.linking?.SCL?.[value]?.name
55
- } else {
56
- label = getNameByLevel(all?.linking?.SCL, "level_1")?.name
57
- }
58
-
59
- return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
60
- },
61
- },
62
- {
63
- title: t("Territory"),
64
- dataIndex: "administrativeLevel2",
65
- key: "administrativeLevel2",
66
- show: entity.includes("locations"),
67
- render: (value, all) => {
68
- let label;
69
- if(all?.administrativeLevel2 && value === all?.administrativeLevel2) {
70
- label = all?.linking?.SCL?.[value]?.name
71
- } else {
72
- label = getNameByLevel(all?.linking?.SCL, "level_2")?.name
73
- }
74
-
75
- return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
76
- },
77
- },
78
- ].filter((c) => c?.show);
1
+ export const mapToSelectOptions = (items, valueKey, selectOptions, optionKey, customMapper = null) => {
2
+ return items
3
+ .map((item) => {
4
+ if (customMapper) {
5
+ return customMapper(item);
6
+ }
7
+
8
+ const value = item?.[valueKey] || "-";
9
+ const optionsList = selectOptions?.[optionKey] || [];
10
+ const foundOption = optionsList.find((option) => option.value === value);
11
+
12
+ return {
13
+ label: foundOption?.label || value,
14
+ value: value,
15
+ };
16
+ })
17
+ .filter(
18
+ (option, index, self) =>
19
+ index === self.findIndex((o) => o.value === option.value),
20
+ );
79
21
  };
@@ -4,7 +4,8 @@ import { Container } from "../CombineModalStyle.js";
4
4
  import { findOptions } from "../../../../../../../helpers/StringHelper.js";
5
5
  import DAFTable from "../../../../Table/index.jsx";
6
6
  import { useMemo, useState } from "react";
7
- import { getColumns } from "./helper.js";
7
+ import { mapToSelectOptions } from "./helper.js";
8
+ import { getColumns } from "./columns.js";
8
9
  import { getNameByLevel } from "../../AdminTables/SubjectsTable/helper.js";
9
10
 
10
11
  const { useToken } = theme;
@@ -111,12 +112,7 @@ export default function CombineSubjectsModal({
111
112
  >
112
113
  <Form.Item className="flex-1" name="id">
113
114
  <Select
114
- options={selectedSubjects.map((subject) => {
115
- return {
116
- label: location?.datastakeId || "-",
117
- value: location?.datastakeId || "-",
118
- };
119
- })}
115
+ options={mapToSelectOptions(selectedSubjects, "datastakeId", selectOptions, null)}
120
116
  placeholder={t("ID")}
121
117
  ></Select>
122
118
  </Form.Item>
@@ -127,44 +123,14 @@ export default function CombineSubjectsModal({
127
123
 
128
124
  <Form.Item className="flex-1" name="category">
129
125
  <Select
130
- options={selectedSubjects
131
- .map((location) => {
132
- return {
133
- label:
134
- (selectOptions?.category || []).find(
135
- (option) => option.value === location?.category,
136
- )?.label ||
137
- location?.category ||
138
- "-",
139
- value: location?.category || "-",
140
- };
141
- })
142
- .filter(
143
- (option, index, self) =>
144
- index === self.findIndex((o) => o.value === option.value),
145
- )}
126
+ options={mapToSelectOptions(selectedSubjects, "category", selectOptions, "category")}
146
127
  placeholder={t("Category")}
147
128
  ></Select>
148
129
  </Form.Item>
149
130
 
150
131
  <Form.Item className="flex-1" name="country">
151
132
  <Select
152
- options={selectedSubjects
153
- .map((location) => {
154
- return {
155
- label:
156
- (selectOptions?.country || []).find(
157
- (option) => option.value === location?.country,
158
- )?.label ||
159
- location?.country ||
160
- "-",
161
- value: location?.country || "-",
162
- };
163
- })
164
- .filter(
165
- (option, index, self) =>
166
- index === self.findIndex((o) => o.value === option.value),
167
- )}
133
+ options={mapToSelectOptions(selectedSubjects, "country", selectOptions, "country")}
168
134
  placeholder={t("admin::country")}
169
135
  ></Select>
170
136
  </Form.Item>
@@ -174,36 +140,26 @@ export default function CombineSubjectsModal({
174
140
  <Form.Item className="flex-1" name="administrativeLevel1">
175
141
  <Select
176
142
  placeholder={t("Province")}
177
- options={selectedSubjects
178
- .map((location) => {
179
- const _data = getNameByLevel(location?.linking?.SCL, "level_1");
143
+ options={mapToSelectOptions(selectedSubjects, null, selectOptions, null, (subject) => {
144
+ const _data = getNameByLevel(subject?.linking?.SCL, "level_1");
180
145
  return {
181
146
  label: _data?.name || "-",
182
147
  value: _data?.id || "-",
183
148
  };
184
- })
185
- .filter(
186
- (option, index, self) =>
187
- index === self.findIndex((o) => o.value === option.value),
188
- )}
149
+ })}
189
150
  />
190
151
  </Form.Item>
191
152
 
192
153
  <Form.Item className="flex-1" name="administrativeLevel2">
193
154
  <Select
194
155
  placeholder={t("Territory")}
195
- options={selectedSubjects
196
- .map((location) => {
197
- const _data = getNameByLevel(location?.linking?.SCL, "level_2");
156
+ options={mapToSelectOptions(selectedSubjects, null, selectOptions, null, (subject) => {
157
+ const _data = getNameByLevel(subject?.linking?.SCL, "level_2");
198
158
  return {
199
159
  label: _data?.name || "-",
200
160
  value: _data?.id || "-",
201
161
  };
202
- })
203
- .filter(
204
- (option, index, self) =>
205
- index === self.findIndex((o) => o.value === option.value),
206
- )}
162
+ })}
207
163
  />
208
164
  </Form.Item>
209
165
  </>
@@ -10,8 +10,8 @@ import {
10
10
  filtersConfig,
11
11
  defaultUrlParams,
12
12
  checkboxConfig,
13
- getColumns,
14
13
  } from "../SubjectsTable/helper.js";
14
+ import { getColumns } from "../SubjectsTable/columns.js";
15
15
  import CombineLocationModal from "../../AdminModals/CombineLocation/index.jsx";
16
16
  const { useToken } = theme;
17
17
 
@@ -0,0 +1,224 @@
1
+ import { Checkbox, Tooltip, Avatar } from "antd";
2
+ import CustomIcon from "../../../../Icon/CustomIcon.jsx";
3
+ import { findOptions } from "../../../../../../../helpers/StringHelper.js";
4
+ import { getNameByLevel } from "./helper.js";
5
+
6
+ export const getColumns = ({
7
+ t,
8
+ goTo = () => {},
9
+ show = "show",
10
+ getRedirectLink = () => {},
11
+ token,
12
+ selectedSubjects,
13
+ setSelectedSubjects,
14
+ selectOptions,
15
+ entity,
16
+ }) => {
17
+ const cols = [
18
+ {
19
+ title: "",
20
+ dataIndex: "select",
21
+ key: "select",
22
+ width: 50,
23
+ show: true,
24
+ render: (v, all) => {
25
+ if (all.empty) {
26
+ return <div className="daf-default-cell" />;
27
+ }
28
+ return (
29
+ <Checkbox
30
+ onChange={() =>
31
+ setSelectedSubjects((prev) => {
32
+ const isSelected = prev.some((p) => p.id === all.id);
33
+ if (isSelected) {
34
+ return prev.filter((p) => p.id !== all.id);
35
+ }
36
+ return [...prev, all];
37
+ })
38
+ }
39
+ checked={selectedSubjects.some((p) => p.id === all.id)}
40
+ disabled={
41
+ selectedSubjects?.length >= 3 &&
42
+ !selectedSubjects.some((p) => p.id === all.id)
43
+ }
44
+ />
45
+ );
46
+ },
47
+ },
48
+ {
49
+ title: t("ID"),
50
+ dataIndex: "datastakeId",
51
+ key: "datastakeId",
52
+ ellipsis: true,
53
+ show: true,
54
+ render: (value, all) => {
55
+ if (all.empty) {
56
+ return <div className="daf-default-cell" />;
57
+ }
58
+
59
+ return <Tooltip title={value}>{value}</Tooltip>;
60
+ },
61
+ },
62
+ {
63
+ title: t("Name"),
64
+ dataIndex: "name",
65
+ key: "name",
66
+ ellipsis: true,
67
+ show: true,
68
+ render: (value, all) => {
69
+ if (all.empty) {
70
+ return <div className="daf-default-cell" />;
71
+ }
72
+
73
+ return <Tooltip title={value}>{value}</Tooltip>;
74
+ },
75
+ },
76
+ {
77
+ title: t("Category"),
78
+ dataIndex: "category",
79
+ key: "category",
80
+ ellipsis: true,
81
+ show: true,
82
+ render: (value, all) => {
83
+ if (all.empty) {
84
+ return <div className="daf-default-cell" />;
85
+ }
86
+
87
+ const category = findOptions(value, selectOptions?.category || []) || "--";
88
+
89
+ return <Tooltip title={category}>{category}</Tooltip>;
90
+ },
91
+ },
92
+ {
93
+ title: t("Country"),
94
+ dataIndex: "country",
95
+ key: "country",
96
+ ellipsis: true,
97
+ show: true,
98
+ render: (value, all) => {
99
+ if (all.empty) {
100
+ return <div className="daf-default-cell" />;
101
+ }
102
+ const country = findOptions(value, selectOptions?.country || []) || "--";
103
+
104
+ return <Tooltip title={country}>{country}</Tooltip>;
105
+ },
106
+ },
107
+ {
108
+ title: t("Province"),
109
+ dataIndex: "administrativeLevel1",
110
+ key: "administrativeLevel1",
111
+ ellipsis: true,
112
+ show: entity.includes("locations"),
113
+ render: (value, all) => {
114
+ if (all.empty) {
115
+ return <div className="daf-default-cell" />;
116
+ }
117
+
118
+ let label;
119
+ if(all?.administrativeLevel1 && value === all?.administrativeLevel1) {
120
+ label = all?.linking?.SCL?.[value]?.name
121
+ } else {
122
+ label = getNameByLevel(all?.linking?.SCL, "level_1")?.name
123
+ }
124
+
125
+ return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
126
+ },
127
+ },
128
+ {
129
+ title: t("Territory"),
130
+ dataIndex: "administrativeLevel2",
131
+ key: "administrativeLevel2",
132
+ show: entity.includes("locations"),
133
+ ellipsis: true,
134
+ render: (value, all) => {
135
+ if (all.empty) {
136
+ return <div className="daf-default-cell" />;
137
+ }
138
+
139
+ let label;
140
+ if(all?.administrativeLevel2 && value === all?.administrativeLevel2) {
141
+ label = all?.linking?.SCL?.[value]?.name
142
+ } else {
143
+ label = getNameByLevel(all?.linking?.SCL, "level_2")?.name
144
+ }
145
+
146
+ return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
147
+ },
148
+ },
149
+ {
150
+ title: t("Sources"),
151
+ dataIndex: "sources",
152
+ key: "sources",
153
+ show: true,
154
+ render: (value, all) => {
155
+ if (all.empty) {
156
+ return <div className="daf-default-cell" />;
157
+ }
158
+
159
+ const MAX_SOURCES = 3;
160
+ const count = value?.length === MAX_SOURCES + 1 ? value?.length : MAX_SOURCES;
161
+ return (
162
+ Array.isArray(value) && value?.length > 0 ? <Avatar.Group
163
+ max={{
164
+ count: count,
165
+ style: {
166
+ color: token.baseGray90,
167
+ backgroundColor: token.baseGray20,
168
+ border: `1px solid ${token.baseGray40}`,
169
+ },
170
+ }}
171
+ size={"small"}
172
+ >
173
+ {value.map((v, i) => (
174
+ <Avatar
175
+ key={i}
176
+ size={"small"}
177
+ style={{
178
+ backgroundColor: token.baseGray20,
179
+ color: token.baseGray90,
180
+ border: `1px solid ${token.baseGray40}`,
181
+ display: "flex",
182
+ alignItems: "center",
183
+ justifyContent: "center",
184
+ }}
185
+ >
186
+ <CustomIcon
187
+ name="Organisation02"
188
+ width={18}
189
+ height={18}
190
+ color={token.baseGray90}
191
+ />
192
+ </Avatar>
193
+ ))}
194
+ </Avatar.Group> : '-'
195
+ );
196
+ },
197
+ },
198
+ {
199
+ title: "",
200
+ dataIndex: "actions",
201
+ key: "actions",
202
+ width: 60,
203
+ show: true,
204
+ render: (value, all) => {
205
+ if (all.empty) {
206
+ return <div className="daf-default-cell" />;
207
+ }
208
+
209
+ return (
210
+ <div
211
+ className="cursor-pointer"
212
+ onClick={() => {
213
+ goTo(getRedirectLink(`/app/accounts/view/${all.id}/details`));
214
+ }}
215
+ >
216
+ <CustomIcon name="Link" width={18} height={18} />
217
+ </div>
218
+ );
219
+ },
220
+ },
221
+ ];
222
+
223
+ return cols.filter((c) => c[show]);
224
+ };
@@ -1,9 +1,3 @@
1
- import { Checkbox, Tooltip, Avatar } from "antd";
2
- import CustomIcon from "../../../../Icon/CustomIcon.jsx";
3
- import { findOptions } from "../../../../../../../helpers/StringHelper.js";
4
-
5
- export const view = "locations";
6
-
7
1
  export const getTabs = ({ t }) => {
8
2
  return [
9
3
  {
@@ -68,222 +62,4 @@ export const getNameByLevel = (data, level) => {
68
62
  return entry;
69
63
  }
70
64
 
71
- export const getColumns = ({
72
- t,
73
- goTo = () => {},
74
- show = "show",
75
- getRedirectLink = () => {},
76
- token,
77
- selectedSubjects,
78
- setSelectedSubjects,
79
- selectOptions,
80
- entity,
81
- }) => {
82
- const cols = [
83
- {
84
- title: "",
85
- dataIndex: "select",
86
- key: "select",
87
- width: 50,
88
- show: true,
89
- render: (v, all) => {
90
- if (all.empty) {
91
- return <div className="daf-default-cell" />;
92
- }
93
- return (
94
- <Checkbox
95
- onChange={() =>
96
- setSelectedSubjects((prev) => {
97
- const isSelected = prev.some((p) => p.id === all.id);
98
- if (isSelected) {
99
- return prev.filter((p) => p.id !== all.id);
100
- }
101
- return [...prev, all];
102
- })
103
- }
104
- checked={selectedSubjects.some((p) => p.id === all.id)}
105
- disabled={
106
- selectedSubjects?.length >= 3 &&
107
- !selectedSubjects.some((p) => p.id === all.id)
108
- }
109
- />
110
- );
111
- },
112
- },
113
- {
114
- title: t("ID"),
115
- dataIndex: "datastakeId",
116
- key: "datastakeId",
117
- ellipsis: true,
118
- show: true,
119
- render: (value, all) => {
120
- if (all.empty) {
121
- return <div className="daf-default-cell" />;
122
- }
123
65
 
124
- return <Tooltip title={value}>{value}</Tooltip>;
125
- },
126
- },
127
- {
128
- title: t("Name"),
129
- dataIndex: "name",
130
- key: "name",
131
- ellipsis: true,
132
- show: true,
133
- render: (value, all) => {
134
- if (all.empty) {
135
- return <div className="daf-default-cell" />;
136
- }
137
-
138
- return <Tooltip title={value}>{value}</Tooltip>;
139
- },
140
- },
141
- {
142
- title: t("Category"),
143
- dataIndex: "category",
144
- key: "category",
145
- ellipsis: true,
146
- show: true,
147
- render: (value, all) => {
148
- if (all.empty) {
149
- return <div className="daf-default-cell" />;
150
- }
151
-
152
- const category = findOptions(value, selectOptions?.category || []) || "--";
153
-
154
- return <Tooltip title={category}>{category}</Tooltip>;
155
- },
156
- },
157
- {
158
- title: t("Country"),
159
- dataIndex: "country",
160
- key: "country",
161
- ellipsis: true,
162
- show: true,
163
- render: (value, all) => {
164
- if (all.empty) {
165
- return <div className="daf-default-cell" />;
166
- }
167
- const country = findOptions(value, selectOptions?.country || []) || "--";
168
-
169
- return <Tooltip title={country}>{country}</Tooltip>;
170
- },
171
- },
172
- {
173
- title: t("Province"),
174
- dataIndex: "administrativeLevel1",
175
- key: "administrativeLevel1",
176
- ellipsis: true,
177
- show: entity.includes("locations"),
178
- render: (value, all) => {
179
- if (all.empty) {
180
- return <div className="daf-default-cell" />;
181
- }
182
-
183
- let label;
184
- if(all?.administrativeLevel1 && value === all?.administrativeLevel1) {
185
- label = all?.linking?.SCL?.[value]?.name
186
- } else {
187
- label = getNameByLevel(all?.linking?.SCL, "level_1")?.name
188
- }
189
-
190
- return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
191
- },
192
- },
193
- {
194
- title: t("Territory"),
195
- dataIndex: "administrativeLevel2",
196
- key: "administrativeLevel2",
197
- show: entity.includes("locations"),
198
- ellipsis: true,
199
- render: (value, all) => {
200
- if (all.empty) {
201
- return <div className="daf-default-cell" />;
202
- }
203
-
204
- let label;
205
- if(all?.administrativeLevel2 && value === all?.administrativeLevel2) {
206
- label = all?.linking?.SCL?.[value]?.name
207
- } else {
208
- label = getNameByLevel(all?.linking?.SCL, "level_2")?.name
209
- }
210
-
211
- return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
212
- },
213
- },
214
- {
215
- title: t("Sources"),
216
- dataIndex: "sources",
217
- key: "sources",
218
- show: true,
219
- render: (value, all) => {
220
- if (all.empty) {
221
- return <div className="daf-default-cell" />;
222
- }
223
-
224
- const MAX_SOURCES = 3;
225
- const count = value?.length === MAX_SOURCES + 1 ? value?.length : MAX_SOURCES;
226
- return (
227
- Array.isArray(value) && value?.length > 0 ? <Avatar.Group
228
- max={{
229
- count: count,
230
- style: {
231
- color: token.baseGray90,
232
- backgroundColor: token.baseGray20,
233
- border: `1px solid ${token.baseGray40}`,
234
- },
235
- }}
236
- size={"small"}
237
- >
238
- {value.map((v, i) => (
239
- <Avatar
240
- key={i}
241
- size={"small"}
242
- style={{
243
- backgroundColor: token.baseGray20,
244
- color: token.baseGray90,
245
- border: `1px solid ${token.baseGray40}`,
246
- display: "flex",
247
- alignItems: "center",
248
- justifyContent: "center",
249
- }}
250
- >
251
- <CustomIcon
252
- name="Organisation02"
253
- width={18}
254
- height={18}
255
- color={token.baseGray90}
256
- />
257
- </Avatar>
258
- ))}
259
- </Avatar.Group> : '-'
260
- );
261
- },
262
- },
263
- {
264
- title: "",
265
- dataIndex: "actions",
266
- key: "actions",
267
- width: 60,
268
- show: true,
269
- render: (value, all) => {
270
- if (all.empty) {
271
- return <div className="daf-default-cell" />;
272
- }
273
-
274
- return (
275
- <div
276
- className="cursor-pointer"
277
- onClick={() => {
278
- goTo(getRedirectLink(`/app/accounts/view/${all.id}/details`));
279
- }}
280
- >
281
- <CustomIcon name="Link" width={18} height={18} />
282
- </div>
283
- );
284
- },
285
- },
286
- ];
287
-
288
- return cols.filter((c) => c[show]);
289
- };
@@ -10,8 +10,8 @@ import {
10
10
  filtersConfig,
11
11
  defaultUrlParams,
12
12
  checkboxConfig,
13
- getColumns,
14
13
  } from "./helper.js";
14
+ import { getColumns } from "./columns.js";
15
15
  import CombineSubjectsModal from "../../AdminModals/CombineSubjects/index.jsx";
16
16
 
17
17
  const { useToken } = theme;
@@ -36,7 +36,7 @@ export default function SubjectsTable({
36
36
  const [hasError, setHasError] = useState(false);
37
37
  const [selectedSubjects, setSelectedSubjects] = useState([]);
38
38
  const { token } = useToken();
39
- const [combineLocationVisible, setCombineLocationVisible] = useState(false);
39
+ const [isCombineModalOpen, setIsModalOpen] = useState(false);
40
40
 
41
41
  const {
42
42
  filter,
@@ -94,7 +94,7 @@ export default function SubjectsTable({
94
94
  actionButton={[
95
95
  {
96
96
  icon: "Merge",
97
- onClick: () => setCombineLocationVisible(true),
97
+ onClick: () => setIsModalOpen(true),
98
98
  tooltip: t("admin::merge-subjects"),
99
99
  disabled: selectedSubjects.length < 2,
100
100
  },
@@ -158,13 +158,13 @@ export default function SubjectsTable({
158
158
  </AdminTable>
159
159
 
160
160
  <CombineSubjectsModal
161
- isOpen={combineLocationVisible}
161
+ isOpen={isCombineModalOpen}
162
162
  t={t}
163
163
  onClose={() => {
164
- setCombineLocationVisible(false);
164
+ setIsModalOpen(false);
165
165
  }}
166
166
  onSuccess={(data) => {
167
- setCombineLocationVisible(false);
167
+ setIsModalOpen(false);
168
168
  setLoading(true);
169
169
  if (typeof mergeSubjectsFunction === 'function') {
170
170
  mergeSubjectsFunction(data);