Fix app list (#2152)

* fix(frontend): Fix app list pagination

* fix(frontend): make minimal changes

* fix(frontend): make minimal changes

* fix(frontend): make minimal changes

* fix(frontend): revert unecessary changes

* fix(frontend): done

* fix(frontend): revert unnecessary changes

* fix(frontend): remove code duplication

* fix(frontend): remove code duplication
This commit is contained in:
Faton Ramadani
2023-08-22 16:46:24 +02:00
committed by GitHub
parent 57586fb376
commit c4e451347c
2 changed files with 34 additions and 12 deletions
@@ -4,6 +4,7 @@ import type {
ConnectingInput,
EditorBreakpoint,
FocusedGrid,
GeneralAppInput,
GridItem
} from '../types'
import {
@@ -215,6 +216,18 @@ function cleanseValue(key: string, value: { type: 'eval' | 'static'; value?: any
return [key, { type: value.type, expr: value.expr }]
}
}
export function cleanseOneOfConfiguration(
configuration: Record<string, Record<string, GeneralAppInput & (StaticAppInput | EvalAppInput)>>
) {
return Object.fromEntries(
Object.entries(configuration).map(([key, val]) => [
key,
Object.fromEntries(Object.entries(val).map(([key, val]) => cleanseValue(key, val)))
])
)
}
export function appComponentFromType<T extends keyof typeof components>(
type: T,
overrideConfiguration?: Partial<InitialAppComponent['configuration']>
@@ -232,14 +245,7 @@ export function appComponentFromType<T extends keyof typeof components>(
{
type: value.type,
selected: value.selected,
configuration: Object.fromEntries(
Object.entries(value.configuration).map(([key, val]) => [
key,
Object.fromEntries(
Object.entries(val).map(([key, val]) => cleanseValue(key, val))
)
])
)
configuration: cleanseOneOfConfiguration(value.configuration)
}
]
}
@@ -521,10 +527,15 @@ export function initConfig<
selected: value.selected,
type: 'oneOf',
configuration: Object.fromEntries(
Object.entries(value.configuration).map(([choice, config]) => [
choice,
initConfig(config, configuration?.[key]?.configuration?.[choice])
])
Object.entries(value.configuration).map(([choice, config]) => {
const conf = initConfig(config, configuration?.[key]?.configuration?.[choice])
Object.entries(config).forEach(([innerKey, innerValue]) => {
if (innerValue.type === 'static' && !(innerKey in conf)) {
conf[innerKey] = innerValue.value
}
})
return [choice, conf]
})
)
}
]
@@ -2,6 +2,7 @@
import Tooltip from '$lib/components/Tooltip.svelte'
import { addWhitespaceBeforeCapitals, capitalize } from '$lib/utils'
import type { RichConfiguration } from '../../types'
import { cleanseOneOfConfiguration } from '../appUtils'
import InputsSpecEditor from './InputsSpecEditor.svelte'
export let key: string
@@ -26,6 +27,16 @@
if (oneOf?.configuration[oneOf?.selected] == undefined) {
oneOf.configuration[oneOf.selected] = {}
}
// If the configuration is empty, we set the first one as selected.
// It happens when the configuration was added after the component was created
if (oneOf.selected === '') {
oneOf = {
configuration: cleanseOneOfConfiguration(inputSpecsConfiguration),
selected: Object.keys(inputSpecsConfiguration ?? {})[0],
type: 'oneOf'
}
}
}
</script>