Skip to content

Commit e9cdd4f

Browse files
authored
Merge pull request #1940 from IFRCGo/feature/update-localunit-feature
Update local unit feature
2 parents e81a93a + 7e470bc commit e9cdd4f

File tree

55 files changed

+2918
-285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2918
-285
lines changed

.changeset/bitter-pans-travel.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"go-web-app": minor
3+
---
4+
5+
Update Local Units
6+
7+
- Add option to manage local units externally by types for each country.
8+
- Externally managed local units cannot be edited or removed from the UI
9+
- Add option to bulk upload local units
10+
- Add option to view bulk upload history
11+
- Update permission in local unit
12+
- Fix legend and map icon mismatch
13+
- Add option to show changes while validating a local unit
14+
- Add an additional validation state to reflect validation of changes

.changeset/free-clocks-boil.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ifrc-go/ui": patch
3+
---
4+
5+
- Update `name` prop in Switch component to support number
6+
- Update value of `--go-ui-color-semantic-yellow`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"namespace": "common",
3+
"strings": {
4+
"previousValueLabel":"Previous Value"
5+
}
6+
}

app/src/components/DiffWrapper/index.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
import { useMemo } from 'react';
2+
import { TextOutput } from '@ifrc-go/ui';
3+
import { useTranslation } from '@ifrc-go/ui/hooks';
24
import { isNotDefined } from '@togglecorp/fujs';
35

4-
interface Props<T> {
6+
import i18n from './i18n.json';
7+
import styles from './styles.module.css';
8+
9+
interface Props<VALUE> {
510
diffContainerClassName?: string;
6-
value?: T;
7-
oldValue?: T;
11+
value?: VALUE | undefined;
12+
oldValue?: VALUE | undefined;
813
children: React.ReactNode;
914
enabled: boolean;
1015
showOnlyDiff?: boolean;
16+
showPreviousValue?: boolean;
1117
}
1218

13-
function DiffWrapper<T>(props: Props<T>) {
19+
function DiffWrapper<
20+
VALUE extends string | number | boolean | null
21+
>(
22+
props: Props<VALUE>,
23+
) {
1424
const {
1525
diffContainerClassName,
1626
oldValue,
1727
value,
1828
children,
1929
enabled = false,
2030
showOnlyDiff,
31+
showPreviousValue,
2132
} = props;
2233

34+
const strings = useTranslation(i18n);
35+
2336
const hasChanged = useMemo(() => {
2437
// NOTE: we consider `null` and `undefined` as same for
2538
// this scenario
@@ -45,6 +58,14 @@ function DiffWrapper<T>(props: Props<T>) {
4558
return (
4659
<div className={diffContainerClassName}>
4760
{children}
61+
{showPreviousValue
62+
&& (
63+
<TextOutput
64+
className={styles.previousValue}
65+
label={strings.previousValueLabel}
66+
value={oldValue}
67+
/>
68+
)}
4869
</div>
4970
);
5071
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.previous-value {
2+
color: var(--go-ui-color-gray-70);
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"namespace": "common",
3+
"strings": {
4+
"multiSelectPreviousValueLabel":"Previous Value"
5+
}
6+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { useMemo } from 'react';
2+
import { useTranslation } from '@ifrc-go/ui/hooks';
3+
import { isNotDefined } from '@togglecorp/fujs';
4+
5+
import MultiSelectOutput from '../MultiSelectOutput';
6+
7+
import i18n from './i18n.json';
8+
import styles from './styles.module.css';
9+
10+
interface Props<VALUE, OPTION> {
11+
value: VALUE[] | undefined;
12+
oldValue: VALUE[] | undefined;
13+
options: OPTION[] | undefined;
14+
keySelector: (datum: OPTION) => VALUE;
15+
labelSelector: (datum: OPTION) => React.ReactNode;
16+
diffContainerClassName?: string;
17+
children: React.ReactNode;
18+
enabled: boolean;
19+
showOnlyDiff?: boolean;
20+
showPreviousValue?: boolean;
21+
}
22+
23+
function MultiSelectDiffWrapper<
24+
VALUE extends number | string, OPTION
25+
>(
26+
props: Props<VALUE, OPTION>,
27+
) {
28+
const {
29+
diffContainerClassName,
30+
oldValue,
31+
value,
32+
children,
33+
enabled = false,
34+
showOnlyDiff,
35+
showPreviousValue,
36+
options,
37+
keySelector,
38+
labelSelector,
39+
} = props;
40+
41+
const strings = useTranslation(i18n);
42+
43+
const hasChanged = useMemo(() => {
44+
// NOTE: we consider `null` and `undefined` as same for
45+
// this scenario
46+
if (isNotDefined(oldValue) && isNotDefined(value)) {
47+
return false;
48+
}
49+
50+
return JSON.stringify(oldValue) !== JSON.stringify(value);
51+
}, [oldValue, value]);
52+
53+
if (!enabled) {
54+
return children;
55+
}
56+
57+
if (!hasChanged && showOnlyDiff) {
58+
return null;
59+
}
60+
61+
if (!hasChanged) {
62+
return children;
63+
}
64+
65+
return (
66+
<div className={diffContainerClassName}>
67+
{children}
68+
{showPreviousValue
69+
&& (
70+
<MultiSelectOutput
71+
className={styles.previousValue}
72+
label={strings.multiSelectPreviousValueLabel}
73+
value={oldValue}
74+
options={options}
75+
keySelector={keySelector}
76+
labelSelector={labelSelector}
77+
/>
78+
)}
79+
</div>
80+
);
81+
}
82+
83+
export default MultiSelectDiffWrapper;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.previous-value {
2+
color: var(--go-ui-color-gray-70);
3+
}

app/src/components/MultiSelectOutput/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TextOutput } from '@ifrc-go/ui';
33
import { listToMap } from '@togglecorp/fujs';
44

55
interface Props<VALUE, OPTION> {
6+
className?: string;
67
value: VALUE[] | undefined;
78
options: OPTION[] | undefined;
89
keySelector: (datum: OPTION) => VALUE;
@@ -12,6 +13,7 @@ interface Props<VALUE, OPTION> {
1213

1314
function MultiSelectOutput<VALUE extends string | number, OPTION>(props: Props<VALUE, OPTION>) {
1415
const {
16+
className,
1517
value,
1618
options,
1719
keySelector,
@@ -37,6 +39,7 @@ function MultiSelectOutput<VALUE extends string | number, OPTION>(props: Props<V
3739

3840
return (
3941
<TextOutput
42+
className={className}
4043
label={label}
4144
value={valueLabel}
4245
strongLabel
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"namespace": "common",
3+
"strings": {
4+
"selectPreviousValueLabel":"Previous Value"
5+
}
6+
}

0 commit comments

Comments
 (0)