Skip to content

Commit

Permalink
fix(entities-plugins): plugin form UX phase 2 [KM-61] (#1301)
Browse files Browse the repository at this point in the history
* fix(entities-plugins): plugin form UX phase 2

* fix(entities-plugins): address feedback

* fix(entities-plugins): address feedback 2

* test(entities-plugins): fix tests
  • Loading branch information
sumimakito authored Apr 3, 2024
1 parent 971b6ea commit 210a0c2
Show file tree
Hide file tree
Showing 62 changed files with 2,157 additions and 1,180 deletions.
92 changes: 88 additions & 4 deletions packages/core/forms/src/generator/FormGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,31 @@
:key="`group-${i}`"
>
<KCollapse
v-if="group.collapsible"
:model-value="group.collapsedByDefault === undefined ? false : group.collapsedByDefault"
:title="group.legend"
v-if="group.collapsible !== undefined && group.collapsible !== false"
class="root-level-collapse"
:model-value="false"
:title="group.collapsible.title"
>
<template
v-if="group.collapsible.description"
#visible-content
>
{{ group.collapsible.description }}
</template>

<slot
v-if="group.slots?.beforeContent"
:name="group.slots?.beforeContent"
/>

<slot
v-if="group.fields.length === 0 && group.slots?.emptyState"
:name="group.slots?.emptyState"
/>

<component
:is="tag"
v-else
:class="getFieldRowClasses(group)"
>
<template
Expand All @@ -55,6 +74,37 @@
/>
</template>
</component>

<KCollapse
v-if="group.collapsible !== true && group.collapsible.nestedCollapsible && group.collapsible.nestedCollapsible.fields.length > 0"
class="nested-collapse"
:model-value="collapseStates[`group-${i}-nested`] ?? true"
trigger-alignment="leading"
:trigger-label="(collapseStates[`group-${i}-nested`] ?? true) ? group.collapsible.nestedCollapsible.triggerLabel.expand : group.collapsible.nestedCollapsible.triggerLabel.collapse"
@update:model-value="(value) => collapseStates[`group-${i}-nested`] = value"
>
<component
:is="tag"
:class="getFieldRowClasses(group)"
>
<template
v-for="field in group.collapsible.nestedCollapsible.fields"
:key="field.model"
>
<form-group
v-if="fieldVisible(field)"
ref="children"
:errors="errors"
:field="field"
:model="model"
:options="options"
:vfg="vfg"
@model-updated="onModelUpdated"
@validated="onFieldValidated"
/>
</template>
</component>
</KCollapse>
</KCollapse>

<component
Expand Down Expand Up @@ -87,6 +137,17 @@
</template>

<script>
/**
* @typedef {import('./types').FGCollapsibleOptions} FGCollapsibleOptions
* @typedef {import('./types').FGSlots} FGSlots
*
* @typedef PartialGroup
* @prop {FGCollapsibleOptions=} collapsible
* @prop {FGSlots=} slots
*
* @typedef {Record<string, any> & PartialGroup} Group
*/
import { get as objGet, forEach, isFunction, isNil, isArray } from 'lodash'
import formMixin from './FormMixin.vue'
import formGroup from './FormGroup.vue'
Expand Down Expand Up @@ -148,6 +209,7 @@ export default {
vfg: this,
errors: [], // Validation errors,
children: ref([]),
collapseStates: {},
}
},
Expand All @@ -163,6 +225,7 @@ export default {
return res
},
groups() {
/** @type {Group[]} */
const res = []
if (this.schema && this.schema.groups) {
forEach(this.schema.groups.slice(0), group => {
Expand Down Expand Up @@ -201,7 +264,7 @@ export default {
mounted() {
this.$nextTick(() => {
if (this.model) {
// First load, running validation if neccessary
// First load, running validation if necessary
if (this.options.validateAfterLoad === true && this.isNewModel !== true) {
this.validate()
} else {
Expand Down Expand Up @@ -304,6 +367,10 @@ export default {
box-sizing: border-box;
}
.hidden-field {
display: none;
}
.form-group {
margin-bottom: 24px;
Expand Down Expand Up @@ -530,6 +597,7 @@ export default {
.vue-form-generator label {
font-weight: 500;
}
.vue-form-generator .form-group input[type=radio] {
align-items: center;
appearance: none;
Expand All @@ -552,4 +620,20 @@ export default {
background-color: currentColor;
}
}
.vue-form-generator {
.root-level-collapse {
.k-collapse-heading {
margin-bottom: 0 !important;
}
.k-collapse-visible-content {
color: $kui-color-text-neutral;
}
}
.nested-collapse .k-collapse-heading {
margin-bottom: $kui-space-80 !important;
}
}
</style>
16 changes: 16 additions & 0 deletions packages/core/forms/src/generator/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type FGCollapsibleOptions = boolean | {
title?: string
description?: string
nestedCollapsible?: {
fields: any[],
triggerLabel: {
expand: string
collapse: string
}
}
}

export interface FGSlots {
beforeContent?: string
emptyState?: string
}
1 change: 1 addition & 0 deletions packages/core/forms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export const getSharedFormName = (modelName: string, enabledAcmeCustomTemplate =
}

export * from './const'
export * from './types'
export * as abstractField from './generator/fields/abstractField'
1 change: 1 addition & 0 deletions packages/core/forms/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './generator/types'
3 changes: 2 additions & 1 deletion packages/core/forms/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"cypress",
"cypress/vue",
"../../../cypress/support"
]
],
"allowJs": true
},
"include": [
"src/**/*",
Expand Down
Loading

0 comments on commit 210a0c2

Please sign in to comment.