Skip to content

Commit

Permalink
Merge pull request #729 from dennis531/custom-roles
Browse files Browse the repository at this point in the history
Custom roles in ACL policy
  • Loading branch information
Arnei authored Jul 12, 2024
2 parents 675dc70 + 6edee86 commit a0ab426
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
57 changes: 36 additions & 21 deletions src/components/shared/DropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
filterBySearch,
formatDropDownOptions,
} from "../../utils/dropDownUtils";
import Select from "react-select";
import Select, { Props } from "react-select";
import CreatableSelect from "react-select/creatable";

/**
* TODO: Ideally, we would remove "type", and just type the "options" array properly.
Expand All @@ -33,6 +34,7 @@ const DropDown = <T,>({
tabIndex = 0,
autoFocus = false,
defaultOpen = false,
creatable = false,
disabled = false,
}: {
value: T
Expand All @@ -45,6 +47,7 @@ const DropDown = <T,>({
tabIndex?: number,
autoFocus?: boolean,
defaultOpen?: boolean,
creatable?: boolean,
disabled?: boolean,
}) => {
const { t } = useTranslation();
Expand All @@ -53,28 +56,40 @@ const DropDown = <T,>({

const style = dropDownStyle(type);

const commonProps: Props = {
tabIndex: tabIndex,
theme: (theme) => (dropDownSpacingTheme(theme)),
styles: style,
defaultMenuIsOpen: defaultOpen,
autoFocus: autoFocus,
isSearchable: true,
value: { value: value, label: text === "" ? placeholder : text },
inputValue: searchText,
options: formatDropDownOptions(
filterBySearch(searchText.toLowerCase(), type, options, t),
type,
required,
t
),
placeholder: placeholder,
onInputChange: (value: string) => setSearch(value),
onChange: (element) => handleChange(element as {value: T, label: string}),
isDisabled: disabled,
};

return (
<Select
tabIndex={tabIndex}
theme={(theme) => (dropDownSpacingTheme(theme))}
styles={style}
defaultMenuIsOpen={defaultOpen}
autoFocus={autoFocus}
isSearchable
value={{ value: value, label: text === "" ? placeholder : text }}
inputValue={searchText}
options={formatDropDownOptions(
filterBySearch(searchText.toLowerCase(), type, options, t),
type,
required,
t
<div>
{creatable ? (
<CreatableSelect
{...commonProps}
/>
) : (
<Select
{...commonProps}
noOptionsMessage={() => t("SELECT_NO_MATCHING_RESULTS")}
/>
)}
placeholder={placeholder}
noOptionsMessage={() => "No matching results."}
onInputChange={(value) => setSearch(value)}
onChange={(element) => handleChange(element as {value: T, label: string} )}
isDisabled={disabled}
/>
</div>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ const ResourceDetailsAccessPolicyTab = ({
}
type={"aclRole"}
required={true}
creatable={true}
handleChange={(element) => {
if (element) {
replace(index, {
Expand All @@ -439,13 +440,7 @@ const ResourceDetailsAccessPolicyTab = ({
}
}}
placeholder={
roles.length > 0
? t(
"EVENTS.EVENTS.DETAILS.ACCESS.ROLES.LABEL"
)
: t(
"EVENTS.EVENTS.DETAILS.ACCESS.ROLES.EMPTY"
)
t("EVENTS.EVENTS.DETAILS.ACCESS.ROLES.LABEL")
}
disabled={
!hasAccess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"RESET": "Reset",
"SELECT_NO_OPTION_SELECTED": "No option selected",
"SELECT_NO_OPTIONS_AVAILABLE": "No options available",
"SELECT_NO_MATCHING_RESULTS": "No matching results.",
"YES": "Yes",
"COPY": "Copy to clipboard",
"UPDATE": {
Expand Down Expand Up @@ -865,8 +866,7 @@
"DETAILS": "Details"
},
"ROLES": {
"LABEL": "Select a role",
"EMPTY": "No role found"
"LABEL": "Select or create a role"
}
},
"COMMENTS": {
Expand Down

0 comments on commit a0ab426

Please sign in to comment.