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

fix(editor): Add read only mode to filter component #8285

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ interface Props {
issues?: string[];
fixedLeftValue?: boolean;
canRemove?: boolean;
readOnly?: boolean;
index?: number;
}

const props = withDefaults(defineProps<Props>(), {
issues: () => [],
canRemove: true,
fixedLeftValue: false,
readOnly: false,
});

const emit = defineEmits<{
Expand Down Expand Up @@ -190,7 +192,7 @@ const onBlur = (): void => {
data-test-id="filter-condition"
>
<n8n-icon-button
v-if="canRemove"
v-if="canRemove && !readOnly"
type="tertiary"
text
size="mini"
Expand Down Expand Up @@ -227,13 +229,15 @@ const onBlur = (): void => {
:value="condition.leftValue"
:path="`${path}.left`"
:class="[$style.input, $style.inputLeft]"
:is-read-only="readOnly"
data-test-id="filter-condition-left"
@update="onLeftValueChange"
@blur="onBlur"
/>
<OperatorSelect
:class="$style.select"
:selected="`${operator.type}:${operator.operation}`"
:read-only="readOnly"
@operatorChange="onOperatorChange"
></OperatorSelect>
<ParameterInputFull
Expand All @@ -248,6 +252,7 @@ const onBlur = (): void => {
:value="condition.rightValue"
:path="`${path}.right`"
:class="[$style.input, $style.inputRight]"
:is-read-only="readOnly"
data-test-id="filter-condition-right"
@update="onRightValueChange"
@blur="onBlur"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ interface Props {
value: FilterValue;
path: string;
node: INode | null;
readOnly?: boolean;
}

const props = defineProps<Props>();
const props = withDefaults(defineProps<Props>(), { readOnly: false });

const emit = defineEmits<{
(event: 'valueChanged', value: { name: string; node: string; value: FilterValue }): void;
Expand Down Expand Up @@ -145,7 +146,7 @@ function getIssues(index: number): string[] {
<div v-for="(condition, index) of state.paramValue.conditions" :key="condition.id">
<CombinatorSelect
v-if="index !== 0"
:read-only="index !== 1"
:read-only="index !== 1 || readOnly"
:options="allowedCombinators"
:selected="state.paramValue.combinator"
:class="$style.combinator"
Expand All @@ -157,6 +158,7 @@ function getIssues(index: number): string[] {
:index="index"
:options="state.paramValue.options"
:fixed-left-value="!!parameter.typeOptions?.filter?.leftValue"
:read-only="readOnly"
:can-remove="index !== 0 || state.paramValue.conditions.length > 1"
:path="`${path}.${index}`"
:issues="getIssues(index)"
Expand All @@ -166,7 +168,7 @@ function getIssues(index: number): string[] {
></Condition>
</div>
</div>
<div v-if="!singleCondition" :class="$style.addConditionWrapper">
<div v-if="!singleCondition && !readOnly" :class="$style.addConditionWrapper">
<n8n-button
type="tertiary"
block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import type { FilterOperator } from './types';

interface Props {
selected: string;
readOnly?: boolean;
}

const props = defineProps<Props>();
const props = withDefaults(defineProps<Props>(), { readOnly: false });

const selected = ref(props.selected);
const menuOpen = ref(false);
Expand Down Expand Up @@ -57,6 +58,7 @@ function onGroupSelect(group: string) {
data-test-id="filter-operator-select"
size="small"
:model-value="selected"
:disabled="readOnly"
@update:modelValue="onOperatorChange"
@visible-change="onSelectVisibleChange"
@mouseenter="shouldRenderItems = true"
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/components/ParameterInputList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
:value="nodeHelpers.getParameterValue(nodeValues, parameter.name, path)"
:path="getPath(parameter.name)"
:node="node"
:read-only="isReadOnly"
@valueChanged="valueChanged"
/>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { STORES } from '@/constants';
import { useNDVStore } from '@/stores/ndv.store';
import { createTestingPinia } from '@pinia/testing';
import userEvent from '@testing-library/user-event';
import { within } from '@testing-library/vue';

const DEFAULT_SETUP = {
pinia: createTestingPinia({
Expand All @@ -31,7 +32,7 @@ const DEFAULT_SETUP = {

const renderComponent = createComponentRenderer(FilterConditions, DEFAULT_SETUP);

describe('Filter.vue', () => {
describe('FilterConditions.vue', () => {
afterEach(() => {
vi.clearAllMocks();
});
Expand Down Expand Up @@ -264,4 +265,45 @@ describe('Filter.vue', () => {
expect(conditions.length).toEqual(1);
expect(conditions[0].querySelector('[data-test-id="filter-remove-condition"]')).toBeNull();
});

it('renders correctly in read only mode', async () => {
const { findAllByTestId, queryByTestId } = renderComponent({
props: {
...DEFAULT_SETUP.props,
value: {
conditions: [
{
leftValue: 'foo',
operator: { type: 'string', operation: 'equals' },
rightValue: 'bar',
},
{
leftValue: 'foo',
operator: { type: 'string', operation: 'equals' },
rightValue: 'bar',
},
],
},
readOnly: true,
},
});

expect(queryByTestId('filter-add-condition')).not.toBeInTheDocument();

const conditions = await findAllByTestId('filter-condition');

for (const condition of conditions) {
const removeButton = within(condition).queryByTestId('filter-remove-condition');
expect(removeButton).not.toBeInTheDocument();

const left = within(condition).getByTestId('filter-condition-left');
expect(left.querySelector('input')).toBeDisabled();

const right = within(condition).getByTestId('filter-condition-right');
expect(right.querySelector('input')).toBeDisabled();

const operatorSelect = within(condition).getByTestId('filter-operator-select');
expect(operatorSelect.querySelector('input')).toBeDisabled();
}
});
});
Loading