Squashed commit of the following:
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 40s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 40s
commit 579f0878e5240dc17db69be1e0b0c0f5af7ef9fe
Author: Arno Kaimbacher <arno.kaimbacher@geosphere.at>
Date: Tue Jun 9 09:25:44 2026 +0200
feat: Refactor error handling in Dataset Edit form and improve validation messages
- Updated error handling in the Dataset Edit form to use a centralized formatError function for displaying validation messages.
- Enhanced user feedback by ensuring that error messages are displayed consistently across various fields.
- Modified the validation rule for arrayContainsTypes to provide clearer error messages for missing main and translated titles/abstracts.
- Introduced a new ValidationService to manage manual construction of validation errors.
- Updated Vite configuration to streamline asset loading and improve performance.
- Adjusted Inertia setup to utilize dynamic imports for page-specific assets.
- Cleaned up unnecessary comments and code in various files for better readability.
commit 5efddc2a58c0e164fef585cc7344c06155dbc2c1
Author: Arno Kaimbacher <arno.kaimbacher@geosphere.at>
Date: Mon Jan 12 17:02:47 2026 +0100
feat: add dataset change detection and form submission composables
- Implemented `useDatasetChangeDetection` for tracking unsaved changes in dataset forms, including comparisons for licenses, basic properties, files, coverage, and more.
- Added `useDatasetFormSubmission` for handling dataset form submissions with validation, success/error handling, and auto-save functionality.
This commit is contained in:
parent
0680879e2f
commit
9368a0dd8d
38 changed files with 5588 additions and 6181 deletions
|
|
@ -15,56 +15,40 @@ type Options = {
|
|||
* where each object has a "type" property.
|
||||
*/
|
||||
async function arrayContainsTypes(value: unknown, options: Options, field: FieldContext) {
|
||||
if (!Array.isArray(value)) {
|
||||
field.report(`The {{field}} must be an array of titles.`, 'array.titlesContainsMainAndTranslated', field);
|
||||
return false;
|
||||
if (!Array.isArray(value)) return;
|
||||
|
||||
const typeAExpected = options.typeA.toLowerCase(); // 'main' or 'abstract'
|
||||
const typeBExpected = options.typeB.toLowerCase(); // 'translated'
|
||||
|
||||
// 1. Check the very first element (The "Main" entry)
|
||||
const firstItem = value[0];
|
||||
const isFirstItemMain = firstItem &&
|
||||
typeof firstItem === 'object' &&
|
||||
String(firstItem.type).toLowerCase() === typeAExpected;
|
||||
|
||||
// 2. Check the rest of the array for the "Translated" entry
|
||||
// We look for typeB anywhere in the array
|
||||
const hasTranslatedEntry = value.some((item: any) =>
|
||||
item && typeof item === 'object' && String(item.type).toLowerCase() === typeBExpected
|
||||
);
|
||||
|
||||
// 3. Conditional Error Messaging based on Field Path
|
||||
const path = field.getFieldPath();
|
||||
const isTitles = path === 'titles';
|
||||
|
||||
if (!isFirstItemMain) {
|
||||
const msg = isTitles
|
||||
? 'The first entry must be the Main Title.'
|
||||
: 'The first entry must be the Main Abstract.';
|
||||
field.report(msg, 'array.first_item_invalid', field);
|
||||
}
|
||||
|
||||
const typeAExpected = options.typeA.toLowerCase();
|
||||
const typeBExpected = options.typeB.toLowerCase();
|
||||
|
||||
// const hasMain = value.some((title: any) => {
|
||||
// return typeof title === 'object' && title !== null && String(title.type).toLowerCase() === 'main';
|
||||
// });
|
||||
|
||||
// const hasTranslated = value.some((title: any) => {
|
||||
// return typeof title === 'object' && title !== null && String(title.type).toLowerCase() === 'translated';
|
||||
// });
|
||||
const hasTypeA = value.some((item: any) => {
|
||||
return typeof item === 'object' && item !== null && String(item.type).toLowerCase() === typeAExpected;
|
||||
});
|
||||
|
||||
const hasTypeB = value.some((item: any) => {
|
||||
return typeof item === 'object' && item !== null && String(item.type).toLowerCase() === typeBExpected;
|
||||
});
|
||||
if (!hasTypeA || !hasTypeB) {
|
||||
let errorMessage = `The ${field.getFieldPath()} array must have at least one '${options.typeA}' item and one '${options.typeB}' item.`;
|
||||
|
||||
// Check for specific field names to produce a more readable message.
|
||||
if (field.getFieldPath() === 'titles') {
|
||||
// For titles we expect one main and minimum one translated title.
|
||||
if (!hasTypeA && !hasTypeB) {
|
||||
errorMessage = 'For titles, define at least one main title and at least one Translated title as MAIN TITLE.';
|
||||
} else if (!hasTypeA) {
|
||||
errorMessage = 'For titles, define at least one main title.';
|
||||
} else if (!hasTypeB) {
|
||||
errorMessage = 'For Titles, define at least one Translated title as MAIN TITLE.';
|
||||
}
|
||||
} else if (field.getFieldPath() === 'descriptions') {
|
||||
// For descriptions we expect one abstracts description and minimum one translated description.
|
||||
if (!hasTypeA && !hasTypeB) {
|
||||
errorMessage = 'For descriptions, define at least one abstract and at least one Translated description as MAIN ABSTRACT.';
|
||||
} else if (!hasTypeA) {
|
||||
errorMessage = 'For descriptions, define at least one abstract.';
|
||||
} else if (!hasTypeB) {
|
||||
errorMessage = 'For Descriptions, define at least one Translated description as MAIN ABSTRACT.';
|
||||
}
|
||||
}
|
||||
|
||||
field.report(errorMessage, 'array.containsTypes', field, options);
|
||||
return false;
|
||||
if (!hasTranslatedEntry) {
|
||||
const msg = isTitles
|
||||
? 'At least one Translated Title is required.'
|
||||
: 'At least one Translated Abstract is required.';
|
||||
field.report(msg, 'array.missing_translated', field);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export const arrayContainsMainAndTranslatedRule = vine.createRule(arrayContainsTypes);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue