From 7132619115e19316485892337251801b98c34a5b Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 18 Apr 2024 18:18:37 +0100 Subject: [PATCH] Fixed internal linking not correctly filtering to published-only (#20054) no issue - updated search to add `status` to the search results - added filtering to the editor's `searchLinks()` method - prevented TaskCancellation errors being thrown from the search task being cast to a Promise --- .../admin/app/components/koenig-lexical-editor.js | 15 ++++++++++++--- ghost/admin/app/services/search.js | 7 ++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ghost/admin/app/components/koenig-lexical-editor.js b/ghost/admin/app/components/koenig-lexical-editor.js index 992d66389c..f892c11c5c 100644 --- a/ghost/admin/app/components/koenig-lexical-editor.js +++ b/ghost/admin/app/components/koenig-lexical-editor.js @@ -4,9 +4,9 @@ import React, {Suspense} from 'react'; import fetch from 'fetch'; import ghostPaths from 'ghost-admin/utils/ghost-paths'; import {action} from '@ember/object'; +import {didCancel, task} from 'ember-concurrency'; import {inject} from 'ghost-admin/decorators/inject'; import {inject as service} from '@ember/service'; -import {task} from 'ember-concurrency'; export const fileTypes = { image: { @@ -311,14 +311,23 @@ export default class KoenigLexicalEditor extends Component { return this.defaultLinks; } - const results = await this.search.searchTask.perform(term); + let results = []; + + try { + results = await this.search.searchTask.perform(term); + } catch (error) { + // don't surface task cancellation errors + if (!didCancel(error)) { + throw error; + } + } // TODO: Add grouped results support to Koenig const flattenedResults = []; results.forEach(group => flattenedResults.push(...group.options)); // only published posts/pages have URLs - const filteredResults = flattenedResults.filter(result => result.groupName === 'Posts'); + const filteredResults = flattenedResults.filter(result => (result.groupName === 'Posts' || result.groupName === 'Pages') && result.status === 'published'); return filteredResults; }; diff --git a/ghost/admin/app/services/search.js b/ghost/admin/app/services/search.js index 0b4779bee6..56b28fa426 100644 --- a/ghost/admin/app/services/search.js +++ b/ghost/admin/app/services/search.js @@ -18,14 +18,14 @@ export default class SearchService extends Service { { name: 'Posts', model: 'post', - fields: ['id', 'url', 'title'], + fields: ['id', 'url', 'title', 'status'], idField: 'id', titleField: 'title' }, { name: 'Pages', model: 'page', - fields: ['id', 'url', 'title'], + fields: ['id', 'url', 'title', 'status'], idField: 'id', titleField: 'title' }, @@ -127,7 +127,8 @@ export default class SearchService extends Service { id: `${searchable.model}.${item[searchable.idField]}`, url: item.url, title: item[searchable.titleField], - groupName: searchable.name + groupName: searchable.name, + status: item.status }) );