fix(editor): Plus node button should not be visible on readonly mode (#10692)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions

This commit is contained in:
Raúl Gómez Morales 2024-09-06 07:54:54 +02:00 committed by GitHub
parent 3adbcab27d
commit 62cb189985
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 28 additions and 3 deletions

View file

@ -121,12 +121,14 @@ export function createCanvasHandleProvide({
type = NodeConnectionType.Main, type = NodeConnectionType.Main,
isConnected = false, isConnected = false,
isConnecting = false, isConnecting = false,
isReadOnly = false,
}: { }: {
label?: string; label?: string;
mode?: CanvasConnectionMode; mode?: CanvasConnectionMode;
type?: NodeConnectionType; type?: NodeConnectionType;
isConnected?: boolean; isConnected?: boolean;
isConnecting?: boolean; isConnecting?: boolean;
isReadOnly?: boolean;
} = {}) { } = {}) {
return { return {
[`${CanvasNodeHandleKey}`]: { [`${CanvasNodeHandleKey}`]: {
@ -135,6 +137,7 @@ export function createCanvasHandleProvide({
type: ref(type), type: ref(type),
isConnected: ref(isConnected), isConnected: ref(isConnected),
isConnecting: ref(isConnecting), isConnecting: ref(isConnecting),
isReadOnly: ref(isReadOnly),
} satisfies CanvasNodeHandleInjectionData, } satisfies CanvasNodeHandleInjectionData,
}; };
} }

View file

@ -18,6 +18,7 @@ const props = defineProps<{
mode: CanvasConnectionMode; mode: CanvasConnectionMode;
isConnected?: boolean; isConnected?: boolean;
isConnecting?: boolean; isConnecting?: boolean;
isReadOnly?: boolean;
label?: string; label?: string;
type: CanvasConnectionPort['type']; type: CanvasConnectionPort['type'];
index: CanvasConnectionPort['index']; index: CanvasConnectionPort['index'];
@ -99,6 +100,7 @@ function onAdd() {
const label = toRef(props, 'label'); const label = toRef(props, 'label');
const isConnected = toRef(props, 'isConnected'); const isConnected = toRef(props, 'isConnected');
const isConnecting = toRef(props, 'isConnecting'); const isConnecting = toRef(props, 'isConnecting');
const isReadOnly = toRef(props, 'isReadOnly');
const mode = toRef(props, 'mode'); const mode = toRef(props, 'mode');
const type = toRef(props, 'type'); const type = toRef(props, 'type');
@ -108,6 +110,7 @@ provide(CanvasNodeHandleKey, {
type, type,
isConnected, isConnected,
isConnecting, isConnecting,
isReadOnly,
}); });
</script> </script>

View file

@ -7,7 +7,7 @@ const renderComponent = createComponentRenderer(CanvasHandleMainOutput);
describe('CanvasHandleMainOutput', () => { describe('CanvasHandleMainOutput', () => {
it('should render correctly', async () => { it('should render correctly', async () => {
const label = 'Test Label'; const label = 'Test Label';
const { container, getByText } = renderComponent({ const { container, getByText, getByTestId } = renderComponent({
global: { global: {
provide: { provide: {
...createCanvasHandleProvide({ label }), ...createCanvasHandleProvide({ label }),
@ -16,6 +16,19 @@ describe('CanvasHandleMainOutput', () => {
}); });
expect(container.querySelector('.canvas-node-handle-main-output')).toBeInTheDocument(); expect(container.querySelector('.canvas-node-handle-main-output')).toBeInTheDocument();
expect(getByTestId('canvas-handle-plus')).toBeInTheDocument();
expect(getByText(label)).toBeInTheDocument(); expect(getByText(label)).toBeInTheDocument();
}); });
it('should not render CanvasHandlePlus when isReadOnly', () => {
const { queryByTestId } = renderComponent({
global: {
provide: {
...createCanvasHandleProvide({ isReadOnly: true }),
},
},
});
expect(queryByTestId('canvas-handle-plus')).not.toBeInTheDocument();
});
}); });

View file

@ -9,7 +9,7 @@ const emit = defineEmits<{
}>(); }>();
const { render } = useCanvasNode(); const { render } = useCanvasNode();
const { label, isConnected, isConnecting } = useCanvasNodeHandle(); const { label, isConnected, isConnecting, isReadOnly } = useCanvasNodeHandle();
const handleClasses = 'source'; const handleClasses = 'source';
const isHovered = ref(false); const isHovered = ref(false);
@ -45,8 +45,9 @@ function onClickAdd() {
<CanvasHandleDot :handle-classes="handleClasses" /> <CanvasHandleDot :handle-classes="handleClasses" />
<Transition name="canvas-node-handle-main-output"> <Transition name="canvas-node-handle-main-output">
<CanvasHandlePlus <CanvasHandlePlus
v-if="!isConnected" v-if="!isConnected && !isReadOnly"
v-show="isHandlePlusVisible" v-show="isHandlePlusVisible"
data-test-id="canvas-handle-plus"
:line-size="plusLineSize" :line-size="plusLineSize"
:handle-classes="handleClasses" :handle-classes="handleClasses"
@mouseenter="onMouseEnter" @mouseenter="onMouseEnter"

View file

@ -271,6 +271,7 @@ onBeforeUnmount(() => {
:offset="source.offset" :offset="source.offset"
:is-connected="source.isConnected" :is-connected="source.isConnected"
:is-connecting="source.isConnecting" :is-connecting="source.isConnecting"
:is-read-only="readOnly"
:is-valid-connection="isValidConnection" :is-valid-connection="isValidConnection"
@add="onAdd" @add="onAdd"
/> />
@ -287,6 +288,7 @@ onBeforeUnmount(() => {
:offset="target.offset" :offset="target.offset"
:is-connected="target.isConnected" :is-connected="target.isConnected"
:is-connecting="target.isConnecting" :is-connecting="target.isConnecting"
:is-read-only="readOnly"
:is-valid-connection="isValidConnection" :is-valid-connection="isValidConnection"
@add="onAdd" @add="onAdd"
/> />

View file

@ -16,11 +16,13 @@ export function useCanvasNodeHandle() {
const isConnecting = computed(() => handle?.isConnecting.value ?? false); const isConnecting = computed(() => handle?.isConnecting.value ?? false);
const type = computed(() => handle?.type.value ?? NodeConnectionType.Main); const type = computed(() => handle?.type.value ?? NodeConnectionType.Main);
const mode = computed(() => handle?.mode.value ?? CanvasConnectionMode.Input); const mode = computed(() => handle?.mode.value ?? CanvasConnectionMode.Input);
const isReadOnly = computed(() => handle?.isReadOnly.value);
return { return {
label, label,
isConnected, isConnected,
isConnecting, isConnecting,
isReadOnly,
type, type,
mode, mode,
}; };

View file

@ -165,6 +165,7 @@ export interface CanvasNodeHandleInjectionData {
type: Ref<NodeConnectionType>; type: Ref<NodeConnectionType>;
isConnected: Ref<boolean | undefined>; isConnected: Ref<boolean | undefined>;
isConnecting: Ref<boolean | undefined>; isConnecting: Ref<boolean | undefined>;
isReadOnly: Ref<boolean | undefined>;
} }
export type ConnectStartEvent = { handleId: string; handleType: string; nodeId: string }; export type ConnectStartEvent = { handleId: string; handleType: string; nodeId: string };