-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1593 from IFRCGo/project/local-unit-v2
project: Update Local Unit edit, validation, and delete workflow
- Loading branch information
Showing
37 changed files
with
3,522 additions
and
977 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"go-web-app": minor | ||
--- | ||
|
||
Add local unit validation workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useMemo } from 'react'; | ||
import { isNotDefined } from '@togglecorp/fujs'; | ||
|
||
interface Props<T> { | ||
diffContainerClassName?: string; | ||
value?: T; | ||
oldValue?: T; | ||
children: React.ReactNode; | ||
enabled: boolean; | ||
showOnlyDiff?: boolean; | ||
} | ||
|
||
function DiffWrapper<T>(props: Props<T>) { | ||
const { | ||
diffContainerClassName, | ||
oldValue, | ||
value, | ||
children, | ||
enabled = false, | ||
showOnlyDiff, | ||
} = props; | ||
|
||
const hasChanged = useMemo(() => { | ||
// NOTE: we consider `null` and `undefined` as same for | ||
// this scenario | ||
if (isNotDefined(oldValue) && isNotDefined(value)) { | ||
return false; | ||
} | ||
|
||
return JSON.stringify(oldValue) !== JSON.stringify(value); | ||
}, [oldValue, value]); | ||
|
||
if (!enabled) { | ||
return children; | ||
} | ||
|
||
if (!hasChanged && showOnlyDiff) { | ||
return null; | ||
} | ||
|
||
if (!hasChanged) { | ||
return children; | ||
} | ||
|
||
return ( | ||
<div className={diffContainerClassName}> | ||
{children} | ||
</div> | ||
); | ||
} | ||
|
||
export default DiffWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useMemo } from 'react'; | ||
import { TextOutput } from '@ifrc-go/ui'; | ||
import { listToMap } from '@togglecorp/fujs'; | ||
|
||
interface Props<VALUE, OPTION> { | ||
value: VALUE[] | undefined; | ||
options: OPTION[] | undefined; | ||
keySelector: (datum: OPTION) => VALUE; | ||
labelSelector: (datum: OPTION) => React.ReactNode; | ||
label: React.ReactNode; | ||
} | ||
|
||
function MultiSelectOutput<VALUE extends string | number, OPTION>(props: Props<VALUE, OPTION>) { | ||
const { | ||
value, | ||
options, | ||
keySelector, | ||
labelSelector, | ||
label, | ||
} = props; | ||
|
||
const valueMap = useMemo( | ||
() => listToMap(value ?? [], (val) => val, () => true), | ||
[value], | ||
); | ||
|
||
const selectedOptions = useMemo(() => options?.filter( | ||
(option) => valueMap[keySelector(option)], | ||
), [keySelector, options, valueMap]); | ||
|
||
const valueLabel = useMemo( | ||
() => selectedOptions?.map( | ||
(selectedOption) => labelSelector(selectedOption), | ||
).join(', ') ?? '--', | ||
[labelSelector, selectedOptions], | ||
); | ||
|
||
return ( | ||
<TextOutput | ||
label={label} | ||
value={valueLabel} | ||
strongLabel | ||
/> | ||
); | ||
} | ||
|
||
export default MultiSelectOutput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useMemo } from 'react'; | ||
import { TextOutput } from '@ifrc-go/ui'; | ||
import { isDefined } from '@togglecorp/fujs'; | ||
|
||
interface Props<VALUE, OPTION> { | ||
value: VALUE | undefined; | ||
options: OPTION[] | undefined; | ||
keySelector: (datum: OPTION) => VALUE; | ||
labelSelector: (datum: OPTION) => React.ReactNode; | ||
label: React.ReactNode; | ||
} | ||
|
||
function SelectOutput<VALUE, OPTION>(props: Props<VALUE, OPTION>) { | ||
const { | ||
value, | ||
options, | ||
keySelector, | ||
labelSelector, | ||
label, | ||
} = props; | ||
|
||
const selectedOption = useMemo(() => options?.find( | ||
(option) => keySelector(option) === value, | ||
), [options, keySelector, value]); | ||
|
||
const valueLabel = useMemo(() => ( | ||
isDefined(selectedOption) | ||
? labelSelector(selectedOption) | ||
: '--' | ||
), [labelSelector, selectedOption]); | ||
|
||
return ( | ||
<TextOutput | ||
label={label} | ||
value={valueLabel} | ||
strongLabel | ||
/> | ||
); | ||
} | ||
|
||
export default SelectOutput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...c/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/FormGrid/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { _cs } from '@togglecorp/fujs'; | ||
|
||
import styles from './styles.module.css'; | ||
|
||
interface Props { | ||
className?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
function FormGrid(props: Props) { | ||
const { | ||
className, | ||
children, | ||
} = props; | ||
|
||
return ( | ||
<div className={_cs(styles.formGrid, className)}> | ||
{children} | ||
</div> | ||
); | ||
} | ||
|
||
export default FormGrid; |
10 changes: 10 additions & 0 deletions
10
...CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/FormGrid/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* NOTE: this element is portaled */ | ||
.form-grid { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
gap: var(--go-ui-spacing-lg); | ||
|
||
@media screen and (max-width: 60rem) { | ||
grid-template-columns: 1fr; | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
...ryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitDeleteButton/i18n.json
This file was deleted.
Oops, something went wrong.
104 changes: 0 additions & 104 deletions
104
...ryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitDeleteButton/index.tsx
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...tryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitDeleteModal/i18n.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"namespace": "countryNsOverviewContextAndStructure", | ||
"strings": { | ||
"submitLabel": "Submit", | ||
"deleteSuccessMessage": "{localUnitName} has been successfully deleted.", | ||
"deleteFailureMessage": "Unable to delete {localUnitName}. Please try again.", | ||
"chooseDeleteReasonMessage": "Choose the reason to delete local unit.", | ||
"deleteReasonExplanation": "Explain the reason why the local unit is being deleted.", | ||
"deleteLocalUnitHeading": "Are you sure you want to delete \"{localUnitName}\"?" | ||
} | ||
} |
Oops, something went wrong.