Skip to content

Commit

Permalink
refactor: remove uiconfig options that are available in UiConfiContex…
Browse files Browse the repository at this point in the history
…t from redux
  • Loading branch information
mikaelrss committed Dec 5, 2023
1 parent 62e2d50 commit babad1b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 33 deletions.
8 changes: 1 addition & 7 deletions src/components/presentation/NavBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { userEvent } from '@testing-library/user-event';
import mockAxios from 'jest-mock-axios';

import { getFormLayoutStateMock } from 'src/__mocks__/getFormLayoutStateMock';
import { getUiConfigStateMock } from 'src/__mocks__/getUiConfigStateMock';
import { getInitialStateMock } from 'src/__mocks__/initialStateMock';
import { NavBar } from 'src/components/presentation/NavBar';
import { mockWindow } from 'src/test/mockWindow';
Expand Down Expand Up @@ -39,12 +38,7 @@ const render = async ({
renderer: () => <NavBar type={type} />,
reduxState: {
...getInitialStateMock(),
formLayout: getFormLayoutStateMock({
uiConfig: getUiConfigStateMock({
hideCloseButton,
showLanguageSelector,
}),
}),
formLayout: getFormLayoutStateMock({}),
},
initialPage,
queries: {
Expand Down
8 changes: 5 additions & 3 deletions src/components/presentation/Presentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NavBar } from 'src/components/presentation/NavBar';
import classes from 'src/components/presentation/Presentation.module.css';
import { Progress } from 'src/components/presentation/Progress';
import { Footer } from 'src/features/footer/Footer';
import { useUiConfigContext } from 'src/features/form/layout/UiConfigContext';
import { useLaxInstanceData } from 'src/features/instance/InstanceContext';
import { Lang } from 'src/features/language/Lang';
import { useCurrentParty } from 'src/features/party/PartiesProvider';
Expand All @@ -30,7 +31,7 @@ export const PresentationComponent = ({ header, type, children, renderNavBar = t
const party = useCurrentParty();
const instance = useLaxInstanceData();
const userParty = useAppSelector((state) => state.profile.profile?.party);
const { expandedWidth } = useAppSelector((state) => state.formLayout.uiConfig);
const { expandedWidth } = useUiConfigContext();

const realHeader = header || (type === ProcessTaskType.Archived ? <Lang id={'receipt.receipt'} /> : undefined);

Expand Down Expand Up @@ -72,8 +73,9 @@ export const PresentationComponent = ({ header, type, children, renderNavBar = t
};

function ProgressBar({ type }: { type: ProcessTaskType | PresentationType }) {
const showProgressSettings = useAppSelector((state) => state.formLayout.uiConfig.showProgress);
const enabled = type !== ProcessTaskType.Archived && showProgressSettings;
const { showProgress } = useUiConfigContext();

const enabled = type !== ProcessTaskType.Archived && showProgress;

if (!enabled) {
return null;
Expand Down
19 changes: 1 addition & 18 deletions src/features/form/layout/formLayoutSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const initialState: ILayoutState = {
},
pageTriggers: [],
keepScrollPos: undefined,
expandedWidth: false,
excludePageFromPdf: null,
excludeComponentFromPdf: null,
pdfLayoutName: undefined,
Expand Down Expand Up @@ -94,8 +93,6 @@ export const formLayoutSlice = () => {
state.uiConfig.pageOrderConfig.order = order;
}
}
state.uiConfig.showExpandWidthButton = settings?.pages.showExpandWidthButton;
state.uiConfig.expandedWidth = settings?.pages.showExpandWidthButton ? state.uiConfig.expandedWidth : false;

state.uiConfig.pdfLayoutName = settings?.pages.pdfLayoutName;
state.uiConfig.excludeComponentFromPdf = settings?.components?.excludeFromPdf ?? [];
Expand Down Expand Up @@ -187,11 +184,6 @@ export const formLayoutSlice = () => {
state.layouts = { ...state.layouts, ...action.payload };
},
}),
toggleExpandedWidth: mkAction<void>({
reducer: (state) => {
state.uiConfig.expandedWidth = !state.uiConfig.expandedWidth;
},
}),
},
};
});
Expand All @@ -207,17 +199,8 @@ const updateCommonPageSettings = (
'hideCloseButton' | 'showLanguageSelector' | 'showProgress' | 'triggers' | 'autoSaveBehavior'
>,
) => {
const {
hideCloseButton = state.uiConfig.hideCloseButton,
showLanguageSelector = state.uiConfig.showLanguageSelector,
autoSaveBehavior = state.uiConfig.autoSaveBehavior,
showProgress = state.uiConfig.showProgress,
triggers = state.uiConfig.pageTriggers,
} = page;
const { autoSaveBehavior = state.uiConfig.autoSaveBehavior, triggers = state.uiConfig.pageTriggers } = page;

state.uiConfig.hideCloseButton = hideCloseButton;
state.uiConfig.showLanguageSelector = showLanguageSelector;
state.uiConfig.showProgress = showProgress;
state.uiConfig.pageTriggers = triggers;
state.uiConfig.autoSaveBehavior = autoSaveBehavior;
};
5 changes: 0 additions & 5 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ export interface IUiConfig {
excludeComponentFromPdf: string[] | null;
pdfLayoutName?: string;
pageTriggers?: Triggers[];
hideCloseButton?: boolean;
showLanguageSelector?: boolean;
showProgress?: boolean;
showExpandWidthButton?: boolean;
expandedWidth?: boolean;
keepScrollPos?: IComponentScrollPos;
}

Expand Down

0 comments on commit babad1b

Please sign in to comment.