Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: hide overlay on delete event #295

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/visualBuilder/components/FieldToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const TOOLTIP_TOP_EDGE_BUFFER = 96;

interface MultipleFieldToolbarProps {
eventDetails: VisualBuilderCslpEventDetails;
hideOverlay: () => void;
};

function handleReplaceAsset(fieldMetadata: CslpData) {
Expand Down Expand Up @@ -309,6 +310,14 @@ function FieldToolbarComponent(
fetchFieldSchema();
}, [fieldMetadata]);

useEffect(() => {
visualBuilderPostMessage?.on(VisualBuilderPostMessageEvents.DELETE_INSTANCE, (args: { data: { path: string } }) => {
if(args.data?.path === fieldMetadata.instance.fieldPathWithIndex){
props.hideOverlay()
}
})
}, [])

const multipleFieldToolbarButtonClasses = classNames(
"visual-builder__button visual-builder__button--secondary",
visualBuilderStyles()["visual-builder__button"],
Expand Down
9 changes: 6 additions & 3 deletions src/visualBuilder/generators/generateToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import FieldLabelWrapperComponent from "../components/fieldLabelWrapper";

export function appendFocusedToolbar(
eventDetails: VisualBuilderCslpEventDetails,
focusedToolbarElement: HTMLDivElement
focusedToolbarElement: HTMLDivElement,
hideOverlay: () => void
): void {
appendFieldPathDropdown(eventDetails, focusedToolbarElement);
appendFieldToolbar(eventDetails, focusedToolbarElement);
appendFieldToolbar(eventDetails, focusedToolbarElement, hideOverlay);
}

export function appendFieldToolbar(
eventDetails: VisualBuilderCslpEventDetails,
focusedToolbarElement: HTMLDivElement
focusedToolbarElement: HTMLDivElement,
hideOverlay: () => void
): void {
if (
focusedToolbarElement.querySelector(
Expand All @@ -35,6 +37,7 @@ export function appendFieldToolbar(
render(
<FieldToolbarComponent
eventDetails={eventDetails}
hideOverlay={hideOverlay}
/>,
wrapper
);
Expand Down
12 changes: 10 additions & 2 deletions src/visualBuilder/listeners/mouseClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type AddFocusOverlayParams = Pick<
type AddFocusedToolbarParams = Pick<
EventListenerHandlerParams,
"eventDetails" | "focusedToolbar"
>;
> & { hideOverlay: () => void };

function addOverlay(params: AddFocusOverlayParams) {
if (!params.overlayWrapper || !params.editableElement) return;
Expand All @@ -53,7 +53,7 @@ export function addFocusedToolbar(params: AddFocusedToolbarParams): void {

if (!editableElement || !params.focusedToolbar) return;

appendFocusedToolbar(params.eventDetails, params.focusedToolbar);
appendFocusedToolbar(params.eventDetails, params.focusedToolbar, params.hideOverlay);
}

async function handleBuilderInteraction(
Expand Down Expand Up @@ -143,6 +143,14 @@ async function handleBuilderInteraction(
addFocusedToolbar({
eventDetails: eventDetails,
focusedToolbar: params.focusedToolbar,
hideOverlay: () => {
hideOverlay({
visualBuilderContainer: params.visualBuilderContainer,
visualBuilderOverlayWrapper: params.overlayWrapper,
focusedToolbar: params.focusedToolbar,
resizeObserver: params.resizeObserver,
});
}
});

const { content_type_uid, fieldPath, cslpValue } = fieldMetadata;
Expand Down
Loading