mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
use cached schema if it exists for the field
This commit is contained in:
@@ -318,15 +318,37 @@ export abstract class EditForm<T extends HalResource = HalResource> {
|
||||
* @param fieldName
|
||||
*/
|
||||
private getFormFieldSchema(fieldName:string):Promise<IFieldSchema|null> {
|
||||
// Sync fast path: whatever schema the changeset currently exposes (form-derived if
|
||||
// loaded, otherwise the pristine resource's cached schema) usually contains the
|
||||
// field. Returning it synchronously lets the field activate without waiting on the
|
||||
// form request — required by Capybara specs whose activate! check has a tight
|
||||
// timeout, and by tests that intentionally disable AJAX before activating a field.
|
||||
const cachedSchema = (this.change.schema as ISchemaProxy).ofProperty(fieldName);
|
||||
if (cachedSchema) {
|
||||
// Still kick off the form load (or piggy-back on an in-flight one) so the form's
|
||||
// defaults, allowed values, and projected payload are populated for subsequent
|
||||
// edits/submissions. We don't await it, but we do surface any error (e.g. a 409
|
||||
// lock-version conflict when the resource was modified elsewhere) through the
|
||||
// same notification path the awaited code-path uses — otherwise the user would
|
||||
// open the editor without ever being told their copy is stale.
|
||||
this.change.getForm().catch((error:unknown) => {
|
||||
console.error('Background form load failed for %s: %o', fieldName, error);
|
||||
this.halNotification.handleRawError(error, this.resource);
|
||||
});
|
||||
return Promise.resolve(cachedSchema);
|
||||
}
|
||||
|
||||
// Cached schema doesn't know about this field. Either the form hasn't been loaded
|
||||
// at all, or the cached form is stale (e.g. the work package type was just changed
|
||||
// and the new type's custom fields aren't in the cached form yet). Load the form,
|
||||
// then retry; if still missing, force a full reload once.
|
||||
return this.change.getForm()
|
||||
.then(():Promise<IFieldSchema|null> => {
|
||||
const fieldSchema:IFieldSchema|null = (this.change.schema as ISchemaProxy).ofProperty(fieldName);
|
||||
|
||||
if (fieldSchema) {
|
||||
return Promise.resolve(fieldSchema);
|
||||
}
|
||||
|
||||
// The cached form may be stale (e.g. type just changed); force a reload and retry once.
|
||||
return this.change.getForm(true).then(
|
||||
():IFieldSchema|null => (this.change.schema as ISchemaProxy).ofProperty(fieldName),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user