Skip to content
代码片段 群组 项目
未验证 提交 381fc65c 编辑于 作者: David Pisek's avatar David Pisek 提交者: GitLab
浏览文件

Merge branch '513314-dropdown-text-explainer' into 'master'

Add dropdown suggestion text on component token

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/181132



Merged-by: default avatarDavid Pisek <dpisek@gitlab.com>
Approved-by: default avatarDavid Pisek <dpisek@gitlab.com>
Reviewed-by: default avatarDavid Pisek <dpisek@gitlab.com>
Co-authored-by: default avatarSamantha Ming <sming@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -12,6 +12,8 @@ import { NAMESPACE_GROUP, NAMESPACE_PROJECT } from 'ee/dependencies/constants'; ...@@ -12,6 +12,8 @@ import { NAMESPACE_GROUP, NAMESPACE_PROJECT } from 'ee/dependencies/constants';
import groupComponentsQuery from 'ee/dependencies/graphql/group_components.query.graphql'; import groupComponentsQuery from 'ee/dependencies/graphql/group_components.query.graphql';
import projectComponentsQuery from 'ee/dependencies/graphql/project_components.query.graphql'; import projectComponentsQuery from 'ee/dependencies/graphql/project_components.query.graphql';
const MIN_CHARS = 3;
export default { export default {
components: { components: {
GlIcon, GlIcon,
...@@ -40,12 +42,18 @@ export default { ...@@ -40,12 +42,18 @@ export default {
searchTerm: '', searchTerm: '',
components: [], components: [],
selectedComponents: [], selectedComponents: [],
/**
* Not using apollo.loading because debounce causes a UX issue where "noResult" state
* shows during the debounce period. Manual setting the loading state allows to show
* loading during the debounce period.
*
* More info here:
* https://gitlab.com/gitlab-org/gitlab/-/merge_requests/181132#note_2342436669
*/
isLoadingComponents: false,
}; };
}, },
computed: { computed: {
isLoadingComponents() {
return this.$apollo.queries.components.loading;
},
filteredComponents() { filteredComponents() {
if (!this.searchTerm) { if (!this.searchTerm) {
return this.components; return this.components;
...@@ -93,6 +101,12 @@ export default { ...@@ -93,6 +101,12 @@ export default {
{ namespaceType: this.namespaceType }, { namespaceType: this.namespaceType },
); );
}, },
isSearchTermTooShort() {
return this.searchTerm.length < MIN_CHARS;
},
shouldShowPlaceholder() {
return this.isSearchTermTooShort && !this.components.length;
},
}, },
apollo: { apollo: {
components: { components: {
...@@ -110,13 +124,18 @@ export default { ...@@ -110,13 +124,18 @@ export default {
// Remove __typename // Remove __typename
return data[this.namespaceType]?.components?.map(({ id, name }) => ({ name, id })); return data[this.namespaceType]?.components?.map(({ id, name }) => ({ name, id }));
}, },
result() {
this.isLoadingComponents = false;
},
error() { error() {
this.isLoadingComponents = false;
createAlert({ createAlert({
message: this.fetchErrorMessage, message: this.fetchErrorMessage,
}); });
}, },
skip() { skip() {
return this.searchTerm === ''; return this.isSearchTermTooShort;
}, },
}, },
}, },
...@@ -135,9 +154,14 @@ export default { ...@@ -135,9 +154,14 @@ export default {
// the data can be either a string or an array, in which case we don't want to perform the search // the data can be either a string or an array, in which case we don't want to perform the search
if (typeof token.data === 'string') { if (typeof token.data === 'string') {
this.searchTerm = token.data.toLowerCase(); this.searchTerm = token.data.toLowerCase();
this.isLoadingComponents = token.data.length >= MIN_CHARS;
} }
}, },
}, },
i18n: {
placeholder: s__('Dependencies|Enter at least 3 characters to view available components.'),
noResult: s__('Dependencies|No components found.'),
},
}; };
</script> </script>
...@@ -180,6 +204,12 @@ export default { ...@@ -180,6 +204,12 @@ export default {
{{ component.name }} {{ component.name }}
</div> </div>
</gl-filtered-search-suggestion> </gl-filtered-search-suggestion>
<div v-if="shouldShowPlaceholder" class="gl-p-2 gl-text-secondary">
{{ $options.i18n.placeholder }}
</div>
<div v-else-if="!components.length" class="gl-p-2 gl-text-secondary">
{{ $options.i18n.noResult }}
</div>
</template> </template>
</template> </template>
</gl-filtered-search-token> </gl-filtered-search-token>
......
...@@ -251,4 +251,37 @@ describe('ee/dependencies/components/filtered_search/tokens/component_token.vue' ...@@ -251,4 +251,37 @@ describe('ee/dependencies/components/filtered_search/tokens/component_token.vue'
expect(findSuggestions().exists()).toBe(false); expect(findSuggestions().exists()).toBe(false);
}); });
}); });
describe('where there is a suggestion dropdown', () => {
it('displays when user types less than 3 characters', async () => {
createComponent({ mountFn: mountExtended });
const suggestionText = 'Enter at least 3 characters to view available components.';
await searchForComponent('we');
expect(wrapper.text()).toBe(suggestionText);
await searchForComponent('web');
expect(wrapper.text()).not.toBe(suggestionText);
});
it('displays when no results are found', async () => {
createComponent({
handlers: {
getGroupComponentsHandler: jest.fn().mockResolvedValue({
data: {
group: {
id: 'some-group-id',
components: [],
},
},
}),
},
});
await searchForComponent('XXXXXXXX');
expect(wrapper.text()).toBe('No components found.');
});
});
}); });
...@@ -19473,6 +19473,9 @@ msgstr "" ...@@ -19473,6 +19473,9 @@ msgstr ""
msgid "Dependencies|Direct dependents" msgid "Dependencies|Direct dependents"
msgstr "" msgstr ""
   
msgid "Dependencies|Enter at least 3 characters to view available components."
msgstr ""
msgid "Dependencies|Error exporting the dependency list. Please reload the page." msgid "Dependencies|Error exporting the dependency list. Please reload the page."
msgstr "" msgstr ""
   
...@@ -19500,6 +19503,9 @@ msgstr "" ...@@ -19500,6 +19503,9 @@ msgstr ""
msgid "Dependencies|Location" msgid "Dependencies|Location"
msgstr "" msgstr ""
   
msgid "Dependencies|No components found."
msgstr ""
msgid "Dependencies|Packager" msgid "Dependencies|Packager"
msgstr "" msgstr ""
   
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册