diff --git a/.vscode/settings.json b/.vscode/settings.json index d471924fe0..f93d3f0886 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,8 @@ "editor.codeActionsOnSave": { "source.fixAll": true }, - "editor.defaultFormatter": "svelte.svelte-vscode" + "editor.defaultFormatter": "svelte.svelte-vscode", + "[javascript]": { + "editor.defaultFormatter": "vscode.typescript-language-features" + } } diff --git a/packages/backend-core/src/db/constants.js b/packages/backend-core/src/db/constants.js index 271d4f412d..0f3daa918c 100644 --- a/packages/backend-core/src/db/constants.js +++ b/packages/backend-core/src/db/constants.js @@ -15,6 +15,7 @@ exports.DocumentTypes = { ROLE: "role", MIGRATIONS: "migrations", DEV_INFO: "devinfo", + GROUP: "gr" } exports.StaticDatabases = { diff --git a/packages/backend-core/src/db/utils.js b/packages/backend-core/src/db/utils.js index d6eb0aa89e..212ada6e9a 100644 --- a/packages/backend-core/src/db/utils.js +++ b/packages/backend-core/src/db/utils.js @@ -148,6 +148,29 @@ exports.getTemplateParams = (ownerId, templateId, otherProps = {}) => { } } +/** + * Generates a new user group ID + * @returns {string} The new user group ID which info can be stored under. + */ +exports.generateUserGroupID = () => { + return `${DocumentTypes.GROUP}${SEPARATOR}${newid()}` +} + +/** + * Gets parameters for retrieving groups. + */ +exports.getUserGroupsParams = (groupId, otherProps = {}) => { + if (!groupId) { + groupId = "" + } + return { + ...otherProps, + startkey: `${DocumentTypes.GROUP}${SEPARATOR}${groupId}`, + endkey: `${DocumentTypes.GROUP}${SEPARATOR}${groupId}${UNICODE_MAX}`, + } +} + + /** * Generates a new role ID. * @returns {string} The new role ID which the role doc can be stored under. 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 c4f38f080b..a8fef775bf 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 @@ -20,7 +20,7 @@
- {parseInt(userCount)} app{parseInt(userCount) === 1 ? "" : "s"} + {parseInt(userCount)} user{parseInt(userCount) === 1 ? "" : "s"}
diff --git a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte index 63fcd105f3..560cf273e5 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte @@ -12,30 +12,37 @@ Tags, IconPicker, } from "@budibase/bbui" + import { API } from "api" + import { groups } from "stores/portal" + import { onMount } from "svelte" + import UserGroupsRow from "./_components/UserGroupsRow.svelte" + let modal let selectedColor let selectedIcon + let groupName let proPlan = true - let userGroupData = [ - { - _id: "gr_123456", - color: "green", - icon: "Anchor", - name: "Core Team", - userCount: 5, - appCount: 2, - }, - { - _id: "gr_45678", - color: "red", - icon: "Beaker", - name: "QA Team", - userCount: 3, - appCount: 7, - }, - ] + async function saveConfig() { + try { + API.saveGroup({ + color: selectedColor, + icon: selectedIcon, + name: groupName, + }) + } catch (error) { + notifications.error(`Failed to save group`) + } + } + + onMount(async () => { + try { + await groups.init() + } catch (error) { + notifications.error("Error getting User groups") + } + }) @@ -72,7 +79,7 @@
- {#each userGroupData as group} + {#each $groups as group}
@@ -81,8 +88,13 @@ - - + +