-
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.
Add validation workflow to local units
- feat(local-units): add delete modal and refine permissions - Add delete modal in Local Units Form and Local Units Table - Separate delete and validate permissions for local units - Simplify delete permission logic
- Loading branch information
1 parent
15a6735
commit 3258b96
Showing
37 changed files
with
2,818 additions
and
978 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
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.
Oops, something went wrong.