Browse Source

fix save search query

pull/4654/head
Ekaterina Balakina 2 years ago
parent
commit
812b82f853
  1. 5
      packages/nc-gui/components/smartsheet/toolbar/SearchData.vue
  2. 21
      packages/nc-gui/composables/useFieldQuery.ts
  3. 2
      packages/nc-gui/composables/useSmartsheetStore.ts
  4. 20
      tests/playwright/pages/Dashboard/common/Toolbar/SearchData.ts
  5. 3
      tests/playwright/pages/Dashboard/common/Toolbar/index.ts
  6. 49
      tests/playwright/tests/views.spec.ts

5
packages/nc-gui/components/smartsheet/toolbar/SearchData.vue

@ -17,7 +17,7 @@ const { meta } = useSmartsheetStoreOrThrow()
const activeView = inject(ActiveViewInj, ref()) const activeView = inject(ActiveViewInj, ref())
const { search, loadFieldQuery } = useFieldQuery(activeView) const { search, loadFieldQuery } = useFieldQuery()
const isDropdownOpen = ref(false) const isDropdownOpen = ref(false)
@ -36,7 +36,7 @@ watch(
() => activeView.value?.id, () => activeView.value?.id,
(n, o) => { (n, o) => {
if (n !== o) { if (n !== o) {
loadFieldQuery(activeView) loadFieldQuery(activeView.value?.id)
} }
}, },
{ immediate: true }, { immediate: true },
@ -76,6 +76,7 @@ function onPressEnter() {
class="max-w-[200px]" class="max-w-[200px]"
:placeholder="$t('placeholder.filterQuery')" :placeholder="$t('placeholder.filterQuery')"
:bordered="false" :bordered="false"
data-testid="search-data-input"
@press-enter="onPressEnter" @press-enter="onPressEnter"
> >
<template #addonBefore> </template> <template #addonBefore> </template>

21
packages/nc-gui/composables/useFieldQuery.ts

@ -1,8 +1,6 @@
import type { Ref } from 'vue'
import type { ViewType } from 'nocodb-sdk'
import { useState } from '#imports' import { useState } from '#imports'
export function useFieldQuery(view: Ref<ViewType | undefined>) { export function useFieldQuery() {
// initial search object // initial search object
const emptyFieldQueryObj = { const emptyFieldQueryObj = {
field: '', field: '',
@ -13,21 +11,16 @@ export function useFieldQuery(view: Ref<ViewType | undefined>) {
const searchMap = useState<Record<string, { field: string; query: string }>>('field-query-search-map', () => ({})) const searchMap = useState<Record<string, { field: string; query: string }>>('field-query-search-map', () => ({}))
// the fieldQueryObj under the current view // the fieldQueryObj under the current view
const search = useState<{ field: string; query: string }>('field-query-search', () => emptyFieldQueryObj) const search = useState<{ field: string; query: string }>('field-query-search', () => ({ ...emptyFieldQueryObj }))
// map current view id to emptyFieldQueryObj
if (view?.value?.id) {
searchMap.value[view!.value!.id] = search.value
}
// retrieve the fieldQueryObj of the given view id // retrieve the fieldQueryObj of the given view id
// if it is not found in `searchMap`, init with emptyFieldQueryObj // if it is not found in `searchMap`, init with emptyFieldQueryObj
const loadFieldQuery = (view: Ref<ViewType | undefined>) => { const loadFieldQuery = (id?: string) => {
if (!view.value?.id) return if (!id) return
if (!(view!.value!.id in searchMap.value)) { if (!(id in searchMap.value)) {
searchMap.value[view!.value!.id!] = emptyFieldQueryObj searchMap.value[id] = { ...emptyFieldQueryObj }
} }
search.value = searchMap.value[view!.value!.id!] search.value = searchMap.value[id]
} }
return { search, loadFieldQuery } return { search, loadFieldQuery }

2
packages/nc-gui/composables/useSmartsheetStore.ts

@ -19,7 +19,7 @@ const [useProvideSmartsheetStore, useSmartsheetStore] = useInjectionState(
const cellRefs = ref<HTMLTableDataCellElement[]>([]) const cellRefs = ref<HTMLTableDataCellElement[]>([])
const { search } = useFieldQuery(view) const { search } = useFieldQuery()
const eventBus = useEventBus<SmartsheetStoreEvents>(Symbol('SmartsheetStore')) const eventBus = useEventBus<SmartsheetStoreEvents>(Symbol('SmartsheetStore'))

20
tests/playwright/pages/Dashboard/common/Toolbar/SearchData.ts

@ -0,0 +1,20 @@
import BasePage from '../../../Base';
import { ToolbarPage } from './index';
import { expect } from '@playwright/test';
export class ToolbarSearchDataPage extends BasePage {
readonly toolbar: ToolbarPage;
constructor(toolbar: ToolbarPage) {
super(toolbar.rootPage);
this.toolbar = toolbar;
}
get() {
return this.rootPage.getByTestId('search-data-input');
}
async verify(query: string) {
await expect(await this.get().inputValue()).toBe(query);
}
}

3
tests/playwright/pages/Dashboard/common/Toolbar/index.ts

@ -13,6 +13,7 @@ import { KanbanPage } from '../../Kanban';
import { FormPage } from '../../Form'; import { FormPage } from '../../Form';
import { ToolbarStackbyPage } from './StackBy'; import { ToolbarStackbyPage } from './StackBy';
import { ToolbarAddEditStackPage } from './AddEditKanbanStack'; import { ToolbarAddEditStackPage } from './AddEditKanbanStack';
import { ToolbarSearchDataPage } from './SearchData';
export class ToolbarPage extends BasePage { export class ToolbarPage extends BasePage {
readonly parent: GridPage | GalleryPage | FormPage | KanbanPage; readonly parent: GridPage | GalleryPage | FormPage | KanbanPage;
@ -24,6 +25,7 @@ export class ToolbarPage extends BasePage {
readonly actions: ToolbarActionsPage; readonly actions: ToolbarActionsPage;
readonly stackBy: ToolbarStackbyPage; readonly stackBy: ToolbarStackbyPage;
readonly addEditStack: ToolbarAddEditStackPage; readonly addEditStack: ToolbarAddEditStackPage;
readonly searchData: ToolbarSearchDataPage;
constructor(parent: GridPage | GalleryPage | FormPage | KanbanPage) { constructor(parent: GridPage | GalleryPage | FormPage | KanbanPage) {
super(parent.rootPage); super(parent.rootPage);
@ -36,6 +38,7 @@ export class ToolbarPage extends BasePage {
this.actions = new ToolbarActionsPage(this); this.actions = new ToolbarActionsPage(this);
this.stackBy = new ToolbarStackbyPage(this); this.stackBy = new ToolbarStackbyPage(this);
this.addEditStack = new ToolbarAddEditStackPage(this); this.addEditStack = new ToolbarAddEditStackPage(this);
this.searchData = new ToolbarSearchDataPage(this);
} }
get() { get() {

49
tests/playwright/tests/views.spec.ts

@ -1,14 +1,17 @@
import { test } from '@playwright/test'; import { expect, test } from '@playwright/test';
import { DashboardPage } from '../pages/Dashboard'; import { DashboardPage } from '../pages/Dashboard';
import { ToolbarPage } from '../pages/Dashboard/common/Toolbar';
import setup from '../setup'; import setup from '../setup';
test.describe('Views CRUD Operations', () => { test.describe('Views CRUD Operations', () => {
let dashboard: DashboardPage; let dashboard: DashboardPage;
let context: any; let context: any;
let toolbar: ToolbarPage;
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
context = await setup({ page }); context = await setup({ page });
dashboard = new DashboardPage(page, context.project); dashboard = new DashboardPage(page, context.project);
toolbar = dashboard.grid.toolbar;
}); });
test('Create views, reorder and delete', async () => { test('Create views, reorder and delete', async () => {
@ -73,4 +76,48 @@ test.describe('Views CRUD Operations', () => {
index: 1, index: 1,
}); });
}); });
test('Save search query for each table and view', async () => {
await dashboard.treeView.openTable({ title: 'City' });
await toolbar.searchData.verify('');
await toolbar.searchData.get().fill('City-City');
await toolbar.searchData.verify('City-City');
await dashboard.viewSidebar.createGridView({ title: 'CityGrid' });
await toolbar.searchData.verify('');
await toolbar.searchData.get().fill('City-CityGrid');
await toolbar.searchData.verify('City-CityGrid');
await dashboard.viewSidebar.createGridView({ title: 'CityGrid2' });
await toolbar.searchData.verify('');
await toolbar.searchData.get().fill('City-CityGrid2');
await toolbar.searchData.verify('City-CityGrid2');
await dashboard.viewSidebar.openView({ title: 'CityGrid' });
await expect(dashboard.get().locator('[data-testid="grid-load-spinner"]')).toBeVisible();
await dashboard.grid.waitLoading();
await toolbar.searchData.verify('City-CityGrid');
await dashboard.viewSidebar.openView({ title: 'City' });
await expect(dashboard.get().locator('[data-testid="grid-load-spinner"]')).toBeVisible();
await dashboard.grid.waitLoading();
await toolbar.searchData.verify('City-City');
await dashboard.treeView.openTable({ title: 'Actor' });
await toolbar.searchData.verify('');
await dashboard.viewSidebar.createGridView({ title: 'ActorGrid' });
await toolbar.searchData.verify('');
await toolbar.searchData.get().fill('Actor-ActorGrid');
await toolbar.searchData.verify('Actor-ActorGrid');
await dashboard.viewSidebar.openView({ title: 'Actor' });
await expect(dashboard.get().locator('[data-testid="grid-load-spinner"]')).toBeVisible();
await dashboard.grid.waitLoading();
await toolbar.searchData.verify('');
await dashboard.treeView.openTable({ title: 'City', mode: '' });
await toolbar.searchData.verify('City-City');
});
}); });

Loading…
Cancel
Save