sort fields by label.

This commit is contained in:
2025-06-26 19:59:25 +09:00
parent ddae42619e
commit 2d84e24d61

View File

@@ -12,12 +12,24 @@ export interface PluginContext {
lookupFields: KintoneFormFieldProperty.Lookup[];
}
const naturalCompare = (a: string, b: string): number => {
const locales = new Set<string>([...navigator.languages, 'en-US', 'ja-JP']);
return new Intl.Collator(Array.from(locales), {
sensitivity: 'variant',
numeric: true,
}).compare(a, b);
};
const filterAttachmentFields = (properties: KintoneFormFieldProperties): KintoneFormFieldProperty.File[] => {
return Object.values(properties).filter((property) => property.type === 'FILE');
return Object.values(properties)
.filter((property) => property.type === 'FILE')
.sort((a, b) => naturalCompare(a.label, b.label));
};
const filterLookupFields = (properties: KintoneFormFieldProperties): KintoneFormFieldProperty.Lookup[] => {
return Object.values(properties).filter((property) => 'lookup' in property);
return Object.values(properties)
.filter((property) => 'lookup' in property)
.sort((a, b) => naturalCompare(a.label, b.label));
};
const getFormFieldsProperties = async (appId: KintoneAppId): Promise<KintoneFormFieldProperties> => {