From 738f716e18bb222226451a948b39388ea74bb862 Mon Sep 17 00:00:00 2001 From: jvega190 Date: Wed, 9 Oct 2024 15:33:54 -0600 Subject: [PATCH] [3941] Rollback showOnlyChanges and accordionView from Context as they can't be shared between dialog and slideouts --- .../CompareVersionsDialogContainer.tsx | 18 ++++++------------ .../VersionsDialogContext.tsx | 6 +----- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/ui/app/src/components/CompareVersionsDialog/CompareVersionsDialogContainer.tsx b/ui/app/src/components/CompareVersionsDialog/CompareVersionsDialogContainer.tsx index 1c661abb6d..2cea1acc8c 100644 --- a/ui/app/src/components/CompareVersionsDialog/CompareVersionsDialogContainer.tsx +++ b/ui/app/src/components/CompareVersionsDialog/CompareVersionsDialogContainer.tsx @@ -47,7 +47,6 @@ import { initialFieldViewState, useVersionsDialogContext, VersionsDialogContextP import { ContentTypeField } from '../../models'; import { getCompareVersionDialogViewModes, setCompareVersionDialogViewModes } from '../../utils/state'; import useActiveUser from '../../hooks/useActiveUser'; -import useMount from '../../hooks/useMount'; import TextDiffView from './FieldsTypesDiffViews/TextDiffView'; export function CompareVersionsDialogContainer(props: CompareVersionsDialogContainerProps) { @@ -60,7 +59,7 @@ export function CompareVersionsDialogContainer(props: CompareVersionsDialogConta contentTypesBranch, compareXml } = props; - const [{ fieldsViewState, showOnlyChanges, accordionView }, contextApiRef] = useVersionsDialogContext(); + const [{ fieldsViewState }] = useVersionsDialogContext(); const fieldsViewStateRef = useRef(); fieldsViewStateRef.current = fieldsViewState; const compareVersionsBranch = versionsBranch?.compareVersionsBranch; @@ -68,6 +67,9 @@ export function CompareVersionsDialogContainer(props: CompareVersionsDialogConta const baseUrl = useSelection((state) => state.env.authoringBase); const { formatMessage } = useIntl(); const { username } = useActiveUser(); + const viewModes = getCompareVersionDialogViewModes(username); + const [showOnlyChanges, setShowOnlyChanges] = useState(viewModes?.entireDiff ?? true); + const [accordionView, setAccordionView] = useState(viewModes?.accordionView ?? false); const [selectionContent, setSelectionContent] = useSpreadState<{ a: SelectionContentVersion; b: SelectionContentVersion; @@ -141,14 +143,6 @@ export function CompareVersionsDialogContainer(props: CompareVersionsDialogConta const sidebarRefs = useRef({}); const fieldsRefs = useRef({}); - useMount(() => { - const viewModes = getCompareVersionDialogViewModes(username); - contextApiRef.current.setState({ - showOnlyChanges: viewModes?.entireDiff ?? true, - accordionView: viewModes?.accordionView ?? false - }); - }); - useEffect(() => { if (preFetchedContent) { setSelectionContent(preFetchedContent); @@ -207,12 +201,12 @@ export function CompareVersionsDialogContainer(props: CompareVersionsDialogConta }; const onToggleShowOnlyChanges = () => { - contextApiRef.current.setState({ showOnlyChanges: !showOnlyChanges }); + setShowOnlyChanges(!showOnlyChanges); setCompareVersionDialogViewModes(username, { entireDiff: !showOnlyChanges, accordionView }); }; const onSetAccordionView = (value: boolean) => { - contextApiRef.current.setState({ accordionView: value }); + setAccordionView(value); setCompareVersionDialogViewModes(username, { entireDiff: showOnlyChanges, accordionView: value }); }; diff --git a/ui/app/src/components/CompareVersionsDialog/VersionsDialogContext.tsx b/ui/app/src/components/CompareVersionsDialog/VersionsDialogContext.tsx index 617427dbb8..b150303421 100644 --- a/ui/app/src/components/CompareVersionsDialog/VersionsDialogContext.tsx +++ b/ui/app/src/components/CompareVersionsDialog/VersionsDialogContext.tsx @@ -34,8 +34,6 @@ export interface VersionsDialogContextProps { viewSlideOutState: ViewVersionDialogProps; fieldsViewState: LookupTable; contentType: ContentType; - showOnlyChanges: boolean; - accordionView: boolean; } export const initialFieldViewState = { @@ -55,9 +53,7 @@ export const dialogInitialState: VersionsDialogContextProps = { compareSlideOutState: { open: false, isFetching: false, error: null }, viewSlideOutState: { open: false, isFetching: false, error: null }, fieldsViewState: {}, - contentType: null, - showOnlyChanges: true, - accordionView: false + contentType: null }; export interface VersionsDialogContextApi {