From 7484cdfb59a05cd038f28e8318bbfb52b303b601 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 26 Sep 2022 17:54:00 +0100 Subject: [PATCH] Feature to allow adding apps from within the groups interface, rather than having to go to apps individually to do this. --- packages/backend-core/src/db/conversions.js | 1 + .../portal/manage/groups/[groupId].svelte | 30 +++++++++-- .../groups/_components/AppAddModal.svelte | 51 +++++++++++++++++++ packages/builder/src/stores/backend/roles.js | 22 +++++--- packages/frontend-core/src/api/roles.js | 9 ++++ .../src/api/controllers/global/roles.js | 3 +- 6 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 packages/builder/src/pages/builder/portal/manage/groups/_components/AppAddModal.svelte diff --git a/packages/backend-core/src/db/conversions.js b/packages/backend-core/src/db/conversions.js index 90c04e9251..5b1a785ecc 100644 --- a/packages/backend-core/src/db/conversions.js +++ b/packages/backend-core/src/db/conversions.js @@ -36,6 +36,7 @@ exports.getDevelopmentAppID = appId => { const rest = split.join(APP_PREFIX) return `${APP_DEV_PREFIX}${rest}` } +exports.getDevAppID = exports.getDevelopmentAppID /** * Convert a development app ID to a deployed app ID. diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index 23cdbff877..92d270931d 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -25,6 +25,7 @@ import ConfirmDialog from "components/common/ConfirmDialog.svelte" import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte" import GroupIcon from "./_components/GroupIcon.svelte" + import AppAddModal from "./_components/AppAddModal.svelte" export let groupId @@ -34,8 +35,7 @@ let prevSearch = undefined let pageInfo = createPaginationStore() let loaded = false - let editModal - let deleteModal + let editModal, deleteModal, appAddModal $: page = $pageInfo.page $: fetchUsers(page, searchTerm) @@ -182,7 +182,14 @@ - Apps +
+ Apps +
+ +
+
{#if groupApps.length} {#each groupApps as app} @@ -203,6 +210,18 @@ {getRoleLabel(app.appId)} + { + groups.actions.removeApp( + groupId, + apps.getProdAppID(app.appId) + ) + e.stopPropagation() + }} + hoverable + size="S" + name="Close" + /> {/each} {:else} @@ -216,6 +235,11 @@ + + + + + + import { Body, ModalContent, Select } from "@budibase/bbui" + import { apps, groups } from "stores/portal" + import { roles } from "stores/backend" + import RoleSelect from "components/common/RoleSelect.svelte" + + export let group + + $: appOptions = $apps.map(app => ({ + label: app.name, + value: app, + })) + $: prodAppId = selectedApp ? apps.getProdAppID(selectedApp.appId) : "" + $: confirmDisabled = + (!selectingRole && !selectedApp) || (selectingRole && !selectedRoleId) + let selectedApp, selectedRoleId + let selectingRole = false + + async function appSelected() { + if (!selectingRole) { + selectingRole = true + await roles.fetchByAppId(prodAppId) + // return false to stop closing modal + return false + } else { + await groups.actions.addApp(group._id, prodAppId, selectedRoleId) + } + } + + + (selectingRole = false)} + disabled={confirmDisabled} +> + {#if !selectingRole} + Select the app to add to the "{group.name}" group. +