From 7cbcada862f5f907ba59d18bfffeef802f13aa7a Mon Sep 17 00:00:00 2001 From: James Kerr Date: Thu, 28 Mar 2024 09:12:20 -0700 Subject: [PATCH 1/3] Fix set from pin --- apps/zui/src/domain/session/handlers/pins.ts | 15 ++++++--------- apps/zui/src/models/session.ts | 14 +++++++------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/apps/zui/src/domain/session/handlers/pins.ts b/apps/zui/src/domain/session/handlers/pins.ts index 68ab000d4..1e52928cc 100644 --- a/apps/zui/src/domain/session/handlers/pins.ts +++ b/apps/zui/src/domain/session/handlers/pins.ts @@ -5,12 +5,12 @@ import {TimeRangeQueryPin} from "src/js/state/Editor/types" import Pools from "src/js/state/Pools" import Current from "src/js/state/Current" import PoolSettings from "src/js/state/PoolSettings" -import Tabs from "src/js/state/Tabs" import {submitSearch} from "src/domain/session/handlers" import {createHandler} from "src/core/handlers" import ZuiApi from "src/js/api/zui-api" import Selection from "src/js/state/Selection" -import {Snapshots} from "src/domain/handlers" +import {Session} from "src/models/session" +import {Active} from "src/models/active" export const createPinFromEditor = createHandler( "session.createPinFromEditor", @@ -43,13 +43,10 @@ export const createFromPin = createHandler( export const setFromPin = createHandler( "session.setFromPin", - ({dispatch, select}, value: string) => { - if (select(Tabs.none)) { - Snapshots.createAndShow({pins: [{type: "from", value}], value: ""}) - } else { - dispatch(Editor.setFrom(value)) - submitSearch() - } + ({dispatch}, value: string) => { + Session.activateLastFocused() + dispatch(Editor.setFrom(value)) + Active.session.navigate(Active.snapshot, Active.session.namedQuery) } ) diff --git a/apps/zui/src/models/session.ts b/apps/zui/src/models/session.ts index 451de7f67..85ba6ce78 100644 --- a/apps/zui/src/models/session.ts +++ b/apps/zui/src/models/session.ts @@ -37,20 +37,20 @@ export class Session extends DomainModel { return new Session({id}) } + get hasUrl() { + return !!this.parentId && !!this.snapshotId + } + get id() { return this.attrs.id } get parentId() { - if (!this.attrs.parentId) - throw new Error("Session has not yet navigated to a url") - else return this.attrs.parentId + return this.attrs.parentId } get snapshotId() { - if (!this.attrs.snapshotId) - throw new Error("Session has not yet navigated to a url") - else return this.attrs.snapshotId + return this.attrs.snapshotId } get pathname() { @@ -78,7 +78,7 @@ export class Session extends DomainModel { } get hasNamedQuery() { - return this.id !== this.parentId + return this.parentId && this.id !== this.parentId } get namedQuery() { From 4159b90d4edc150b6f0cbfe5bfea14374522332f Mon Sep 17 00:00:00 2001 From: James Kerr Date: Fri, 29 Mar 2024 08:29:58 -0700 Subject: [PATCH 2/3] Add e2e tests from set as from pin --- .../src/app/routes/app-wrapper/main-area.tsx | 8 +++++- .../src/js/components/TabBar/SearchTab.tsx | 3 ++ apps/zui/src/js/components/TabBar/TabBar.tsx | 7 ++++- packages/zui-player/helpers/test-app.ts | 6 ++++ .../zui-player/tests/set-as-from-pin.spec.ts | 28 +++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 packages/zui-player/tests/set-as-from-pin.spec.ts diff --git a/apps/zui/src/app/routes/app-wrapper/main-area.tsx b/apps/zui/src/app/routes/app-wrapper/main-area.tsx index 6c34d6dc6..27474c51b 100644 --- a/apps/zui/src/app/routes/app-wrapper/main-area.tsx +++ b/apps/zui/src/app/routes/app-wrapper/main-area.tsx @@ -47,7 +47,13 @@ export function MainArea({children}) { } return ( - + {children} ) diff --git a/apps/zui/src/js/components/TabBar/SearchTab.tsx b/apps/zui/src/js/components/TabBar/SearchTab.tsx index ec3ad070f..e91ca409c 100644 --- a/apps/zui/src/js/components/TabBar/SearchTab.tsx +++ b/apps/zui/src/js/components/TabBar/SearchTab.tsx @@ -40,6 +40,9 @@ const SearchTab = React.forwardRef(function SearchTab(
diff --git a/apps/zui/src/js/components/TabBar/TabBar.tsx b/apps/zui/src/js/components/TabBar/TabBar.tsx index 51a5e16d6..48355738f 100644 --- a/apps/zui/src/js/components/TabBar/TabBar.tsx +++ b/apps/zui/src/js/components/TabBar/TabBar.tsx @@ -83,7 +83,12 @@ export default function TabBar() { )} {sidebarCollapsed && !global.env.isMac && } - + {ids.map((id: string) => { const tabModel = tab(id, lakes, pools, queryIdNameMap, lakeId) return ( diff --git a/packages/zui-player/helpers/test-app.ts b/packages/zui-player/helpers/test-app.ts index 79dea2208..bcc2f6c51 100644 --- a/packages/zui-player/helpers/test-app.ts +++ b/packages/zui-player/helpers/test-app.ts @@ -129,6 +129,12 @@ export default class TestApp { return await this.mainWin.getByTestId('main-editor').textContent(); } + async getTabCount() { + const tablist = this.page.locator('[role=tablist][id=main-area-tabs]'); + const tabs = tablist.getByRole('tab'); + return await tabs.count(); + } + async getViewerResults(includeHeaders = true): Promise { const fields = await this.mainWin.locator('.zed-table__cell'); await fields.waitFor(); diff --git a/packages/zui-player/tests/set-as-from-pin.spec.ts b/packages/zui-player/tests/set-as-from-pin.spec.ts new file mode 100644 index 000000000..62d374fa2 --- /dev/null +++ b/packages/zui-player/tests/set-as-from-pin.spec.ts @@ -0,0 +1,28 @@ +import { play } from 'zui-player'; +import { getPath } from 'zui-test-data'; + +play('Set As From Pin', (app, test) => { + test('when no session tab exists', async () => { + // it creates a session tab + await app.dropFile(getPath('small-zeek.zng')); + await app.click('button', 'Load'); + await app.attached(/Successfully/); + await app.rightClick('treeitem', 'small-zeek.zng'); + const tabCount = await app.getTabCount(); + await app.click('listitem', 'Use as From Pin'); + await app.attached('button', 'from small-zeek.zng'); + test.expect(await app.getTabCount()).toBe(tabCount + 1); + }); + + test('when a session tab does exists', async () => { + // it re-uses the existing session tab + await app.dropFile(getPath('small-zeek.zng')); + await app.click('button', 'Load'); + await app.attached(/Successfully/); + await app.rightClick('treeitem', 'small-zeek.zng_1'); + const tabCount = await app.getTabCount(); + await app.click('listitem', 'Use as From Pin'); + await app.attached('button', 'from small-zeek.zng_1'); + test.expect(await app.getTabCount()).toBe(tabCount); + }); +}); From 0b0c14fbfd5f046fe79e7c06171bc341441cdc07 Mon Sep 17 00:00:00 2001 From: James Kerr Date: Fri, 29 Mar 2024 09:23:41 -0700 Subject: [PATCH 3/3] Update packages/zui-player/tests/set-as-from-pin.spec.ts Co-authored-by: Phil Rzewski --- packages/zui-player/tests/set-as-from-pin.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zui-player/tests/set-as-from-pin.spec.ts b/packages/zui-player/tests/set-as-from-pin.spec.ts index 62d374fa2..90e707972 100644 --- a/packages/zui-player/tests/set-as-from-pin.spec.ts +++ b/packages/zui-player/tests/set-as-from-pin.spec.ts @@ -14,7 +14,7 @@ play('Set As From Pin', (app, test) => { test.expect(await app.getTabCount()).toBe(tabCount + 1); }); - test('when a session tab does exists', async () => { + test('when a session tab does exist', async () => { // it re-uses the existing session tab await app.dropFile(getPath('small-zeek.zng')); await app.click('button', 'Load');