diff --git a/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditQueryPopover.svelte b/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditQueryPopover.svelte index 98bc7e6c83..78e8da400b 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditQueryPopover.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditQueryPopover.svelte @@ -14,7 +14,7 @@ async function duplicateQuery() { try { - await queries.duplicate(query, queries.save) + await queries.duplicate(query) } catch (e) { notifications.error(e.message) } diff --git a/packages/builder/src/stores/backend/queries.js b/packages/builder/src/stores/backend/queries.js index d07f6d2f6c..d45c9d4c8e 100644 --- a/packages/builder/src/stores/backend/queries.js +++ b/packages/builder/src/stores/backend/queries.js @@ -13,10 +13,7 @@ export function createQueriesStore() { const store = writable({ list: [], selected: null }) const { subscribe, set, update } = store - return { - subscribe, - set, - update, + const actions = { init: async () => { const response = await api.get(`/api/queries`) const json = await response.json() @@ -86,7 +83,7 @@ export function createQueriesStore() { }) return response }, - duplicate: async (query, saveFn) => { + duplicate: async query => { let list = get(store).list const newQuery = { ...query } const datasourceId = query.datasourceId @@ -98,9 +95,16 @@ export function createQueriesStore() { list.map(q => q.name) ) - saveFn(datasourceId, newQuery) + actions.save(datasourceId, newQuery) }, } + + return { + subscribe, + set, + update, + ...actions, + } } export const queries = createQueriesStore() diff --git a/packages/builder/src/stores/backend/tests/queries.spec.js b/packages/builder/src/stores/backend/tests/queries.spec.js index 1d1a1d0154..b4c1805c66 100644 --- a/packages/builder/src/stores/backend/tests/queries.spec.js +++ b/packages/builder/src/stores/backend/tests/queries.spec.js @@ -6,7 +6,6 @@ jest.mock('builderStore/api'); import { SOME_QUERY, SAVE_QUERY_RESPONSE } from './fixtures/queries' import { createQueriesStore } from "../queries" -import { datasources } from '../datasources' describe("Queries Store", () => { let store = createQueriesStore()