Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0b8e4e090 |
@@ -2,6 +2,15 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
|
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## [1.0.10] - 2026-09-04
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Re-added map entries and object list items are seeded with their schema defaults, including a value for every non-nullable boolean.
|
||||||
|
|
||||||
## [1.0.9] - 2026-08-24
|
## [1.0.9] - 2026-08-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "stalwart-webui",
|
"name": "stalwart-webui",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.9",
|
"version": "1.0.10",
|
||||||
"description": "Stalwart WebUI",
|
"description": "Stalwart WebUI",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { useState, useEffect, useMemo, type KeyboardEvent } from 'react';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useBufferedValue, useResetOnChange } from '@/hooks/useBufferedValue';
|
import { useBufferedValue, useResetOnChange } from '@/hooks/useBufferedValue';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
|
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -21,14 +20,10 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/comp
|
|||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||||
import { Combobox, type ComboboxOption } from '@/components/ui/combobox';
|
import { Combobox, type ComboboxOption } from '@/components/ui/combobox';
|
||||||
import { Calendar } from '@/components/ui/calendar';
|
import { Calendar } from '@/components/ui/calendar';
|
||||||
|
|
||||||
import { Plus, X, Eye, EyeOff, Loader2, Search, Check, ChevronRight, Calendar as CalendarIcon } from 'lucide-react';
|
import { Plus, X, Eye, EyeOff, Loader2, Search, Check, ChevronRight, Calendar as CalendarIcon } from 'lucide-react';
|
||||||
|
|
||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
||||||
|
|
||||||
import { ExpressionEditor } from '@/components/expression/ExpressionEditor';
|
import { ExpressionEditor } from '@/components/expression/ExpressionEditor';
|
||||||
import { OtpAuthField } from '@/components/forms/OtpAuthField';
|
import { OtpAuthField } from '@/components/forms/OtpAuthField';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bytesToHuman,
|
bytesToHuman,
|
||||||
humanToBytes,
|
humanToBytes,
|
||||||
@@ -39,7 +34,13 @@ import {
|
|||||||
SIZE_UNITS,
|
SIZE_UNITS,
|
||||||
DURATION_UNITS,
|
DURATION_UNITS,
|
||||||
} from '@/lib/durationFormat';
|
} from '@/lib/durationFormat';
|
||||||
import { resolveSchema, resolveVariantForm, resolveObject, buildEmbeddedDefaults } from '@/lib/schemaResolver';
|
import {
|
||||||
|
resolveSchema,
|
||||||
|
resolveVariantForm,
|
||||||
|
resolveObject,
|
||||||
|
buildEmbeddedDefaults,
|
||||||
|
buildNewObjectValue,
|
||||||
|
} from '@/lib/schemaResolver';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { useAccountStore } from '@/stores/accountStore';
|
import { useAccountStore } from '@/stores/accountStore';
|
||||||
import { useEffectiveEdition } from '@/components/forms/FormEditionContext';
|
import { useEffectiveEdition } from '@/components/forms/FormEditionContext';
|
||||||
@@ -1539,16 +1540,7 @@ function ObjectListField({
|
|||||||
|
|
||||||
const addItem = () => {
|
const addItem = () => {
|
||||||
const nextIndex = entries.length > 0 ? Math.max(...entries.map(([k]) => parseInt(k))) + 1 : 0;
|
const nextIndex = entries.length > 0 ? Math.max(...entries.map(([k]) => parseInt(k))) + 1 : 0;
|
||||||
let defaults: Record<string, unknown> = {};
|
onChange({ ...mapValue, [String(nextIndex)]: buildNewObjectValue(schema, objectName) });
|
||||||
if (resolvedSchema.type === 'single' && resolvedSchema.fields.defaults) {
|
|
||||||
defaults = { ...resolvedSchema.fields.defaults };
|
|
||||||
} else if (resolvedSchema.type === 'multiple' && resolvedSchema.variants[0]) {
|
|
||||||
defaults = { '@type': resolvedSchema.variants[0].name };
|
|
||||||
if (resolvedSchema.variants[0].fields?.defaults) {
|
|
||||||
defaults = { ...defaults, ...resolvedSchema.variants[0].fields.defaults };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onChange({ ...mapValue, [String(nextIndex)]: defaults });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeItem = (key: string) => {
|
const removeItem = (key: string) => {
|
||||||
@@ -1790,10 +1782,10 @@ function EnumMultiSelect({ enumName, items, onChange, readOnly, schema, minItems
|
|||||||
if (variants.length > 10) {
|
if (variants.length > 10) {
|
||||||
const filtered = searchQuery
|
const filtered = searchQuery
|
||||||
? variants.filter(
|
? variants.filter(
|
||||||
(v) =>
|
(v) =>
|
||||||
v.label.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
v.label.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
v.name.toLowerCase().includes(searchQuery.toLowerCase()),
|
v.name.toLowerCase().includes(searchQuery.toLowerCase()),
|
||||||
)
|
)
|
||||||
: variants;
|
: variants;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -2021,7 +2013,7 @@ function MapField({ keyClass, valueClass, value, onChange, readOnly, schema, min
|
|||||||
if (valueClass.type === 'number') {
|
if (valueClass.type === 'number') {
|
||||||
defaultValue = 0;
|
defaultValue = 0;
|
||||||
} else if (valueClass.type === 'object') {
|
} else if (valueClass.type === 'object') {
|
||||||
defaultValue = {};
|
defaultValue = buildNewObjectValue(schema, valueClass.objectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange({ ...mapValue, [key]: defaultValue });
|
onChange({ ...mapValue, [key]: defaultValue });
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
deepMerge,
|
deepMerge,
|
||||||
buildCreateDefaults,
|
buildCreateDefaults,
|
||||||
buildEmbeddedDefaults,
|
buildEmbeddedDefaults,
|
||||||
|
buildNewObjectValue,
|
||||||
} from './schemaResolver';
|
} from './schemaResolver';
|
||||||
import { getDisplayProperty } from './schemaResolver';
|
import { getDisplayProperty } from './schemaResolver';
|
||||||
|
|
||||||
@@ -865,3 +866,115 @@ describe('getDisplayProperty', () => {
|
|||||||
expect(getDisplayProperty(schema, 'x:NoLabel')).toBe('title');
|
expect(getDisplayProperty(schema, 'x:NoLabel')).toBe('title');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const structSchema: Schema = {
|
||||||
|
objects: {},
|
||||||
|
schemas: {
|
||||||
|
'x:Service': { type: 'single', schemaName: 'x:Service' },
|
||||||
|
'x:Listener': { type: 'single', schemaName: 'x:Listener' },
|
||||||
|
'x:Tls': { type: 'single', schemaName: 'x:Tls' },
|
||||||
|
'x:Store': {
|
||||||
|
type: 'multiple',
|
||||||
|
variants: [
|
||||||
|
{ name: 'S3', label: 'S3', schemaName: 'x:S3Store' },
|
||||||
|
{ name: 'Manual', label: 'Manual' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fields: {
|
||||||
|
'x:Service': {
|
||||||
|
properties: {
|
||||||
|
hostname: {
|
||||||
|
description: '',
|
||||||
|
type: { type: 'string', format: 'string', nullable: true },
|
||||||
|
update: 'mutable',
|
||||||
|
},
|
||||||
|
cleartext: { description: '', type: { type: 'boolean' }, update: 'mutable' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x:Listener': {
|
||||||
|
properties: {
|
||||||
|
enabled: { description: '', type: { type: 'boolean' }, update: 'mutable' },
|
||||||
|
proxied: { description: '', type: { type: 'boolean' }, update: 'mutable' },
|
||||||
|
readOnly: { description: '', type: { type: 'boolean' }, update: 'serverSet' },
|
||||||
|
tls: { description: '', type: { type: 'object', objectName: 'x:Tls' }, update: 'mutable' },
|
||||||
|
fallback: {
|
||||||
|
description: '',
|
||||||
|
type: { type: 'object', objectName: 'x:Tls', nullable: true },
|
||||||
|
update: 'mutable',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaults: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x:Tls': {
|
||||||
|
properties: {
|
||||||
|
implicit: { description: '', type: { type: 'boolean' }, update: 'mutable' },
|
||||||
|
certificateId: {
|
||||||
|
description: '',
|
||||||
|
type: { type: 'string', format: 'string', nullable: true },
|
||||||
|
update: 'mutable',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'x:S3Store': {
|
||||||
|
properties: {
|
||||||
|
bucket: { description: '', type: { type: 'string', format: 'string' }, update: 'mutable' },
|
||||||
|
allowInvalidCerts: { description: '', type: { type: 'boolean' }, update: 'mutable' },
|
||||||
|
},
|
||||||
|
defaults: {
|
||||||
|
bucket: 'stalwart',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
forms: {},
|
||||||
|
lists: {},
|
||||||
|
enums: {},
|
||||||
|
dashboards: [],
|
||||||
|
layouts: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('buildNewObjectValue', () => {
|
||||||
|
it('seeds non-nullable booleans a struct has no defaults for', () => {
|
||||||
|
expect(buildNewObjectValue(structSchema, 'x:Service')).toEqual({ cleartext: false });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps schema defaults and only fills the missing booleans', () => {
|
||||||
|
const result = buildNewObjectValue(structSchema, 'x:Listener');
|
||||||
|
expect(result.enabled).toBe(true);
|
||||||
|
expect(result.proxied).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips serverSet properties', () => {
|
||||||
|
expect(buildNewObjectValue(structSchema, 'x:Listener')).not.toHaveProperty('readOnly');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recurses into non-nullable embedded objects and skips nullable ones', () => {
|
||||||
|
const result = buildNewObjectValue(structSchema, 'x:Listener');
|
||||||
|
expect(result.tls).toEqual({ implicit: false });
|
||||||
|
expect(result).not.toHaveProperty('fallback');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('seeds the first variant with its @type, defaults and booleans', () => {
|
||||||
|
expect(buildNewObjectValue(structSchema, 'x:Store')).toEqual({
|
||||||
|
'@type': 'S3',
|
||||||
|
bucket: 'stalwart',
|
||||||
|
allowInvalidCerts: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('honours an explicit variant name', () => {
|
||||||
|
expect(buildNewObjectValue(structSchema, 'x:Store', 'Manual')).toEqual({ '@type': 'Manual' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an empty object for an unknown object name', () => {
|
||||||
|
expect(buildNewObjectValue(structSchema, 'x:Unknown')).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('still merges parent defaults into embedded children', () => {
|
||||||
|
const result = buildNewObjectValue(embeddedSchema, 'x:Model', 'FtrlCcfh');
|
||||||
|
expect(result.featureL2Normalize).toBe(true);
|
||||||
|
expect((result.parameters as Record<string, unknown>).numFeatures).toBe('20');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -260,6 +260,62 @@ export function buildEmbeddedDefaults(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function buildNewObjectValue(schema: Schema, objectName: string, variantName?: string): Record<string, unknown> {
|
||||||
|
const result = buildEmbeddedDefaults(schema, objectName, {}, variantName);
|
||||||
|
return completeStructDefaults(schema, objectName, (result['@type'] as string | undefined) ?? variantName, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function completeStructDefaults(
|
||||||
|
schema: Schema,
|
||||||
|
objectName: string,
|
||||||
|
variantName: string | undefined,
|
||||||
|
target: Record<string, unknown>,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
const resolved = resolveSchema(schema, objectName);
|
||||||
|
if (!resolved) return target;
|
||||||
|
|
||||||
|
const fields =
|
||||||
|
resolved.type === 'single'
|
||||||
|
? resolved.fields
|
||||||
|
: ((variantName ? resolved.variants.find((v) => v.name === variantName) : resolved.variants[0])?.fields ?? null);
|
||||||
|
if (!fields) return target;
|
||||||
|
|
||||||
|
for (const [propName, propDef] of Object.entries(fields.properties)) {
|
||||||
|
if (propDef.update === 'serverSet') continue;
|
||||||
|
const t = propDef.type;
|
||||||
|
|
||||||
|
if (t.type === 'boolean') {
|
||||||
|
if (!(propName in target)) {
|
||||||
|
target[propName] = false;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.type !== 'object' || t.nullable) continue;
|
||||||
|
|
||||||
|
const current = target[propName];
|
||||||
|
if (current !== undefined && !isPlainRecord(current)) continue;
|
||||||
|
|
||||||
|
const overrides = isPlainRecord(current) ? current : {};
|
||||||
|
const nestedEntry = schema.schemas[t.objectName];
|
||||||
|
const nestedVariant =
|
||||||
|
nestedEntry?.type === 'multiple'
|
||||||
|
? ((overrides['@type'] as string | undefined) ?? nestedEntry.variants[0]?.name)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const nested = completeStructDefaults(schema, t.objectName, nestedVariant, { ...overrides });
|
||||||
|
if (Object.keys(nested).length > 0) {
|
||||||
|
target[propName] = nested;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
||||||
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
||||||
|
}
|
||||||
|
|
||||||
export function getDisplayProperty(schema: Schema, objectName: string): string {
|
export function getDisplayProperty(schema: Schema, objectName: string): string {
|
||||||
const list = schema.lists[objectName];
|
const list = schema.lists[objectName];
|
||||||
if (list?.labelProperty) return list.labelProperty;
|
if (list?.labelProperty) return list.labelProperty;
|
||||||
|
|||||||
Reference in New Issue
Block a user