-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow options to assign many flags (#3820)
- Loading branch information
1 parent
9a9acf0
commit 8c5f127
Showing
13 changed files
with
745 additions
and
291 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
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
87 changes: 87 additions & 0 deletions
87
editor.planx.uk/src/@planx/components/shared/FlagsSelect.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,87 @@ | ||
import { | ||
AutocompleteChangeReason, | ||
AutocompleteProps, | ||
} from "@mui/material/Autocomplete"; | ||
import Chip from "@mui/material/Chip"; | ||
import ListItem from "@mui/material/ListItem"; | ||
import { Flag, flatFlags } from "@opensystemslab/planx-core/types"; | ||
import React, { useMemo } from "react"; | ||
import InputRow from "ui/shared/InputRow"; | ||
import { CustomCheckbox, SelectMultiple } from "ui/shared/SelectMultiple"; | ||
|
||
interface Props { | ||
value?: Array<Flag["value"]>; | ||
onChange: (values: Array<Flag["value"]>) => void; | ||
} | ||
|
||
const renderOptions: AutocompleteProps< | ||
Flag, | ||
true, | ||
true, | ||
false, | ||
"div" | ||
>["renderOption"] = (props, flag, { selected }) => ( | ||
<ListItem {...props}> | ||
<CustomCheckbox | ||
aria-hidden="true" | ||
className={selected ? "selected" : ""} | ||
sx={{ backgroundColor: `${flag.bgColor}` }} | ||
/> | ||
{flag.text} | ||
</ListItem> | ||
); | ||
|
||
const renderTags: AutocompleteProps< | ||
Flag, | ||
true, | ||
true, | ||
false, | ||
"div" | ||
>["renderTags"] = (value, getFlagProps) => | ||
value.map((flag, index) => ( | ||
<Chip | ||
{...getFlagProps({ index })} | ||
key={flag.value} | ||
label={flag.text} | ||
sx={{ backgroundColor: flag.bgColor, color: flag.color }} | ||
/> | ||
)); | ||
|
||
export const FlagsSelect: React.FC<Props> = (props) => { | ||
const { value: initialFlagValues } = props; | ||
|
||
const value: Flag[] | undefined = useMemo( | ||
() => | ||
initialFlagValues?.flatMap((initialFlagValue) => | ||
flatFlags.filter((flag) => flag.value === initialFlagValue), | ||
), | ||
[initialFlagValues], | ||
); | ||
|
||
const handleChange = ( | ||
_event: React.SyntheticEvent, | ||
value: Flag[], | ||
_reason: AutocompleteChangeReason, | ||
) => { | ||
const selectedFlags = value.map((flag) => flag.value); | ||
props.onChange(selectedFlags); | ||
}; | ||
|
||
return ( | ||
<InputRow> | ||
<SelectMultiple | ||
id="select-multiple-flags" | ||
key="select-multiple-flags" | ||
label="Flags (up to one per category)" | ||
options={flatFlags} | ||
getOptionLabel={(flag) => flag.text} | ||
groupBy={(flag) => flag.category} | ||
onChange={handleChange} | ||
isOptionEqualToValue={(flag, value) => flag.value === value.value} | ||
value={value} | ||
renderOption={renderOptions} | ||
renderTags={renderTags} | ||
/> | ||
</InputRow> | ||
); | ||
}; |
40 changes: 0 additions & 40 deletions
40
editor.planx.uk/src/@planx/components/shared/PermissionSelect.tsx
This file was deleted.
Oops, something went wrong.
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
31 changes: 31 additions & 0 deletions
31
editor.planx.uk/src/pages/FlowEditor/components/Flow/components/FlagBand.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,31 @@ | ||
import Box from "@mui/material/Box"; | ||
import { Flag } from "@opensystemslab/planx-core/types"; | ||
import React from "react"; | ||
|
||
export const FlagBand: React.FC<{ | ||
flag: Flag; | ||
}> = ({ flag }) => { | ||
return ( | ||
<Box | ||
sx={(theme) => ({ | ||
backgroundColor: `${flag?.bgColor || theme.palette.grey[800]}`, | ||
borderBottom: `1px solid ${theme.palette.grey[400]}`, | ||
width: "100%", | ||
height: "12px", | ||
})} | ||
/> | ||
); | ||
}; | ||
|
||
export const NoFlagBand: React.FC = () => { | ||
return ( | ||
<Box | ||
sx={(theme) => ({ | ||
backgroundColor: theme.palette.grey[700], | ||
borderBottom: `1px solid ${theme.palette.grey[400]}`, | ||
width: "100%", | ||
height: "12px", | ||
})} | ||
/> | ||
); | ||
} |
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
Oops, something went wrong.