Skip to content

Commit

Permalink
[3941] Rollback showOnlyChanges and accordionView from Context as the…
Browse files Browse the repository at this point in the history
…y can't be shared between dialog and slideouts
  • Loading branch information
jvega190 committed Oct 9, 2024
1 parent 56d6c3b commit 738f716
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -60,14 +59,17 @@ export function CompareVersionsDialogContainer(props: CompareVersionsDialogConta
contentTypesBranch,
compareXml
} = props;
const [{ fieldsViewState, showOnlyChanges, accordionView }, contextApiRef] = useVersionsDialogContext();
const [{ fieldsViewState }] = useVersionsDialogContext();
const fieldsViewStateRef = useRef<VersionsDialogContextProps['fieldsViewState']>();
fieldsViewStateRef.current = fieldsViewState;
const compareVersionsBranch = versionsBranch?.compareVersionsBranch;
const item = versionsBranch?.item;
const baseUrl = useSelection<string>((state) => state.env.authoringBase);
const { formatMessage } = useIntl();
const { username } = useActiveUser();
const viewModes = getCompareVersionDialogViewModes(username);
const [showOnlyChanges, setShowOnlyChanges] = useState<boolean>(viewModes?.entireDiff ?? true);
const [accordionView, setAccordionView] = useState<boolean>(viewModes?.accordionView ?? false);
const [selectionContent, setSelectionContent] = useSpreadState<{
a: SelectionContentVersion;
b: SelectionContentVersion;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export interface VersionsDialogContextProps {
viewSlideOutState: ViewVersionDialogProps;
fieldsViewState: LookupTable<FieldViewState>;
contentType: ContentType;
showOnlyChanges: boolean;
accordionView: boolean;
}

export const initialFieldViewState = {
Expand All @@ -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 {
Expand Down

0 comments on commit 738f716

Please sign in to comment.