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,
isConnected = false,
isConnecting = false,
isReadOnly = false,
}: {
label?: string;
mode?: CanvasConnectionMode;
type?: NodeConnectionType;
isConnected?: boolean;
isConnecting?: boolean;
isReadOnly?: boolean;
} = {}) {
return {
[`${CanvasNodeHandleKey}`]: {
@ -135,6 +137,7 @@ export function createCanvasHandleProvide({
type: ref(type),
isConnected: ref(isConnected),
isConnecting: ref(isConnecting),
isReadOnly: ref(isReadOnly),
} satisfies CanvasNodeHandleInjectionData,
};
}

View file

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

View file

@ -7,7 +7,7 @@ const renderComponent = createComponentRenderer(CanvasHandleMainOutput);
describe('CanvasHandleMainOutput', () => {
it('should render correctly', async () => {
const label = 'Test Label';
const { container, getByText } = renderComponent({
const { container, getByText, getByTestId } = renderComponent({
global: {
provide: {
...createCanvasHandleProvide({ label }),
@ -16,6 +16,19 @@ describe('CanvasHandleMainOutput', () => {
});
expect(container.querySelector('.canvas-node-handle-main-output')).toBeInTheDocument();
expect(getByTestId('canvas-handle-plus')).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 { label, isConnected, isConnecting } = useCanvasNodeHandle();
const { label, isConnected, isConnecting, isReadOnly } = useCanvasNodeHandle();
const handleClasses = 'source';
const isHovered = ref(false);
@ -45,8 +45,9 @@ function onClickAdd() {
<CanvasHandleDot :handle-classes="handleClasses" />
<Transition name="canvas-node-handle-main-output">
<CanvasHandlePlus
v-if="!isConnected"
v-if="!isConnected && !isReadOnly"
v-show="isHandlePlusVisible"
data-test-id="canvas-handle-plus"
:line-size="plusLineSize"
:handle-classes="handleClasses"
@mouseenter="onMouseEnter"

View file

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

View file

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

View file

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