diff --git a/packages/backend-core/src/db/constants.js b/packages/backend-core/src/db/constants.js index 0f3daa918c..4f2f1f556a 100644 --- a/packages/backend-core/src/db/constants.js +++ b/packages/backend-core/src/db/constants.js @@ -15,7 +15,7 @@ exports.DocumentTypes = { ROLE: "role", MIGRATIONS: "migrations", DEV_INFO: "devinfo", - GROUP: "gr" + GROUP: "gr", } exports.StaticDatabases = { diff --git a/packages/backend-core/src/db/utils.js b/packages/backend-core/src/db/utils.js index 212ada6e9a..3e879cd004 100644 --- a/packages/backend-core/src/db/utils.js +++ b/packages/backend-core/src/db/utils.js @@ -170,7 +170,6 @@ exports.getUserGroupsParams = (groupId, otherProps = {}) => { } } - /** * Generates a new role ID. * @returns {string} The new role ID which the role doc can be stored under. diff --git a/packages/bbui/src/IconPicker/IconPicker.svelte b/packages/bbui/src/IconPicker/IconPicker.svelte index 954145b42d..0b96cbe4c9 100644 --- a/packages/bbui/src/IconPicker/IconPicker.svelte +++ b/packages/bbui/src/IconPicker/IconPicker.svelte @@ -4,6 +4,7 @@ import clickOutside from "../Actions/click_outside" import { fly } from "svelte/transition" import Icon from "../Icon/Icon.svelte" + import { createEventDispatcher } from "svelte" export let value = "Anchor" export let size = "M" @@ -11,7 +12,7 @@ let open = false - // const dispatch = createEventDispatcher() + const dispatch = createEventDispatcher() const iconList = [ { @@ -44,12 +45,11 @@ ], }, ] - /* + const onChange = value => { dispatch("change", value) open = false } -*/
@@ -76,7 +76,7 @@ {#each icon.icons as icon}
{ - value = icon + onChange(icon) }} > 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 d33f144680..21169c6513 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -11,50 +11,66 @@ Search, Divider, Detail, + notifications, } from "@budibase/bbui" import UserRow from "./_components/UserRow.svelte" - import { users } from "stores/portal" + import { users, apps, groups } from "stores/portal" import { onMount } from "svelte" + import GroupAppsRow from "./_components/GroupAppsRow.svelte" + export let groupId let popoverAnchor let popover + $: group = $groups.find(x => x._id === groupId) let searchTerm = "" let selectedUsers = [] - $: filteredUsers = $users.filter(user => - user?.email?.toLowerCase().includes(searchTerm.toLowerCase()) + $: filteredUsers = $users.filter( + user => + selectedUsers && + user?.email?.toLowerCase().includes(searchTerm.toLowerCase()) ) - - let group = { - _id: "gr_123456", - color: "green", - icon: "Anchor", - name: "Core Team", - userCount: 5, - appCount: 2, - } - - let groupUsers = [ + let app_list = [ { - email: "peter@budibase.com", access: "Developer", + name: "test app", + icon: "Anchor", + color: "blue", }, ] - /* - function getGroup() { - return + async function addAll() { + selectedUsers = [...selectedUsers, ...filteredUsers] + group.users = selectedUsers + await groups.actions.save(group) } - */ - function selectUser(id) { - let user = selectedUsers.find(user_id => user_id === id) - if (user) { - selectedUsers = selectedUsers.filter(id => id !== user) + + async function selectUser(id) { + let selectedUser = selectedUsers.find(user_id => user_id === id) + let enrichedUser = $users.find(user => user._id === id) + if (selectedUser) { + selectedUsers = selectedUsers.filter(id => id !== selectedUser) + let newUsers = group.users.filter(user => user._id !== id) + group.users = newUsers } else { selectedUsers = [...selectedUsers, id] + group.users.push(enrichedUser) } + await groups.actions.save(group) } - onMount(() => { - console.log($users) + + async function removeUser(id) { + let newUsers = group.users.filter(user => user._id !== id) + group.users = newUsers + await groups.actions.save(group) + } + onMount(async () => { + try { + await groups.actions.init() + await users.init() + await apps.load() + } catch (error) { + notifications.error("Error fetching User Group data") + } }) @@ -66,13 +82,13 @@
-
+
- +
- {group.name} + {group?.name}
@@ -90,7 +106,9 @@ >
- Add all + Add all
@@ -121,10 +139,39 @@
- {#if groupUsers.length} - {#each groupUsers as user} + {#if group?.users.length} + {#each group.users as user}
- + +
+ {/each} + {:else} +
+
+ +
+ You have no users in this team +
+
+
+ {/if} +
+
+ Apps +
+ Manage apps that this User group has been assigned to +
+
+ +
+ {#if app_list.length} + {#each app_list as app} +
+
{/each} {:else} diff --git a/packages/builder/src/pages/builder/portal/manage/groups/_components/CreateEditGroupModal.svelte b/packages/builder/src/pages/builder/portal/manage/groups/_components/CreateEditGroupModal.svelte new file mode 100644 index 0000000000..c34731d0e5 --- /dev/null +++ b/packages/builder/src/pages/builder/portal/manage/groups/_components/CreateEditGroupModal.svelte @@ -0,0 +1,58 @@ + + + saveGroup(group)} + size="M" + title="Create User Group" + confirmText="Save" +> + + + + + diff --git a/packages/builder/src/pages/builder/portal/manage/groups/_components/GroupAppsRow.svelte b/packages/builder/src/pages/builder/portal/manage/groups/_components/GroupAppsRow.svelte new file mode 100644 index 0000000000..6c400c03fe --- /dev/null +++ b/packages/builder/src/pages/builder/portal/manage/groups/_components/GroupAppsRow.svelte @@ -0,0 +1,58 @@ + + +
+
+
+ +
+
+
+
+
+ {app.name} +
+ {app.access} +
+
+
+
+
+ + {app.access} +
+ + diff --git a/packages/builder/src/pages/builder/portal/manage/groups/_components/UserGroupsRow.svelte b/packages/builder/src/pages/builder/portal/manage/groups/_components/UserGroupsRow.svelte index a8fef775bf..ff3519516f 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/_components/UserGroupsRow.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/_components/UserGroupsRow.svelte @@ -1,50 +1,87 @@
-
+
- +
-
{name}
+
+ {group.name} +
- {parseInt(userCount)} user{parseInt(userCount) === 1 ? "" : "s"} + {parseInt(group.userCount) || 0} user{parseInt(group.userCount) === 1 + ? "" + : "s"}
-
- {parseInt(appCount)} app{parseInt(appCount) === 1 ? "" : "s"} +
+ {parseInt(group.appCount) || 0} app{parseInt(group.appCount) === 1 + ? "" + : "s"}
-
+
+
+ + + + + deleteGroup(group)} icon="Delete" + >Delete + editGroup(group)} icon="Delete">Edit + +
+ + + +