Skip to content

Commit

Permalink
refactor rename activeDocumentOrFormPreviewElement -> activeDocumentP…
Browse files Browse the repository at this point in the history
…reviewElement
  • Loading branch information
mnholtz committed Jun 27, 2024
1 parent 9640d59 commit f065bbb
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("DocumentOptions", () => {
),
);
dispatch(
actions.setActiveDocumentOrFormPreviewElement(initialActiveElement),
actions.setActiveBuilderPreviewElement(initialActiveElement),
);
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/documentBuilder/edit/DocumentOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ConfigErrorBoundary from "@/pageEditor/fields/ConfigErrorBoundary";
import { joinName } from "@/utils/formUtils";
import useAsyncEffect from "use-async-effect";
import { useSelector } from "react-redux";
import { selectActiveDocumentOrFormPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { selectActiveBuilderPreviewElement } from "@/pageEditor/slices/editorSelectors";
import ElementEditor from "@/pageEditor/documentBuilder/edit/ElementEditor";
import ConnectedCollapsibleFieldSection from "@/pageEditor/fields/ConnectedCollapsibleFieldSection";
import SchemaField from "@/components/fields/schemaFields/SchemaField";
Expand All @@ -37,7 +37,7 @@ const DocumentOptions: React.FC<{
const documentConfigName = joinName(name, configKey);
const documentBodyName = joinName(documentConfigName, "body");

const activeElement = useSelector(selectActiveDocumentOrFormPreviewElement);
const activeElement = useSelector(selectActiveBuilderPreviewElement);

const [{ value: bodyValue }, , { setValue: setBodyValue }] =
useField<DocumentBuilderElement[]>(documentBodyName);
Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/documentBuilder/edit/ElementEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import MoveElement from "./MoveElement";
import documentBuilderElementTypeLabels from "@/pageEditor/documentBuilder/elementTypeLabels";
import useElementOptions from "@/pageEditor/documentBuilder/edit/useElementOptions";
import { useSelector } from "react-redux";
import { selectActiveDocumentOrFormPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { selectActiveBuilderPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { getProperty } from "@/utils/objectUtils";
import ConnectedCollapsibleFieldSection from "@/pageEditor/fields/ConnectedCollapsibleFieldSection";
import { joinName } from "@/utils/formUtils";
Expand All @@ -34,7 +34,7 @@ type ElementEditorProps = {
};

const ElementEditor: React.FC<ElementEditorProps> = ({ documentBodyName }) => {
const activeElement = useSelector(selectActiveDocumentOrFormPreviewElement);
const activeElement = useSelector(selectActiveBuilderPreviewElement);
const elementName = `${documentBodyName}.${activeElement}`;
const [{ value: documentBuilderElement }] =
useField<DocumentBuilderElement>(elementName);
Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/documentBuilder/edit/RemoveElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { Button } from "react-bootstrap";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faTrash } from "@fortawesome/free-solid-svg-icons";
import useDeleteElement from "@/pageEditor/documentBuilder/hooks/useDeleteElement";
import { selectActiveDocumentOrFormPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { selectActiveBuilderPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { useSelector } from "react-redux";

type RemoveElementProps = {
documentBodyName: string;
};

const RemoveElement: React.FC<RemoveElementProps> = ({ documentBodyName }) => {
const activeElement = useSelector(selectActiveDocumentOrFormPreviewElement);
const activeElement = useSelector(selectActiveBuilderPreviewElement);
const deleteElement = useDeleteElement(documentBodyName);
const onDelete = async () => {
await deleteElement(activeElement);
Expand Down
2 changes: 1 addition & 1 deletion src/pageEditor/documentBuilder/hooks/useDeleteElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function useDeleteElement(documentBodyName: string) {

return useCallback(
async (elementName: string) => {
dispatch(editorActions.setActiveDocumentOrFormPreviewElement(null));
dispatch(editorActions.setActiveBuilderPreviewElement(null));

const { collectionName, elementIndex } = getElementCollectionName(
[documentBodyName, elementName].join("."),
Expand Down
6 changes: 3 additions & 3 deletions src/pageEditor/documentBuilder/hooks/useMoveElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { getIn, useField } from "formik";
import { getAllowedChildTypes } from "@/pageEditor/documentBuilder/allowedElementTypes";
import { useCallback } from "react";
import useReduxState from "@/hooks/useReduxState";
import { selectActiveDocumentOrFormPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { selectActiveBuilderPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { actions as editorActions } from "@/pageEditor/slices/editorSlice";

// https://stackoverflow.com/a/6470794/402560
Expand Down Expand Up @@ -114,8 +114,8 @@ function useMoveElement(documentBodyName: string) {
useField<DocumentBuilderElement[]>(documentBodyName);

const [, setActiveElement] = useReduxState(
selectActiveDocumentOrFormPreviewElement,
editorActions.setActiveDocumentOrFormPreviewElement,
selectActiveBuilderPreviewElement,
editorActions.setActiveBuilderPreviewElement,
);

return useCallback(
Expand Down
6 changes: 3 additions & 3 deletions src/pageEditor/documentBuilder/hooks/useMoveWithinParent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import useReduxState from "@/hooks/useReduxState";
import { selectActiveDocumentOrFormPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { selectActiveBuilderPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { actions } from "@/pageEditor/slices/editorSlice";
import { useField } from "formik";
import { type DocumentBuilderElement } from "@/pageEditor/documentBuilder/documentBuilderTypes";
Expand All @@ -33,8 +33,8 @@ type MoveWithinParent = {

function useMoveWithinParent(documentBodyName: string): MoveWithinParent {
const [activeElement, setActiveElement] = useReduxState(
selectActiveDocumentOrFormPreviewElement,
actions.setActiveDocumentOrFormPreviewElement,
selectActiveBuilderPreviewElement,
actions.setActiveBuilderPreviewElement,
);

assertNotNullish(activeElement, "No active element found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ function useSelectParentElement() {
const dispatch = useDispatch();
return (elementName: string) => {
const parentElementName = getParentElementName(elementName);
dispatch(
editorActions.setActiveDocumentOrFormPreviewElement(parentElementName),
);
dispatch(editorActions.setActiveBuilderPreviewElement(parentElementName));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const renderElementPreview = (
formState.extension.blockPipeline[0].instanceId,
),
);
dispatch(actions.setActiveDocumentOrFormPreviewElement("0"));
dispatch(actions.setActiveBuilderPreviewElement("0"));
},
});
};
Expand Down
6 changes: 3 additions & 3 deletions src/pageEditor/fields/FormModalOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import FormEditor from "@/components/formBuilder/edit/FormEditor";
import FormIntroFields from "@/components/formBuilder/edit/FormIntroFields";
import useReduxState from "@/hooks/useReduxState";
import ConfigErrorBoundary from "@/pageEditor/fields/ConfigErrorBoundary";
import { selectActiveDocumentOrFormPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { selectActiveBuilderPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { actions as editorActions } from "@/pageEditor/slices/editorSlice";
import FORM_FIELD_TYPE_OPTIONS from "@/pageEditor/fields/formFieldTypeOptions";
import ConnectedCollapsibleFieldSection from "@/pageEditor/fields/ConnectedCollapsibleFieldSection";
Expand Down Expand Up @@ -63,8 +63,8 @@ const FormModalOptions: React.FC<{
const configName = partial(joinName, baseName);

const [activeElement, setActiveElement] = useReduxState(
selectActiveDocumentOrFormPreviewElement,
editorActions.setActiveDocumentOrFormPreviewElement,
selectActiveBuilderPreviewElement,
editorActions.setActiveBuilderPreviewElement,
);

return (
Expand Down
6 changes: 3 additions & 3 deletions src/pageEditor/fields/FormRendererOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import FormEditor from "@/components/formBuilder/edit/FormEditor";
import FormIntroFields from "@/components/formBuilder/edit/FormIntroFields";
import useReduxState from "@/hooks/useReduxState";
import ConfigErrorBoundary from "@/pageEditor/fields/ConfigErrorBoundary";
import { selectActiveDocumentOrFormPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { selectActiveBuilderPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { actions as editorActions } from "@/pageEditor/slices/editorSlice";
import { useField, useFormikContext } from "formik";
import { partial } from "lodash";
Expand Down Expand Up @@ -273,8 +273,8 @@ const FormRendererOptions: React.FC<{
const configName = makeName();

const [activeElement, setActiveElement] = useReduxState(
selectActiveDocumentOrFormPreviewElement,
editorActions.setActiveDocumentOrFormPreviewElement,
selectActiveBuilderPreviewElement,
editorActions.setActiveBuilderPreviewElement,
);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/pageEditor/slices/editorSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export function selectNodeDataPanelTabState(
/**
* Selects the active element of the Document or Form builder on the Preview tab
*/
export function selectActiveDocumentOrFormPreviewElement(
export function selectActiveBuilderPreviewElement(
state: EditorRootState,
): Nullishable<string> {
return selectNodeDataPanelTabState(state, DataPanelTabKey.Preview)
Expand Down
2 changes: 1 addition & 1 deletion src/pageEditor/slices/editorSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("DataPanel state", () => {
test("should set the active element", () => {
const editorState = editorSlice.reducer(
state,
actions.setActiveDocumentOrFormPreviewElement("test-field"),
actions.setActiveBuilderPreviewElement("test-field"),
);

expect(
Expand Down
2 changes: 1 addition & 1 deletion src/pageEditor/slices/editorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export const editorSlice = createSlice({
const nodeUIState = validateNodeUIState(state);
nodeUIState.dataPanel[tabKey].treeExpandedState = expandedState;
},
setActiveDocumentOrFormPreviewElement(
setActiveBuilderPreviewElement(
state,
action: PayloadAction<string | null>,
) {
Expand Down
26 changes: 12 additions & 14 deletions src/pageEditor/tabs/editTab/dataPanel/DataPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
selectActiveModComponentFormState,
selectActiveNodeId,
selectActiveNodeInfo,
selectActiveDocumentOrFormPreviewElement,
selectActiveBuilderPreviewElement,
} from "@/pageEditor/slices/editorSelectors";
import { actions as editorActions } from "@/pageEditor/slices/editorSlice";
import Alert from "@/components/Alert";
Expand Down Expand Up @@ -173,13 +173,11 @@ const DataPanel: React.FC = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps -- We only want to report when `activeTabKey` changes
}, [activeTabKey]);

const [
activeDocumentOrFormPreviewElement,
setActiveDocumentOrFormPreviewElement,
] = useReduxState(
selectActiveDocumentOrFormPreviewElement,
editorActions.setActiveDocumentOrFormPreviewElement,
);
const [activeBuilderPreviewElement, setActiveBuilderPreviewElement] =
useReduxState(
selectActiveBuilderPreviewElement,
editorActions.setActiveBuilderPreviewElement,
);

const popupBoundary = showDocumentPreview
? document.querySelector(`.${dataPanelStyles.tabContent}`)
Expand Down Expand Up @@ -372,14 +370,14 @@ const DataPanel: React.FC = () => {
{showFormPreview ? (
<FormPreview
rjsfSchema={brickConfig?.config as RJSFSchema}
activeField={activeDocumentOrFormPreviewElement}
setActiveField={setActiveDocumentOrFormPreviewElement}
activeField={activeBuilderPreviewElement}
setActiveField={setActiveBuilderPreviewElement}
/>
) : (
<DocumentPreview
documentBodyName={documentBodyFieldName}
activeElement={activeDocumentOrFormPreviewElement}
setActiveElement={setActiveDocumentOrFormPreviewElement}
activeElement={activeBuilderPreviewElement}
setActiveElement={setActiveBuilderPreviewElement}
menuBoundary={popupBoundary}
/>
)}
Expand Down Expand Up @@ -412,8 +410,8 @@ const DataPanel: React.FC = () => {
)}
<DocumentOutline
documentBodyName={documentBodyFieldName}
activeElement={activeDocumentOrFormPreviewElement}
setActiveElement={setActiveDocumentOrFormPreviewElement}
activeElement={activeBuilderPreviewElement}
setActiveElement={setActiveBuilderPreviewElement}
/>
</ErrorBoundary>
</DataTab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import {
selectActiveModComponentFormState,
selectActiveNodeId,
selectCollapsedNodes,
selectActiveDocumentOrFormPreviewElement,
selectActiveBuilderPreviewElement,
selectPipelineMap,
} from "@/pageEditor/slices/editorSelectors";
import { getRootPipelineFlavor } from "@/bricks/brickFilterHelpers";
Expand Down Expand Up @@ -212,7 +212,7 @@ const usePipelineNodes = (): {
selectExtensionAnnotations(activeModComponentFormState.uuid),
);
const activeNodePreviewElementId = useSelector(
selectActiveDocumentOrFormPreviewElement,
selectActiveBuilderPreviewElement,
);

const isApiAtLeastV2 = useApiVersionAtLeast("v2");
Expand Down Expand Up @@ -319,7 +319,7 @@ const usePipelineNodes = (): {

const onClick = () => {
if (activeNodePreviewElementId) {
dispatch(actions.setActiveDocumentOrFormPreviewElement(null));
dispatch(actions.setActiveBuilderPreviewElement(null));

if (isNodeActive) {
return;
Expand Down Expand Up @@ -521,7 +521,7 @@ const usePipelineNodes = (): {
focus() {
setActiveNodeId(blockConfig.instanceId);
dispatch(
editorActions.setActiveDocumentOrFormPreviewElement(
editorActions.setActiveBuilderPreviewElement(
nodePreviewElementId,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import {
RunStatus,
} from "@/pageEditor/tabs/editTab/editTabTypes";
import { useSelector } from "react-redux";
import { selectActiveDocumentOrFormPreviewElement } from "@/pageEditor/slices/editorSelectors";
import { selectActiveBuilderPreviewElement } from "@/pageEditor/slices/editorSelectors";

const useScrollIntoViewEffect = (
active = false,
isSubPipelineHeaderActive = false,
) => {
const nodeRef = useRef<HTMLDivElement>(null);
const activeNodePreviewElementId = useSelector(
selectActiveDocumentOrFormPreviewElement,
selectActiveBuilderPreviewElement,
);

useEffect(() => {
Expand Down

0 comments on commit f065bbb

Please sign in to comment.