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

Fix for typings in MultiSelection #1

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
7 changes: 6 additions & 1 deletion frontend/src/components/MultiSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
HelperTextItem,
} from '@patternfly/react-core';
import { TimesIcon } from '@patternfly/react-icons/dist/esm/icons/times-icon';
import { SelectionOptions } from '~/pages/groupSettings/groupTypes';

export type SelectionOptions = {
id: number | string;
name: string;
selected?: boolean;
};

type MultiSelectionProps = {
value: SelectionOptions[];
Expand Down
24 changes: 19 additions & 5 deletions frontend/src/pages/groupSettings/GroupSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
import ApplicationsPage from '~/pages/ApplicationsPage';
import { isGroupEmpty } from '~/utilities/utils';
import SettingSection from '~/components/SettingSection';
import { MultiSelection } from '~/components/MultiSelection';
import { MultiSelection, SelectionOptions } from '~/components/MultiSelection';
import { useWatchGroups } from '~/utilities/useWatchGroups';
import { GroupsConfigField, MenuItemStatus } from './groupTypes';
import { GroupsConfigField } from './groupTypes';

const GroupSettings: React.FC = () => {
const {
Expand All @@ -37,13 +37,27 @@ const GroupSettings: React.FC = () => {
updateGroups(groupSettings);
};

const handleMenuItemSelection = (newState: MenuItemStatus[], field: GroupsConfigField) => {
const handleMenuItemSelection = (newState: SelectionOptions[], field: GroupsConfigField) => {
switch (field) {
case GroupsConfigField.ADMIN:
setGroupSettings({ ...groupSettings, adminGroups: newState });
setGroupSettings({
...groupSettings,
adminGroups: newState.map((opt) => ({
id: Number(opt.id),
name: opt.name,
enabled: opt.selected || false,
})),
});
break;
case GroupsConfigField.USER:
setGroupSettings({ ...groupSettings, allowedGroups: newState });
setGroupSettings({
...groupSettings,
allowedGroups: newState.map((opt) => ({
id: Number(opt.id),
name: opt.name,
enabled: opt.selected || false,
})),
});
break;
}
setIsGroupSettingsChanged(true);
Expand Down
12 changes: 0 additions & 12 deletions frontend/src/pages/groupSettings/groupTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,3 @@ export type GroupStatus = {
name: string;
enabled: boolean;
};

export type MenuItemStatus = {
id: number;
name: string;
enabled: boolean;
};

export type SelectionOptions = {
id: number | string;
name: string;
selected?: boolean;
};
Loading