From 1e675478af519d8db643505a8f7dd04016beee9f Mon Sep 17 00:00:00 2001 From: James Kerr Date: Mon, 25 Jan 2021 19:40:13 -0800 Subject: [PATCH] Account for No Windows when Migrating Queries (#1387) * account for no windows in the migration * Only migrate data if there is data --- src/js/electron/tron/migrations.ts | 2 +- .../202101201109_moveQueriesStateToGlobal.test.ts | 8 ++++++++ .../migrations/202101201109_moveQueriesStateToGlobal.ts | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/js/electron/tron/migrations.ts b/src/js/electron/tron/migrations.ts index 1785cc4b26..fe81734a5e 100644 --- a/src/js/electron/tron/migrations.ts +++ b/src/js/electron/tron/migrations.ts @@ -42,7 +42,7 @@ export default async function migrations( run(state: VersionedData, migrations: Migration[]) { for (const {version, migrate} of migrations) { - state.data = migrate(state.data) + state.data = state.data ? migrate(state.data) : undefined state.version = version } return state diff --git a/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.test.ts b/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.test.ts index 3670deeda1..8234bda320 100644 --- a/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.test.ts +++ b/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.test.ts @@ -1,6 +1,14 @@ import getTestState from "../../test/helpers/getTestState" import migrate from "./202101201109_moveQueriesStateToGlobal" +test("when there are no windows", () => { + const {data} = getTestState("v0.22.0") + data.windows = {} + data.order = [] + const next = migrate(data) + expect(next.globalState.queries).toBe(undefined) +}) + test("migrating 202101201109_moveQueriesStateToGlobal", () => { let {data} = getTestState("v0.22.0") diff --git a/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.ts b/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.ts index 2a45d9d246..58e633516f 100644 --- a/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.ts +++ b/src/js/state/migrations/202101201109_moveQueriesStateToGlobal.ts @@ -4,6 +4,13 @@ export default function moveQueriesStateToGlobal(state: any) { // Migrate state here const mergedQueryMap = {} const mergedQueryItems = [] + const windows = Object.values(state.windows) + + if (windows.length === 0) { + state.globalState.queries = undefined + return state + } + for (const s of getAllStates(state)) { if (!s.queries) continue s.queries.items.forEach((q) => {