Skip to content

Commit

Permalink
Use generic SelectOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Makarichev committed Mar 17, 2024
1 parent 86a8c88 commit 8a217ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions frontend/src/components/ACLPage/Form/CustomACL/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@ import { RadioOption } from 'components/common/Radio/types';

import { FormValues } from './types';

function toOptionsArray<T extends object, O extends keyof T>(
enumerable: T,
unknown: O
): Array<SelectOption> {
return Object.values(enumerable).reduce<SelectOption[]>((acc, cur) => {
function toOptionsArray<T extends string>(
list: T[],
unknown: T
): SelectOption<T>[] {
return list.reduce<SelectOption<T>[]>((acc, cur) => {
if (cur !== unknown) {
const option: SelectOption = { label: cur, value: cur };
acc.push(option);
acc.push({ label: cur, value: cur });
}

return acc;
}, []);
}

export const resourceTypes: Array<SelectOption> = toOptionsArray(
KafkaAclResourceType,
export const resourceTypes = toOptionsArray(
Object.values(KafkaAclResourceType),
KafkaAclResourceType.UNKNOWN
);

export const operations = toOptionsArray(
KafkaAclOperationEnum,
Object.values(KafkaAclOperationEnum),
KafkaAclOperationEnum.UNKNOWN
);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ACLPage/Form/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const matchTypeOptions: RadioOption[] = [
{ value: MatchType.PREFIXED },
];

export const ACLTypeOptions: SelectOption[] = [
export const ACLTypeOptions: SelectOption<ACLType>[] = [
{ label: 'Custom ACL', value: ACLType.CUSTOM_ACL },
{ label: 'For Consumers', value: ACLType.FOR_CONSUMERS },
{ label: 'For Producers', value: ACLType.FOR_PRODUCERS },
Expand Down

0 comments on commit 8a217ea

Please sign in to comment.