Skip to content

Commit

Permalink
WRS-2133 - session store selected user interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-mereuta committed Nov 29, 2024
1 parent 78f8c34 commit a84343c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/navbar/navbarItems/useUserInterfaceSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AvailableIcons, DropDown } from '@chili-publish/grafx-shared-components';
import { useMemo } from 'react';
import { SESSION_USER_INTEFACE_ID_KEY } from '../../../utils/constants';
import { getDataIdForSUI, getDataTestIdForSUI } from '../../../utils/dataIds';
import { useUiConfigContext } from '../../../contexts/UiConfigContext';

Expand All @@ -10,7 +11,12 @@ const useUserInterfaceSelector = () => {
() => userInterfaces.map((item) => ({ label: item.name, value: item.id })),
[userInterfaces],
);
const selectedUserInterface = selectedUserInterfaceId || userInterfaces.find((item) => item.default)?.id;
const validUserInterfaceForTemplate = userInterfaces.find(
(item) => item.id === sessionStorage.getItem(SESSION_USER_INTEFACE_ID_KEY),
)?.id;

const selectedUserInterface =
validUserInterfaceForTemplate || selectedUserInterfaceId || userInterfaces.find((item) => item.default)?.id;

const navbarItem = useMemo(
() => ({
Expand All @@ -21,7 +27,10 @@ const useUserInterfaceSelector = () => {
dataTestId={getDataTestIdForSUI('dropdown-user-interface')}
options={options}
value={options.find((op) => op.value === selectedUserInterface)}
onChange={(option) => onUserInterfaceChange(option?.value as unknown as string)}
onChange={(option) => {
onUserInterfaceChange(option?.value as unknown as string);
sessionStorage.setItem(SESSION_USER_INTEFACE_ID_KEY, option?.value as string);
}}
noDropDownIcon
controlShouldRenderValue={false}
placeholderIcon={AvailableIcons.faTableLayout}
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const APP_WRAPPER_ID = 'studio-ui-application';
export const SESSION_USER_INTEFACE_ID_KEY = 'userInterfaceId';

0 comments on commit a84343c

Please sign in to comment.