From 98607ca1bdec1a7f1f578e0661b5f20972e61671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Mon, 22 Mar 2021 10:55:23 +0100 Subject: [PATCH] moves roles in backendstore to a separate store --- .../builder/src/builderStore/store/backend.js | 27 ----------------- .../src/builderStore/store/backend/roles.js | 30 +++++++++++++++++++ .../backend/DataTable/cells/RoleCell.svelte | 4 +-- .../DataTable/modals/CreateEditUser.svelte | 3 +- .../backend/DataTable/modals/EditRoles.svelte | 12 ++++---- .../popovers/ManageAccessPopover.svelte | 3 +- .../FrontendNavigatePane.svelte | 4 +-- .../NavigationPanel/NewScreenModal.svelte | 3 +- .../PropertyControls/RoleSelect.svelte | 4 +-- .../src/pages/[application]/_reset.svelte | 3 +- 10 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 packages/builder/src/builderStore/store/backend/roles.js diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index d7cc857483..0eb5aaaf7a 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -1,12 +1,10 @@ import { writable, get } from "svelte/store" import { cloneDeep } from "lodash/fp" import api from "../api" -import { permissions } from './backend/permissions' const INITIAL_BACKEND_UI_STATE = { tables: [], views: [], - roles: [], datasources: [], queries: [], integrations: {}, @@ -50,11 +48,6 @@ export const getBackendUiStore = () => { state.selectedView = state.selectedView return state }), - select: row => - store.update(state => { - state.selectedRow = row - return state - }), }, datasources: { fetch: async () => { @@ -301,26 +294,6 @@ export const getBackendUiStore = () => { }) }, }, - roles: { - fetch: async () => { - const response = await api.get("/api/roles") - const roles = await response.json() - store.update(state => { - state.roles = roles - return state - }) - }, - delete: async role => { - const response = await api.delete(`/api/roles/${role._id}/${role._rev}`) - await store.actions.roles.fetch() - return response - }, - save: async role => { - const response = await api.post("/api/roles", role) - await store.actions.roles.fetch() - return response - }, - }, permissions: { fetchLevels: async () => { const response = await api.get("/api/permission/levels") diff --git a/packages/builder/src/builderStore/store/backend/roles.js b/packages/builder/src/builderStore/store/backend/roles.js new file mode 100644 index 0000000000..fc8bf57b23 --- /dev/null +++ b/packages/builder/src/builderStore/store/backend/roles.js @@ -0,0 +1,30 @@ +import { writable } from "svelte/store" +import api from "../../api" + +function createRolesStore() { + const { subscribe, set } = writable([]) + + return { + subscribe, + fetch: async () => { + set(await getRoles()) + }, + delete: async role => { + const response = await api.delete(`/api/roles/${role._id}/${role._rev}`) + set(await getRoles()) + return response + }, + save: async role => { + const response = await api.post("/api/roles", role) + set(await getRoles()) + return response + }, + } +} + +async function getRoles() { + const response = await api.get("/api/roles") + return await response.json() +} + +export const roles = createRolesStore() diff --git a/packages/builder/src/components/backend/DataTable/cells/RoleCell.svelte b/packages/builder/src/components/backend/DataTable/cells/RoleCell.svelte index a45f376a3e..784272c534 100644 --- a/packages/builder/src/components/backend/DataTable/cells/RoleCell.svelte +++ b/packages/builder/src/components/backend/DataTable/cells/RoleCell.svelte @@ -1,9 +1,9 @@ diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditUser.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditUser.svelte index db92abc065..61da9f61bf 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditUser.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditUser.svelte @@ -1,5 +1,6 @@ diff --git a/packages/builder/src/pages/[application]/_reset.svelte b/packages/builder/src/pages/[application]/_reset.svelte index 2411fad0c9..8e34989a23 100644 --- a/packages/builder/src/pages/[application]/_reset.svelte +++ b/packages/builder/src/pages/[application]/_reset.svelte @@ -1,5 +1,6 @@