Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom roles in ACL policy #729

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -864,8 +865,7 @@
"DETAILS": "Details"
},
"ROLES": {
"LABEL": "Select a role",
"EMPTY": "No role found"
"LABEL": "Select or create a role"
}
},
"COMMENTS": {
Expand Down
Loading