1
0
Fork 0
mirror of synced 2024-10-06 13:04:36 +13:00

Feedback and some fixes. Fix for app list getting squashed when the app metadata was updated.

This commit is contained in:
Dean 2024-05-15 12:50:50 +01:00
parent 531281521e
commit bb552c1984
4 changed files with 34 additions and 42 deletions

View file

@ -17,44 +17,49 @@
let updating = false let updating = false
let edited = false let edited = false
let initialised = false
$: filteredApps = $appsStore.apps.filter(app => app.devId == $appStore.appId) $: filteredApps = $appsStore.apps.filter(app => app.devId == $appStore.appId)
$: app = filteredApps.length ? filteredApps[0] : {} $: app = filteredApps.length ? filteredApps[0] : {}
$: appDeployed = app?.status === AppStatus.DEPLOYED $: appDeployed = app?.status === AppStatus.DEPLOYED
$: appIdParts = app.appId ? app.appId?.split("_") : [] $: appName = $appStore.name
$: appId = appIdParts.slice(-1)[0] $: appURL = $appStore.url
$: appIconName = $appStore.icon?.name
$: appIconColor = $appStore.icon?.color
$: appMeta = { $: appMeta = {
name: $appStore.name, name: appName,
url: $appStore.url, url: appURL,
iconName: $appStore.icon?.name, iconName: appIconName,
iconColor: $appStore.icon?.color, iconColor: appIconColor,
} }
// On app update, reset the state. const initForm = appMeta => {
$: if (appMeta) {
edited = false edited = false
const { name, url, iconName, iconColor } = appMeta
values.set({ values.set({
name, ...appMeta,
url,
iconName,
iconColor,
}) })
setupValidation() if (!initialised) {
setupValidation()
initialised = true
}
} }
$: if (values && $values) { const validate = (vals, appMeta) => {
const { url } = $values || {} const { url } = vals || {}
validation.check({ validation.check({
...$values, ...vals,
url: url?.[0] === "/" ? url.substring(1, url.length) : url, url: url?.[0] === "/" ? url.substring(1, url.length) : url,
}) })
edited = !isEqual($values, appMeta) edited = !isEqual(vals, appMeta)
} }
// On app/apps update, reset the state.
$: initForm(appMeta)
$: validate($values, appMeta)
const resolveAppUrl = (template, name) => { const resolveAppUrl = (template, name) => {
let parsedName let parsedName
const resolvedName = resolveAppName(null, name) const resolvedName = resolveAppName(null, name)
@ -89,26 +94,13 @@
} }
const setupValidation = async () => { const setupValidation = async () => {
const applications = $appsStore.apps
appValidation.name(validation, { appValidation.name(validation, {
apps: applications, apps: $appsStore.apps,
currentApp: { currentApp: app,
...app,
appId,
},
}) })
appValidation.url(validation, { appValidation.url(validation, {
apps: applications, apps: $appsStore.apps,
currentApp: { currentApp: app,
...app,
appId,
},
})
// init validation
const { url } = $values
validation.check({
...$values,
url: url?.[0] === "/" ? url.substring(1, url.length) : url,
}) })
} }
@ -182,8 +174,10 @@
await updateApp() await updateApp()
updating = false updating = false
}} }}
disabled={appDeployed || updating || !edited}>Save</Button disabled={appDeployed || updating || !edited || !$validation.valid}
> >
Save
</Button>
{:else} {:else}
<div class="edit-info"> <div class="edit-info">
<Icon size="S" name="Info" /> Unpublish your app to edit name and URL <Icon size="S" name="Info" /> Unpublish your app to edit name and URL

View file

@ -40,7 +40,6 @@
customZindex={998} customZindex={998}
bind:this={formPopover} bind:this={formPopover}
align="center" align="center"
disabled={!isPublished}
anchor={formPopoverAnchor} anchor={formPopoverAnchor}
offset={20} offset={20}
on:close={() => { on:close={() => {

View file

@ -19,11 +19,10 @@ export const name = (validation, { apps, currentApp } = { apps: [] }) => {
// exit early, above validator will fail // exit early, above validator will fail
return true return true
} }
if (currentApp) {
// filter out the current app if present
apps = apps.filter(app => app.appId !== currentApp.appId)
}
return !apps return !apps
.filter(app => {
return app.appId !== currentApp?.appId
})
.map(app => app.name) .map(app => app.name)
.some(appName => appName.toLowerCase() === value.toLowerCase()) .some(appName => appName.toLowerCase() === value.toLowerCase())
} }

View file

@ -131,7 +131,7 @@ export class AppsStore extends BudiStore {
if (updatedAppIndex !== -1) { if (updatedAppIndex !== -1) {
let updatedApp = state.apps[updatedAppIndex] let updatedApp = state.apps[updatedAppIndex]
updatedApp = { ...updatedApp, ...value } updatedApp = { ...updatedApp, ...value }
state.apps = state.apps.splice(updatedAppIndex, 1, updatedApp) state.apps.splice(updatedAppIndex, 1, updatedApp)
} }
return state return state
}) })