Skip to content
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
99 changes: 0 additions & 99 deletions packages/ee/ui/embed-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export enum ActivepiecesClientEventName {
CLIENT_CONFIGURATION_FINISHED = 'CLIENT_CONFIGURATION_FINISHED',
CLIENT_CONNECTION_PIECE_NOT_FOUND = 'CLIENT_CONNECTION_PIECE_NOT_FOUND',
CLIENT_BUILDER_HOME_BUTTON_CLICKED = 'CLIENT_BUILDER_HOME_BUTTON_CLICKED',
CLIENT_STEP_SETTINGS_DIALOG_CLOSED = 'CLIENT_STEP_SETTINGS_DIALOG_CLOSED',
CLIENT_SHOW_STEP_SETTINGS_IFRAME = 'CLIENT_SHOW_STEP_SETTINGS_IFRAME',
}
export interface ActivepiecesClientInit {
type: ActivepiecesClientEventName.CLIENT_INIT;
Expand Down Expand Up @@ -65,14 +63,6 @@ export interface ActivepiecesBuilderHomeButtonClicked {
route: string;
};
}
export interface ActivepiecesClientShowStepSettingsIframe {
type: ActivepiecesClientEventName.CLIENT_SHOW_STEP_SETTINGS_IFRAME;
data: Record<string, never>;
}
export interface ActivepiecesStepSettingsDialogClosed {
type: ActivepiecesClientEventName.CLIENT_STEP_SETTINGS_DIALOG_CLOSED;
data: Record<string, never>;
}

type IframeWithWindow = HTMLIFrameElement & { contentWindow: Window };

Expand Down Expand Up @@ -411,59 +401,6 @@ class ActivepiecesEmbedded {
}


private _addStepSettingsIframe({stepName, flowVersionId, flowId}:{stepName:string, flowVersionId:string, flowId:string}) {
const stepSettingsIframe = this.connectToEmbed({
iframeContainer: document.body,
initialRoute: `/embed/step-settings?${STEP_SETTINGS_QUERY_PARAMS.stepName}=${stepName}&${STEP_SETTINGS_QUERY_PARAMS.flowVersionId}=${flowVersionId}&${STEP_SETTINGS_QUERY_PARAMS.flowId}=${flowId}`
});
stepSettingsIframe.style.cssText = ['display:none', 'position:fixed', 'top:0', 'left:0', 'width:100%', 'height:100%', 'border:none'].join(';');
return stepSettingsIframe;
}

private _openNewWindowForStepSettings({stepName, flowVersionId, flowId, newWindow}:{stepName:string, flowVersionId:string, flowId:string, newWindow:newWindowFeatures}) {
const popup = window.open(`${this._instanceUrl}/embed`, '_blank', this._getNewWindowFeatures(newWindow));
if (!popup) {
this._errorCreator('Failed to open popup window');
}
this._setupInitialMessageHandler(popup, `/embed/step-settings?${STEP_SETTINGS_QUERY_PARAMS.stepName}=${stepName}&${STEP_SETTINGS_QUERY_PARAMS.flowVersionId}=${flowVersionId}&${STEP_SETTINGS_QUERY_PARAMS.flowId}=${flowId}`);
return popup;
}

async openStepSettings({ stepName, flowVersionId, flowId, newWindow }: {
stepName: string,
flowVersionId: string,
flowId: string,
newWindow?:newWindowFeatures
}) {
this._cleanStepSettingsIframe();
return this._addGracePeriodBeforeMethod({
condition: () => {
return !!document.body;
},
method: async () => {
const target = newWindow? this._openNewWindowForStepSettings({stepName, flowVersionId, flowId, newWindow}) : this._addStepSettingsIframe({stepName, flowVersionId, flowId});
//don't check for window because (instanceof Window) is false for popups
if(!(target instanceof HTMLIFrameElement)) {
const checkClosed = setInterval(() => {
if (target.closed) {
clearInterval(checkClosed);
if(this._resolveStepSettingsDialogClosed) {
this._resolveStepSettingsDialogClosed()
}
}
}, 500);
}
return new Promise<void>((resolve, reject) => {
this._resolveStepSettingsDialogClosed = resolve;
this._rejectStepSettingsDialogClosed = reject;
this._setStepSettingsIframeEventsListener(target);
});
},
errorMessage: 'unable to add step settings embedding'
});
}


navigate({ route }: { route: string }) {
if (!this._dashboardAndBuilderIframeWindow) {
this._logger().error('dashboard iframe not found');
Expand Down Expand Up @@ -524,8 +461,6 @@ class ActivepiecesEmbedded {
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
private _cleanConnectionIframe = () => { };
// eslint-disable-next-line @typescript-eslint/no-empty-function
private _cleanStepSettingsIframe = () => { };
private _setConnectionIframeEventsListener(target: Window | HTMLIFrameElement ) {
const connectionRelatedMessageHandler = (event: MessageEvent<ActivepiecesNewConnectionDialogClosed | ActivepiecesClientConnectionNameIsInvalid | ActivepiecesClientShowConnectionIframe | ActivepiecesClientConnectionPieceNotFound>) => {
if (event.data.type) {
Expand Down Expand Up @@ -570,40 +505,6 @@ class ActivepiecesEmbedded {
this._removeEmbedding(target);
}
}

private _setStepSettingsIframeEventsListener(target: Window | HTMLIFrameElement ) {
const stepSettingsRelatedMessageHandler = (event: MessageEvent<ActivepiecesStepSettingsDialogClosed | ActivepiecesClientShowStepSettingsIframe>) => {
if (event.data.type) {
switch (event.data.type) {
case ActivepiecesClientEventName.CLIENT_STEP_SETTINGS_DIALOG_CLOSED: {
if (this._resolveStepSettingsDialogClosed) {
this._resolveStepSettingsDialogClosed();
}
this._removeEmbedding(target);
window.removeEventListener('message', stepSettingsRelatedMessageHandler);
break;
}
case ActivepiecesClientEventName.CLIENT_SHOW_STEP_SETTINGS_IFRAME: {
if (target instanceof HTMLIFrameElement) {
target.style.display = 'block';
}
break;
}
}
}
}
window.addEventListener(
'message',
stepSettingsRelatedMessageHandler
);
this._cleanStepSettingsIframe = () => {
window.removeEventListener('message', stepSettingsRelatedMessageHandler);
this._resolveStepSettingsDialogClosed = undefined;
this._rejectStepSettingsDialogClosed = undefined;
this._removeEmbedding(target);
}
}

private _removeTrailingSlashes(str: string) {
return str.endsWith('/') ? str.slice(0, -1) : str;
}
Expand Down
55 changes: 24 additions & 31 deletions packages/react-ui/src/app/builder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
FlowTriggerType,
FlowVersionState,
flowStructureUtil,
isNil,
} from '@activepieces/shared';

import { cn, useElementSize } from '../../lib/utils';
Expand All @@ -43,46 +42,40 @@ const animateResizeClassName = `transition-all `;

const BuilderPage = () => {
const { platform } = platformHooks.useCurrentPlatform();
const [flowVersion, rightSidebar, selectedStep, removeAllStepTestsListeners] =
useBuilderStateContext((state) => [
state.flowVersion,
state.rightSidebar,
state.selectedStep,
state.removeAllStepTestsListeners,
]);
const [
flowVersion,
rightSidebar,
selectedStepName,
removeAllStepTestsListeners,
selectedStep,
] = useBuilderStateContext((state) => [
state.flowVersion,
state.rightSidebar,
state.selectedStep,
state.removeAllStepTestsListeners,
flowStructureUtil.getStep(
state.selectedStep ?? '',
state.flowVersion.trigger,
),
]);
useEffect(() => {
return () => {
removeAllStepTestsListeners();
};
}, [removeAllStepTestsListeners]);
flowCanvasHooks.useShowBuilderIsSavingWarningBeforeLeaving();
const { memorizedSelectedStep } = useBuilderStateContext((state) => {
const flowVersion = state.flowVersion;
if (isNil(state.selectedStep) || isNil(flowVersion)) {
return {
memorizedSelectedStep: undefined,
};
}
const step = flowStructureUtil.getStep(
state.selectedStep,
flowVersion.trigger,
);
return {
memorizedSelectedStep: step,
};
});
const middlePanelRef = useRef<HTMLDivElement>(null);
const middlePanelSize = useElementSize(middlePanelRef);
const [isDraggingHandle, setIsDraggingHandle] = useState(false);
const rightHandleRef = flowCanvasHooks.useAnimateSidebar(rightSidebar);
const rightSidePanelRef = useRef<HTMLDivElement>(null);
const { pieceModel, refetch: refetchPiece } =
piecesHooks.usePieceModelForStepSettings({
name: memorizedSelectedStep?.settings.pieceName,
version: memorizedSelectedStep?.settings.pieceVersion,
name: selectedStep?.settings.pieceName,
version: selectedStep?.settings.pieceVersion,
enabled:
memorizedSelectedStep?.type === FlowActionType.PIECE ||
memorizedSelectedStep?.type === FlowTriggerType.PIECE,
selectedStep?.type === FlowActionType.PIECE ||
selectedStep?.type === FlowTriggerType.PIECE,
getExactVersion: flowVersion.state === FlowVersionState.LOCKED,
});
flowCanvasHooks.useSetSocketListener(refetchPiece);
Expand Down Expand Up @@ -114,7 +107,7 @@ const BuilderPage = () => {
canvasHeight={middlePanelRef.current?.clientHeight ?? 0}
canvasWidth={middlePanelRef.current?.clientWidth ?? 0}
hasCanvasBeenInitialised={hasCanvasBeenInitialised}
selectedStep={selectedStep}
selectedStep={selectedStepName}
></CanvasControls>
)}

Expand Down Expand Up @@ -157,14 +150,14 @@ const BuilderPage = () => {
>
<div ref={rightSidePanelRef} className="h-full w-full">
{rightSidebar === RightSideBarType.PIECE_SETTINGS &&
memorizedSelectedStep && (
selectedStep && (
<ResizableVerticalPanelsProvider>
<StepSettingsProvider
pieceModel={pieceModel}
selectedStep={memorizedSelectedStep}
selectedStep={selectedStep}
key={constructContainerKey({
flowVersionId: flowVersion.id,
step: memorizedSelectedStep,
step: selectedStep,
hasPieceModelLoaded: !!pieceModel,
})}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useRef } from 'react';
import React, { useEffect, useRef } from 'react';
import { useFormContext } from 'react-hook-form';

import { cn, GAP_SIZE_FOR_STEP_SETTINGS } from '@/lib/utils';
import { ArraySubProps } from '@activepieces/pieces-framework';
import { isNil } from '@activepieces/shared';

import { useBuilderStateContext } from '../builder-hooks';
import { flowCanvasHooks } from '../flow-canvas/hooks';
Expand Down Expand Up @@ -40,7 +42,7 @@ const ArrayPiecePropertyInInlineItemMode = React.memo(
setIsFocusInsideListMapperModeInput,
isFocusInsideListMapperModeInput,
});

useFixInlineArrayPropertyValue(inputName, props);
return (
<div className="w-full" ref={containerRef}>
{props.arrayProperties ? (
Expand Down Expand Up @@ -74,3 +76,23 @@ const ArrayPiecePropertyInInlineItemMode = React.memo(
ArrayPiecePropertyInInlineItemMode.displayName =
'ArrayPiecePropertyInInlineItemMode';
export { ArrayPiecePropertyInInlineItemMode };

/**
* we had a bug where the value for inline array property was not an object
* this will always insure the value is an object
*/
const useFixInlineArrayPropertyValue = (
inputName: string,
props: ArrayPiecePropertyInInlineItemModeProps,
) => {
const form = useFormContext();
useEffect(() => {
const value = form.getValues(inputName);
if (
props.arrayProperties &&
(isNil(value) || typeof value !== 'object' || Array.isArray(value))
) {
form.setValue(inputName, {}, { shouldValidate: true });
}
}, []);
};
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const DynamicPropertiesImplementation = React.memo(
const defaultValue = formUtils.getDefaultValueForProperties({
props: response.options,
existingInput: currentValue ?? {},
propertySettings: undefined,
propertySettings: props.propertySettings ?? {},
});
setPropertyMap(response.options);
const schemaWithoutDropdownOptions =
Expand All @@ -159,7 +159,6 @@ const DynamicPropertiesImplementation = React.memo(
form,
);
}

form.setValue(
prependPrefixToPropertyName({
propertyName: props.propertyName,
Expand Down
Loading
Loading