Fixed post/page requests in Admin not including correct ?formats param

no issue

- `buildQuery` method in adapters is only used for store `.query()` calls so when saving the formats param wasn't being added meaning we were losing the `lexical` field in the API response
- switched to `buildURL` which is always used
This commit is contained in:
Kevin Ansfield 2022-09-15 17:40:45 +01:00
parent 6f3c18b6f4
commit 58b0a1b90d
2 changed files with 26 additions and 8 deletions

View File

@ -6,11 +6,20 @@ export default class Page extends ApplicationAdapter {
return this.buildURL(modelName, id, snapshot, requestType, query);
}
buildQuery(store, modelName, options) {
if (!options.formats) {
options.formats = 'mobiledoc,lexical';
buildURL() {
const url = super.buildURL(...arguments);
try {
const parsedUrl = new URL(url);
if (!parsedUrl.searchParams.get('formats')) {
parsedUrl.searchParams.set('formats', 'mobiledoc,lexical');
return parsedUrl.href;
}
} catch (e) {
// noop, just use the original url
console.error('Couldn\'t parse URL', e); // eslint-disable-line
}
return options;
return url;
}
}

View File

@ -24,11 +24,20 @@ export default class Post extends ApplicationAdapter {
return parsedUrl.toString();
}
buildQuery(store, modelName, options) {
if (!options.formats) {
options.formats = 'mobiledoc,lexical';
buildURL() {
const url = super.buildURL(...arguments);
try {
const parsedUrl = new URL(url);
if (!parsedUrl.searchParams.get('formats')) {
parsedUrl.searchParams.set('formats', 'mobiledoc,lexical');
return parsedUrl.href;
}
} catch (e) {
// noop, just use the original url
console.error('Couldn\'t parse URL', e); // eslint-disable-line
}
return options;
return url;
}
}