Added fetchLabels to the Lexical config (#16774)

closes https://github.com/TryGhost/Team/issues/3183
- fetches all existing labels
- returns "id" and "name" fields
This commit is contained in:
Sag 2023-05-11 16:36:56 +02:00 committed by GitHub
parent 080a1c92d8
commit d86ac17e31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,6 +213,16 @@ export default class KoenigLexicalEditor extends Component {
return this.offers;
}
@task({restartable: true})
*fetchLabelsTask() {
if (this.labels) {
return this.labels;
}
this.labels = yield this.store.query('label', {limit: 'all', fields: 'id, name'});
return this.labels;
}
ReactComponent = (props) => {
const fetchEmbed = async (url, {type}) => {
let oembedEndpoint = this.ghostPaths.url.api('oembed');
@ -239,6 +249,17 @@ export default class KoenigLexicalEditor extends Component {
return [...defaults, ...offersLinks];
};
const fetchLabels = async () => {
const labels = await this.fetchLabelsTask.perform();
return labels.toArray().map((label) => {
return {
id: label.id,
name: label.name
};
});
};
const defaultCardConfig = {
unsplash: {
defaultHeaders: {
@ -252,6 +273,7 @@ export default class KoenigLexicalEditor extends Component {
tenor: this.config.tenor?.googleApiKey ? this.config.tenor : null,
fetchEmbed: fetchEmbed,
fetchAutocompleteLinks,
fetchLabels,
feature: {
signupCard: this.feature.get('signupCard')
}