diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-13 21:10:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-13 21:10:20 +0300 |
commit | b1928c08f1642be0f66f6fa2587177b95a1cedc1 (patch) | |
tree | 35cc089bc6692db0135437fe7834928fc64052fe /app/assets/javascripts/content_editor/extensions/suggestions.js | |
parent | bd25f1d9c685039381df23e49bc52cdcf4ec1b4a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/content_editor/extensions/suggestions.js')
-rw-r--r-- | app/assets/javascripts/content_editor/extensions/suggestions.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/app/assets/javascripts/content_editor/extensions/suggestions.js b/app/assets/javascripts/content_editor/extensions/suggestions.js index 1b345a36c7e..b6db7f9d358 100644 --- a/app/assets/javascripts/content_editor/extensions/suggestions.js +++ b/app/assets/javascripts/content_editor/extensions/suggestions.js @@ -3,7 +3,7 @@ import { VueRenderer } from '@tiptap/vue-2'; import tippy from 'tippy.js'; import Suggestion from '@tiptap/suggestion'; import { PluginKey } from 'prosemirror-state'; -import { isFunction, uniqueId } from 'lodash'; +import { isFunction, uniqueId, memoize } from 'lodash'; import axios from '~/lib/utils/axios_utils'; import { initEmojiMap, getAllEmoji } from '~/emoji'; import SuggestionsDropdown from '../components/suggestions_dropdown.vue'; @@ -21,6 +21,10 @@ function createSuggestionPlugin({ nodeType, nodeProps = {}, }) { + const fetchData = memoize( + isFunction(dataSource) ? dataSource : async () => (await axios.get(dataSource)).data, + ); + return Suggestion({ editor, char, @@ -38,9 +42,7 @@ function createSuggestionPlugin({ if (!dataSource) return []; try { - const items = isFunction(dataSource) - ? await dataSource() - : (await axios.get(dataSource)).data; + const items = await fetchData(); return items.filter(search(query)).slice(0, limit); } catch { |