mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
fix: visible
+ enabled
reactivity
This commit is contained in:
parent
67ab4a2637
commit
5408b0553c
5 changed files with 15 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts" generic="MV extends Obj, FFD extends FormFieldDict<MV>">
|
<script setup lang="ts" generic="MV extends Obj, FFD extends FormFieldDict<MV>">
|
||||||
import { createReusableTemplate } from '@vueuse/core'
|
import { createReusableTemplate } from '@vueuse/core'
|
||||||
import { computed, reactive, toValue } from 'vue'
|
import { computed, toValue } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
import type { FormValidation } from '@/composables/form'
|
import type { FormValidation } from '@/composables/form'
|
||||||
|
@ -85,7 +85,7 @@ const sections = computed(() => {
|
||||||
if (!sections || !fields) return
|
if (!sections || !fields) return
|
||||||
return sections.map((section) => ({
|
return sections.map((section) => ({
|
||||||
...section,
|
...section,
|
||||||
fields: reactive(section.fields.map((id) => [id, fields[id]])) as {
|
fields: section.fields.map((id) => [id, fields[id]]) as {
|
||||||
[k in Extract<keyof FFD, string>]: [k, FFD[k]]
|
[k in Extract<keyof FFD, string>]: [k, FFD[k]]
|
||||||
}[Extract<keyof FFD, string>][],
|
}[Extract<keyof FFD, string>][],
|
||||||
}))
|
}))
|
||||||
|
@ -109,7 +109,7 @@ const Fields = createReusableTemplate<{
|
||||||
<template>
|
<template>
|
||||||
<Fields.define v-slot="{ fieldsProps }">
|
<Fields.define v-slot="{ fieldsProps }">
|
||||||
<template v-for="[k, field] in fieldsProps" :key="k">
|
<template v-for="[k, field] in fieldsProps" :key="k">
|
||||||
<template v-if="field.visible ?? true">
|
<template v-if="toValue(field.visible) ?? true">
|
||||||
<slot
|
<slot
|
||||||
v-if="isWritableComponent<MV[typeof k]>(field)"
|
v-if="isWritableComponent<MV[typeof k]>(field)"
|
||||||
:name="`field:${k}`"
|
:name="`field:${k}`"
|
||||||
|
@ -174,7 +174,7 @@ const Fields = createReusableTemplate<{
|
||||||
<template v-for="section in sections" :key="section.id">
|
<template v-for="section in sections" :key="section.id">
|
||||||
<Component
|
<Component
|
||||||
:is="section.name ? 'section' : 'div'"
|
:is="section.name ? 'section' : 'div'"
|
||||||
v-if="section.visible"
|
v-if="toValue(section.visible)"
|
||||||
class="form-section"
|
class="form-section"
|
||||||
>
|
>
|
||||||
<BCardTitle v-if="section.name" title-tag="h3">
|
<BCardTitle v-if="section.name" title-tag="h3">
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed, toValue } from 'vue'
|
||||||
|
|
||||||
import type { ButtonItemProps } from '@/types/form'
|
import type { ButtonItemProps } from '@/types/form'
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ const icon = computed(() => {
|
||||||
<BButton
|
<BButton
|
||||||
:id="id"
|
:id="id"
|
||||||
:variant="type"
|
:variant="type"
|
||||||
:disabled="!enabled"
|
:disabled="!toValue(enabled)"
|
||||||
class="d-block mb-3"
|
class="d-block mb-3"
|
||||||
@click="emit('action', id)"
|
@click="emit('action', id)"
|
||||||
>
|
>
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
import { APIBadRequestError, APIError } from '@/api/errors'
|
import { APIBadRequestError, APIError } from '@/api/errors'
|
||||||
import { deepSetErrors, useForm, type FormValidation } from '@/composables/form'
|
import { deepSetErrors, useForm, type FormValidation } from '@/composables/form'
|
||||||
import { asUnreffed, isObjectLiteral } from '@/helpers/commons'
|
import { isObjectLiteral } from '@/helpers/commons'
|
||||||
import * as validators from '@/helpers/validators'
|
import * as validators from '@/helpers/validators'
|
||||||
import { formatForm, formatI18nField } from '@/helpers/yunohostArguments'
|
import { formatForm, formatI18nField } from '@/helpers/yunohostArguments'
|
||||||
import type { CustomRoute, KeyOfStr, MergeUnion, Obj } from '@/types/commons'
|
import type { CustomRoute, KeyOfStr, MergeUnion, Obj } from '@/types/commons'
|
||||||
|
@ -324,14 +324,14 @@ export function formatConfigPanels<
|
||||||
function useExpression(
|
function useExpression(
|
||||||
expression: JSExpression | undefined,
|
expression: JSExpression | undefined,
|
||||||
form: Ref<Obj>,
|
form: Ref<Obj>,
|
||||||
): boolean {
|
): boolean | ComputedRef<boolean> {
|
||||||
if (typeof expression === 'boolean') return expression
|
if (typeof expression === 'boolean') return expression
|
||||||
if (typeof expression === 'string') {
|
if (typeof expression === 'string') {
|
||||||
// FIXME normalize expression in core? ('', 'false', 'true') and rm next 2 lines
|
// FIXME normalize expression in core? ('', 'false', 'true') and rm next 2 lines
|
||||||
if (!expression || expression === 'true') return true
|
if (!expression || expression === 'true') return true
|
||||||
if (expression === 'false') return false
|
if (expression === 'false') return false
|
||||||
// FIXME remove asUnreffed and manage ref type?
|
// FIXME remove asUnreffed and manage ref type?
|
||||||
return asUnreffed(useEvaluation(expression, form))
|
return useEvaluation(expression, form)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { Ref } from 'vue'
|
import type { ComputedRef, Ref } from 'vue'
|
||||||
|
|
||||||
import type { Obj, KeyOfStr, CustomRoute } from '@/types/commons'
|
import type { Obj, KeyOfStr, CustomRoute } from '@/types/commons'
|
||||||
import type {
|
import type {
|
||||||
|
@ -56,7 +56,7 @@ export type ConfigSection<MV extends Obj, FFD extends FormFieldDict<MV>> = {
|
||||||
id: string
|
id: string
|
||||||
isActionSection: boolean
|
isActionSection: boolean
|
||||||
name?: string
|
name?: string
|
||||||
visible: boolean
|
visible: boolean | ComputedRef<boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConfigPanel<
|
export type ConfigPanel<
|
||||||
|
|
|
@ -3,6 +3,7 @@ import type {
|
||||||
ValidationArgs,
|
ValidationArgs,
|
||||||
ValidationRuleCollection,
|
ValidationRuleCollection,
|
||||||
} from '@vuelidate/core'
|
} from '@vuelidate/core'
|
||||||
|
import type { ComputedRef } from 'vue'
|
||||||
import type { RouteLocationRaw } from 'vue-router'
|
import type { RouteLocationRaw } from 'vue-router'
|
||||||
|
|
||||||
import { isObjectLiteral } from '@/helpers/commons'
|
import { isObjectLiteral } from '@/helpers/commons'
|
||||||
|
@ -19,7 +20,7 @@ type BaseDisplayItemProps = {
|
||||||
|
|
||||||
export type ButtonItemProps = BaseDisplayItemProps & {
|
export type ButtonItemProps = BaseDisplayItemProps & {
|
||||||
// FIXME compute enabled JSExpression
|
// FIXME compute enabled JSExpression
|
||||||
enabled?: boolean
|
enabled?: boolean | ComputedRef<boolean>
|
||||||
icon?: string
|
icon?: string
|
||||||
type?: StateVariant
|
type?: StateVariant
|
||||||
}
|
}
|
||||||
|
@ -239,8 +240,7 @@ type BaseFormField<C extends AnyItemComponents> = {
|
||||||
label?: string
|
label?: string
|
||||||
props?: ItemComponentToItemProps[C]
|
props?: ItemComponentToItemProps[C]
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
// FIXME compute visible JSExpression
|
visible?: boolean | ComputedRef<boolean>
|
||||||
visible?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FormField<
|
export type FormField<
|
||||||
|
@ -274,7 +274,7 @@ export type FormFieldDisplay<
|
||||||
> = {
|
> = {
|
||||||
component: C
|
component: C
|
||||||
props: ItemComponentToItemProps[C]
|
props: ItemComponentToItemProps[C]
|
||||||
visible?: boolean
|
visible?: boolean | ComputedRef<boolean>
|
||||||
hr?: boolean
|
hr?: boolean
|
||||||
readonly?: true
|
readonly?: true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue