PR feedback
This commit is contained in:
parent
9755d40203
commit
4949ea1bcd
|
@ -18,7 +18,7 @@
|
||||||
auth,
|
auth,
|
||||||
groups,
|
groups,
|
||||||
licensing,
|
licensing,
|
||||||
enriched as enrichedApps,
|
enrichedApps,
|
||||||
} from "stores/portal"
|
} from "stores/portal"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import { AppStatus } from "constants"
|
import { AppStatus } from "constants"
|
||||||
|
|
|
@ -21,8 +21,22 @@
|
||||||
{size}
|
{size}
|
||||||
on:click={async e => {
|
on:click={async e => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
const userAppFavourites = new Set([...($auth.user.appFavourites || [])])
|
||||||
|
let processedAppIds = []
|
||||||
|
|
||||||
|
if ($auth.user.appFavourites && app?.appId) {
|
||||||
|
if (userAppFavourites.has(app.appId)) {
|
||||||
|
userAppFavourites.delete(app.appId)
|
||||||
|
} else {
|
||||||
|
userAppFavourites.add(app.appId)
|
||||||
|
}
|
||||||
|
processedAppIds = [...userAppFavourites]
|
||||||
|
} else {
|
||||||
|
processedAppIds = [app.appId]
|
||||||
|
}
|
||||||
|
|
||||||
await auth.updateSelf({
|
await auth.updateSelf({
|
||||||
appFavourites: [app?.appId],
|
appFavourites: processedAppIds,
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
disabled={!app}
|
disabled={!app}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { params, goto } from "@roxi/routify"
|
import { params, goto } from "@roxi/routify"
|
||||||
import {
|
import { auth, sideBarCollapsed, enrichedApps } from "stores/portal"
|
||||||
auth,
|
|
||||||
sideBarCollapsed,
|
|
||||||
enriched as enrichedApps,
|
|
||||||
} from "stores/portal"
|
|
||||||
import AppRowContext from "components/start/AppRowContext.svelte"
|
import AppRowContext from "components/start/AppRowContext.svelte"
|
||||||
import FavouriteAppButton from "../FavouriteAppButton.svelte"
|
import FavouriteAppButton from "../FavouriteAppButton.svelte"
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import {
|
import { sideBarCollapsed, enrichedApps, auth } from "stores/portal"
|
||||||
sideBarCollapsed,
|
|
||||||
enriched as enrichedApps,
|
|
||||||
auth,
|
|
||||||
} from "stores/portal"
|
|
||||||
import { params, goto } from "@roxi/routify"
|
import { params, goto } from "@roxi/routify"
|
||||||
import NavItem from "components/common/NavItem.svelte"
|
import NavItem from "components/common/NavItem.svelte"
|
||||||
import NavHeader from "components/common/NavHeader.svelte"
|
import NavHeader from "components/common/NavHeader.svelte"
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
admin,
|
admin,
|
||||||
licensing,
|
licensing,
|
||||||
environment,
|
environment,
|
||||||
enriched as enrichedApps,
|
enrichedApps,
|
||||||
} from "stores/portal"
|
} from "stores/portal"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import AppRow from "components/start/AppRow.svelte"
|
import AppRow from "components/start/AppRow.svelte"
|
||||||
|
|
|
@ -141,7 +141,7 @@ export class AppsStore extends BudiStore {
|
||||||
export const appsStore = new AppsStore()
|
export const appsStore = new AppsStore()
|
||||||
|
|
||||||
// Centralise any logic that enriches the apps list
|
// Centralise any logic that enriches the apps list
|
||||||
export const enriched = derived([appsStore, auth], ([$store, $auth]) => {
|
export const enrichedApps = derived([appsStore, auth], ([$store, $auth]) => {
|
||||||
const enrichedApps = $store.apps
|
const enrichedApps = $store.apps
|
||||||
? $store.apps.map(app => ({
|
? $store.apps.map(app => ({
|
||||||
...app,
|
...app,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { writable } from "svelte/store"
|
||||||
export { organisation } from "./organisation"
|
export { organisation } from "./organisation"
|
||||||
export { users } from "./users"
|
export { users } from "./users"
|
||||||
export { admin } from "./admin"
|
export { admin } from "./admin"
|
||||||
export { appsStore, enriched } from "./apps"
|
export { appsStore, enrichedApps } from "./apps"
|
||||||
export { email } from "./email"
|
export { email } from "./email"
|
||||||
export { auth } from "./auth"
|
export { auth } from "./auth"
|
||||||
export { oidc } from "./oidc"
|
export { oidc } from "./oidc"
|
||||||
|
|
|
@ -59,7 +59,6 @@ import sdk from "../../sdk"
|
||||||
import { builderSocket } from "../../websockets"
|
import { builderSocket } from "../../websockets"
|
||||||
import { sdk as sharedCoreSDK } from "@budibase/shared-core"
|
import { sdk as sharedCoreSDK } from "@budibase/shared-core"
|
||||||
import * as appMigrations from "../../appMigrations"
|
import * as appMigrations from "../../appMigrations"
|
||||||
import { cloneDeep } from "lodash"
|
|
||||||
|
|
||||||
// utility function, need to do away with this
|
// utility function, need to do away with this
|
||||||
async function getLayouts() {
|
async function getLayouts() {
|
||||||
|
@ -684,7 +683,7 @@ export async function duplicateApp(
|
||||||
const createRequest = {
|
const createRequest = {
|
||||||
roleId: ctx.roleId,
|
roleId: ctx.roleId,
|
||||||
user: {
|
user: {
|
||||||
...cloneDeep(ctx.user),
|
...ctx.user,
|
||||||
_id: dbCore.getGlobalIDFromUserMetadataID(ctx.user._id || ""),
|
_id: dbCore.getGlobalIDFromUserMetadataID(ctx.user._id || ""),
|
||||||
},
|
},
|
||||||
request: {
|
request: {
|
||||||
|
|
|
@ -111,6 +111,9 @@ export async function getSelf(ctx: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const syncAppFavourites = async (processedAppIds: string[]) => {
|
export const syncAppFavourites = async (processedAppIds: string[]) => {
|
||||||
|
if (processedAppIds.length === 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
const apps = await fetchAppsByIds(processedAppIds)
|
const apps = await fetchAppsByIds(processedAppIds)
|
||||||
return apps?.reduce((acc: string[], app) => {
|
return apps?.reduce((acc: string[], app) => {
|
||||||
const id = app.appId.replace(dbCore.APP_DEV_PREFIX, "")
|
const id = app.appId.replace(dbCore.APP_DEV_PREFIX, "")
|
||||||
|
@ -127,35 +130,27 @@ export const fetchAppsByIds = async (processedAppIds: string[]) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const processUserAppFavourites = (
|
const processUserAppFavourites = async (
|
||||||
user: User,
|
user: User,
|
||||||
appIdRequest: string[] | undefined
|
update: UpdateSelfRequest
|
||||||
) => {
|
) => {
|
||||||
const userAppFavourites = user.appFavourites || []
|
if (!("appFavourites" in update)) {
|
||||||
const appFavouritesRequest = appIdRequest || []
|
// Ignore requests without an explicit update to favourites.
|
||||||
const appFavouritesUpdated = [
|
return
|
||||||
...new Set(userAppFavourites.concat(appFavouritesRequest)),
|
|
||||||
]
|
|
||||||
|
|
||||||
// Process state
|
|
||||||
let processedAppIds: string[]
|
|
||||||
if (userAppFavourites.length) {
|
|
||||||
const req = new Set(appFavouritesRequest)
|
|
||||||
const updated = new Set(userAppFavourites)
|
|
||||||
for (const element of req) {
|
|
||||||
if (updated.has(element)) {
|
|
||||||
// Subtract/Toggle any existing ones
|
|
||||||
updated.delete(element)
|
|
||||||
} else {
|
|
||||||
// Add new appIds
|
|
||||||
updated.add(element)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
processedAppIds = [...updated]
|
|
||||||
} else {
|
|
||||||
processedAppIds = [...appFavouritesUpdated]
|
|
||||||
}
|
}
|
||||||
return processedAppIds
|
|
||||||
|
const userAppFavourites = user.appFavourites || []
|
||||||
|
const requestAppFavourites = new Set(update.appFavourites || [])
|
||||||
|
const containsAll = userAppFavourites.every(v => requestAppFavourites.has(v))
|
||||||
|
|
||||||
|
if (containsAll && requestAppFavourites.size === userAppFavourites.length) {
|
||||||
|
// Ignore request if the outcome will have no change
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up the request by purging apps that no longer exist.
|
||||||
|
const syncedAppFavourites = await syncAppFavourites([...requestAppFavourites])
|
||||||
|
return syncedAppFavourites
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateSelf(
|
export async function updateSelf(
|
||||||
|
@ -164,16 +159,7 @@ export async function updateSelf(
|
||||||
const update = ctx.request.body
|
const update = ctx.request.body
|
||||||
|
|
||||||
let user = await userSdk.db.getUser(ctx.user._id!)
|
let user = await userSdk.db.getUser(ctx.user._id!)
|
||||||
let requestAppFavourites: string[] = [...(update.appFavourites || [])]
|
const updatedAppFavourites = await processUserAppFavourites(user, update)
|
||||||
let updatedAppFavourites: string[] | undefined
|
|
||||||
|
|
||||||
if ("appFavourites" in update) {
|
|
||||||
const appIds: string[] = processUserAppFavourites(
|
|
||||||
user,
|
|
||||||
requestAppFavourites
|
|
||||||
)
|
|
||||||
updatedAppFavourites = await syncAppFavourites(appIds)
|
|
||||||
}
|
|
||||||
|
|
||||||
user = {
|
user = {
|
||||||
...user,
|
...user,
|
||||||
|
|
Loading…
Reference in New Issue