From b55146e1285a739d2a7fdfc72ac969cb04dda029 Mon Sep 17 00:00:00 2001 From: Sonia Zorba Date: Wed, 17 Apr 2024 15:52:10 +0200 Subject: [PATCH 01/11] Renamed FiltersCreationForm to AttributesTypesForm, made buttons text configurable --- ...rm.test.js => AttributesTypesForm.test.js} | 24 ++--- .../v2/projects/datasets/AddImageModal.svelte | 14 +-- ...Form.svelte => AttributesTypesForm.svelte} | 102 +++++++++++------- .../datasets/CreateDatasetModal.svelte | 6 +- .../datasets/DatasetFiltersModal.svelte | 6 +- .../v2/workflow/InputFiltersTab.svelte | 6 +- tests/v2/images.spec.js | 10 +- 7 files changed, 95 insertions(+), 73 deletions(-) rename __tests__/v2/{FiltersCreationForm.test.js => AttributesTypesForm.test.js} (88%) rename src/lib/components/v2/projects/datasets/{FiltersCreationForm.svelte => AttributesTypesForm.svelte} (79%) diff --git a/__tests__/v2/FiltersCreationForm.test.js b/__tests__/v2/AttributesTypesForm.test.js similarity index 88% rename from __tests__/v2/FiltersCreationForm.test.js rename to __tests__/v2/AttributesTypesForm.test.js index 5fe71e53..3701c9da 100644 --- a/__tests__/v2/FiltersCreationForm.test.js +++ b/__tests__/v2/AttributesTypesForm.test.js @@ -1,12 +1,12 @@ import { describe, it, expect } from 'vitest'; import { fireEvent, render } from '@testing-library/svelte'; -import FiltersCreationForm from '../../src/lib/components/v2/projects/datasets/FiltersCreationForm.svelte'; +import AttributesTypesForm from '../../src/lib/components/v2/projects/datasets/AttributesTypesForm.svelte'; import { tick } from 'svelte'; -describe('FiltersCreationForm', () => { +describe('AttributesTypesForm', () => { it('init with existing filters', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); result.component.init( { key1: 'value1', @@ -29,7 +29,7 @@ describe('FiltersCreationForm', () => { }); it('add and remove attribute filter', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); expect(result.queryAllByPlaceholderText('Key').length).eq(0); await fireEvent.click(result.getByRole('button', { name: 'Add attribute filter' })); expect(result.queryAllByPlaceholderText('Key').length).eq(1); @@ -38,7 +38,7 @@ describe('FiltersCreationForm', () => { }); it('add and remove type filter', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); expect(result.queryAllByPlaceholderText('Key').length).eq(0); await fireEvent.click(result.getByRole('button', { name: 'Add type filter' })); expect(result.queryAllByPlaceholderText('Key').length).eq(1); @@ -47,7 +47,7 @@ describe('FiltersCreationForm', () => { }); it('validate missing attribute filter key', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); result.component.init({}, {}); await fireEvent.click(result.getByRole('button', { name: 'Add attribute filter' })); expect(result.component.validateFields()).false; @@ -56,7 +56,7 @@ describe('FiltersCreationForm', () => { }); it('validate missing attribute filter value', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); result.component.init({}, {}); await fireEvent.click(result.getByRole('button', { name: 'Add attribute filter' })); await fireEvent.input(result.getByPlaceholderText('Key'), { target: { value: 'my-key' } }); @@ -66,7 +66,7 @@ describe('FiltersCreationForm', () => { }); it('validate invalid number', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); await fireEvent.click(result.getByRole('button', { name: 'Add attribute filter' })); await fireEvent.input(result.getByPlaceholderText('Key'), { target: { value: 'my-key' } }); await fireEvent.change(result.getByLabelText('Type'), { target: { value: 'number' } }); @@ -77,7 +77,7 @@ describe('FiltersCreationForm', () => { }); it('switch to boolean attribute', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); await fireEvent.click(result.getByRole('button', { name: 'Add attribute filter' })); await fireEvent.input(result.getByPlaceholderText('Key'), { target: { value: 'my-key' } }); await fireEvent.change(result.getByLabelText('Type'), { target: { value: 'boolean' } }); @@ -86,7 +86,7 @@ describe('FiltersCreationForm', () => { }); it('validate duplicated attribute key', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); await fireEvent.click(result.getByRole('button', { name: 'Add attribute filter' })); await fireEvent.input(result.getByPlaceholderText('Key'), { target: { value: 'my-key' } }); await fireEvent.input(result.getByPlaceholderText('Value'), { target: { value: 'foo' } }); @@ -103,7 +103,7 @@ describe('FiltersCreationForm', () => { }); it('validate missing type filter key', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); result.component.init({}, {}); await fireEvent.click(result.getByRole('button', { name: 'Add type filter' })); expect(result.component.validateFields()).false; @@ -112,7 +112,7 @@ describe('FiltersCreationForm', () => { }); it('validate duplicated type filter key', async () => { - const result = render(FiltersCreationForm); + const result = render(AttributesTypesForm); result.component.init({}, {}); await fireEvent.click(result.getByRole('button', { name: 'Add type filter' })); await fireEvent.input(result.getByPlaceholderText('Key'), { target: { value: 'my-key' } }); diff --git a/src/lib/components/v2/projects/datasets/AddImageModal.svelte b/src/lib/components/v2/projects/datasets/AddImageModal.svelte index 59203b8f..ddfcbec8 100644 --- a/src/lib/components/v2/projects/datasets/AddImageModal.svelte +++ b/src/lib/components/v2/projects/datasets/AddImageModal.svelte @@ -1,7 +1,7 @@ {#if attributeFields.length > 0} -
Attribute filters
+
+ {#if filters} + Attribute filters + {:else} + Attributes + {/if} +
{/if} {#each attributeFields as field, index}
removeAttributeFilter(index)} - aria-label="Remove attribute filter" + on:click={() => removeAttribute(index)} + aria-label={filters ? 'Remove attribute filter' : 'Remove attribute'} > @@ -262,7 +270,13 @@ {/each} {#if typeFields.length > 0} -
Type filters
+
+ {#if filters} + Type filters + {:else} + Types + {/if} +
{/if} {#each typeFields as field, index}
@@ -270,7 +284,7 @@
removeTypeFilter(index)} - aria-label="Remove type filter" + on:click={() => removeType(index)} + aria-label={filters ? 'Remove type filter' : 'Remove type'} > @@ -304,11 +318,19 @@
- -
diff --git a/src/lib/components/v2/projects/datasets/CreateDatasetModal.svelte b/src/lib/components/v2/projects/datasets/CreateDatasetModal.svelte index 85790b3d..5b08219a 100644 --- a/src/lib/components/v2/projects/datasets/CreateDatasetModal.svelte +++ b/src/lib/components/v2/projects/datasets/CreateDatasetModal.svelte @@ -2,7 +2,7 @@ import { page } from '$app/stores'; import { AlertError } from '$lib/common/errors'; import Modal from '../../../common/Modal.svelte'; - import FiltersCreationForm from './FiltersCreationForm.svelte'; + import AttributesTypesForm from './AttributesTypesForm.svelte'; /** @type {(dataset: import('$lib/types-v2').DatasetV2) => void} */ export let createDatasetCallback; @@ -16,7 +16,7 @@ let saving = false; let creatingDataset = false; - /** @type {FiltersCreationForm} */ + /** @type {AttributesTypesForm} */ let filtersCreationForm; function onOpen() { @@ -131,7 +131,7 @@
- + diff --git a/src/lib/components/v2/projects/datasets/DatasetFiltersModal.svelte b/src/lib/components/v2/projects/datasets/DatasetFiltersModal.svelte index b8dc9b0b..a49a508c 100644 --- a/src/lib/components/v2/projects/datasets/DatasetFiltersModal.svelte +++ b/src/lib/components/v2/projects/datasets/DatasetFiltersModal.svelte @@ -2,7 +2,7 @@ import { page } from '$app/stores'; import { AlertError } from '$lib/common/errors'; import Modal from '$lib/components/common/Modal.svelte'; - import FiltersCreationForm from './FiltersCreationForm.svelte'; + import AttributesTypesForm from './AttributesTypesForm.svelte'; /** @type {import('$lib/types-v2').DatasetV2} */ export let dataset; @@ -12,7 +12,7 @@ /** @type {Modal} */ let modal; - /** @type {FiltersCreationForm} */ + /** @type {AttributesTypesForm} */ let filtersCreationForm; let saving = false; @@ -72,7 +72,7 @@ - + - - {/each} - + - {:else} + {:else if apiVersion === 'v1'} {/if}