From 8d2c267efcdb6adbf69ce60d84ad7a73b18a5eb6 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 25 Nov 2021 06:12:46 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../boards/components/board_filtered_search.vue | 21 +++++++ .../components/issue_board_filtered_search.vue | 35 ++++++++++- app/assets/javascripts/boards/index.js | 3 +- .../boards/mount_filtered_search_issue_boards.js | 3 +- .../sidebar/components/sidebar_dropdown_widget.vue | 69 ++++++++-------------- app/assets/javascripts/sidebar/constants.js | 33 +++++++++++ app/helpers/boards_helper.rb | 9 +++ locale/gitlab.pot | 3 + qa/qa/page/component/blob_content.rb | 7 ++- spec/features/boards/board_filters_spec.rb | 58 ++++++++++++++++++ .../components/board_filtered_search_spec.js | 3 +- .../components/issue_board_filtered_search_spec.js | 1 + spec/frontend/boards/mock_data.js | 8 +++ .../components/sidebar_dropdown_widget_spec.js | 14 +++-- spec/views/layouts/_head.html.haml_spec.rb | 2 +- 15 files changed, 210 insertions(+), 59 deletions(-) create mode 100644 spec/features/boards/board_filters_spec.rb diff --git a/app/assets/javascripts/boards/components/board_filtered_search.vue b/app/assets/javascripts/boards/components/board_filtered_search.vue index 6fa5f018875..f66bc7887dc 100644 --- a/app/assets/javascripts/boards/components/board_filtered_search.vue +++ b/app/assets/javascripts/boards/components/board_filtered_search.vue @@ -44,6 +44,7 @@ export default { weight, epicId, myReactionEmoji, + releaseTag, } = this.filterParams; const filteredSearchValue = []; @@ -105,6 +106,13 @@ export default { }); } + if (releaseTag) { + filteredSearchValue.push({ + type: 'release', + value: { data: releaseTag, operator: '=' }, + }); + } + if (epicId) { filteredSearchValue.push({ type: 'epic_id', @@ -177,6 +185,13 @@ export default { }); } + if (this.filterParams['not[releaseTag]']) { + filteredSearchValue.push({ + type: 'release', + value: { data: this.filterParams['not[releaseTag]'], operator: '!=' }, + }); + } + if (search) { filteredSearchValue.push(search); } @@ -195,6 +210,7 @@ export default { epicId, myReactionEmoji, iterationId, + releaseTag, } = this.filterParams; let notParams = {}; @@ -210,6 +226,7 @@ export default { 'not[epic_id]': this.filterParams.not.epicId, 'not[my_reaction_emoji]': this.filterParams.not.myReactionEmoji, 'not[iteration_id]': this.filterParams.not.iterationId, + 'not[release_tag]': this.filterParams.not.releaseTag, }, undefined, ); @@ -227,6 +244,7 @@ export default { weight, epic_id: getIdFromGraphQLId(epicId), my_reaction_emoji: myReactionEmoji, + release_tag: releaseTag, }; }, }, @@ -290,6 +308,9 @@ export default { case 'my_reaction_emoji': filterParams.myReactionEmoji = filter.value.data; break; + case 'release': + filterParams.releaseTag = filter.value.data; + break; case 'filtered-search-term': if (filter.value.data) plainText.push(filter.value.data); break; diff --git a/app/assets/javascripts/boards/components/issue_board_filtered_search.vue b/app/assets/javascripts/boards/components/issue_board_filtered_search.vue index aa6ffa500ea..b5270c9d5fa 100644 --- a/app/assets/javascripts/boards/components/issue_board_filtered_search.vue +++ b/app/assets/javascripts/boards/components/issue_board_filtered_search.vue @@ -5,6 +5,7 @@ import { mapActions } from 'vuex'; import BoardFilteredSearch from 'ee_else_ce/boards/components/board_filtered_search.vue'; import { BoardType } from '~/boards/constants'; import axios from '~/lib/utils/axios_utils'; +import { joinPaths } from '~/lib/utils/url_utility'; import issueBoardFilters from '~/boards/issue_board_filters'; import { TYPE_USER } from '~/graphql_shared/constants'; import { convertToGraphQLId } from '~/graphql_shared/utils'; @@ -18,6 +19,7 @@ import AuthorToken from '~/vue_shared/components/filtered_search_bar/tokens/auth import EmojiToken from '~/vue_shared/components/filtered_search_bar/tokens/emoji_token.vue'; import LabelToken from '~/vue_shared/components/filtered_search_bar/tokens/label_token.vue'; import MilestoneToken from '~/vue_shared/components/filtered_search_bar/tokens/milestone_token.vue'; +import ReleaseToken from '~/vue_shared/components/filtered_search_bar/tokens/release_token.vue'; export default { types: { @@ -34,9 +36,10 @@ export default { incident: __('Incident'), issue: __('Issue'), milestone: __('Milestone'), + release: __('Release'), }, components: { BoardFilteredSearch }, - inject: ['isSignedIn'], + inject: ['isSignedIn', 'releasesFetchPath'], props: { fullPath: { type: String, @@ -57,7 +60,16 @@ export default { : this.fullPath.slice(0, this.fullPath.lastIndexOf('/')); }, tokensCE() { - const { label, author, assignee, issue, incident, type, milestone } = this.$options.i18n; + const { + label, + author, + assignee, + issue, + incident, + type, + milestone, + release, + } = this.$options.i18n; const { types } = this.$options; const { fetchAuthors, fetchLabels } = issueBoardFilters( this.$apollo, @@ -144,6 +156,25 @@ export default { { icon: 'issue-type-incident', value: types.INCIDENT, title: incident }, ], }, + { + type: 'release', + title: release, + icon: 'rocket', + token: ReleaseToken, + fetchReleases: (search) => { + // TODO: Switch to GraphQL query when backend is ready: https://gitlab.com/gitlab-org/gitlab/-/issues/337686 + return axios + .get(joinPaths(gon.relative_url_root, this.releasesFetchPath)) + .then(({ data }) => { + if (search) { + return fuzzaldrinPlus.filter(data, search, { + key: ['tag'], + }); + } + return data; + }); + }, + }, ]; }, tokens() { diff --git a/app/assets/javascripts/boards/index.js b/app/assets/javascripts/boards/index.js index 6fa8dd63245..ded3bfded86 100644 --- a/app/assets/javascripts/boards/index.js +++ b/app/assets/javascripts/boards/index.js @@ -110,7 +110,8 @@ export default () => { }); if (gon?.features?.issueBoardsFilteredSearch) { - initBoardsFilteredSearch(apolloProvider, isLoggedIn()); + const { releasesFetchPath } = $boardApp.dataset; + initBoardsFilteredSearch(apolloProvider, isLoggedIn(), releasesFetchPath); } mountBoardApp($boardApp); diff --git a/app/assets/javascripts/boards/mount_filtered_search_issue_boards.js b/app/assets/javascripts/boards/mount_filtered_search_issue_boards.js index 1ea74d5685c..a8ade58e316 100644 --- a/app/assets/javascripts/boards/mount_filtered_search_issue_boards.js +++ b/app/assets/javascripts/boards/mount_filtered_search_issue_boards.js @@ -4,7 +4,7 @@ import store from '~/boards/stores'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { queryToObject } from '~/lib/utils/url_utility'; -export default (apolloProvider, isSignedIn) => { +export default (apolloProvider, isSignedIn, releasesFetchPath) => { const el = document.getElementById('js-issue-board-filtered-search'); const rawFilterParams = queryToObject(window.location.search, { gatherArrays: true }); @@ -21,6 +21,7 @@ export default (apolloProvider, isSignedIn) => { provide: { initialFilterParams, isSignedIn, + releasesFetchPath, }, store, // TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/324094 apolloProvider, diff --git a/app/assets/javascripts/sidebar/components/sidebar_dropdown_widget.vue b/app/assets/javascripts/sidebar/components/sidebar_dropdown_widget.vue index 0ba8c4f8907..a5e39e31024 100644 --- a/app/assets/javascripts/sidebar/components/sidebar_dropdown_widget.vue +++ b/app/assets/javascripts/sidebar/components/sidebar_dropdown_widget.vue @@ -14,9 +14,10 @@ import createFlash from '~/flash'; import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { IssuableType } from '~/issue_show/constants'; import { timeFor } from '~/lib/utils/datetime_utility'; -import { __, s__, sprintf } from '~/locale'; +import { __ } from '~/locale'; import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue'; import { + dropdowni18nText, Tracking, IssuableAttributeState, IssuableAttributeType, @@ -24,14 +25,11 @@ import { noAttributeId, defaultEpicSort, epicIidPattern, -} from '~/sidebar/constants'; +} from 'ee_else_ce/sidebar/constants'; export default { noAttributeId, - IssuableAttributeState, - issuableAttributesQueries, i18n: { - [IssuableAttributeType.Milestone]: __('Milestone'), expired: __('(expired)'), none: __('None'), }, @@ -53,14 +51,24 @@ export default { isClassicSidebar: { default: false, }, + issuableAttributesQueries: { + default: issuableAttributesQueries, + }, + issuableAttributesState: { + default: IssuableAttributeState, + }, + widgetTitleText: { + default: { + [IssuableAttributeType.Milestone]: __('Milestone'), + expired: __('(expired)'), + none: __('None'), + }, + }, }, props: { issuableAttribute: { type: String, required: true, - validator(value) { - return [IssuableAttributeType.Milestone].includes(value); - }, }, workspacePath: { required: true, @@ -132,13 +140,13 @@ export default { return { fullPath: this.attrWorkspacePath, title: this.searchTerm, - state: this.$options.IssuableAttributeState[this.issuableAttribute], + state: this.issuableAttributesState[this.issuableAttribute], }; } const variables = { fullPath: this.attrWorkspacePath, - state: this.$options.IssuableAttributeState[this.issuableAttribute], + state: this.issuableAttributesState[this.issuableAttribute], sort: defaultEpicSort, }; @@ -180,7 +188,7 @@ export default { }, computed: { issuableAttributeQuery() { - return this.$options.issuableAttributesQueries[this.issuableAttribute]; + return this.issuableAttributesQueries[this.issuableAttribute]; }, attributeTitle() { return this.currentAttribute?.title || this.i18n.noAttribute; @@ -189,9 +197,7 @@ export default { return this.currentAttribute?.webUrl; }, dropdownText() { - return this.currentAttribute - ? this.currentAttribute?.title - : this.$options.i18n[this.issuableAttribute]; + return this.currentAttribute ? this.currentAttribute?.title : this.attributeTypeTitle; }, loading() { return this.$apollo.queries.currentAttribute.loading; @@ -200,7 +206,7 @@ export default { return this.attributesList.length === 0; }, attributeTypeTitle() { - return this.$options.i18n[this.issuableAttribute]; + return this.widgetTitleText[this.issuableAttribute]; }, attributeTypeIcon() { return this.icon || this.issuableAttribute; @@ -209,37 +215,10 @@ export default { return timeFor(this.currentAttribute?.dueDate); }, i18n() { - return { - noAttribute: sprintf(s__('DropdownWidget|No %{issuableAttribute}'), { - issuableAttribute: this.issuableAttribute, - }), - assignAttribute: sprintf(s__('DropdownWidget|Assign %{issuableAttribute}'), { - issuableAttribute: this.issuableAttribute, - }), - noAttributesFound: sprintf(s__('DropdownWidget|No %{issuableAttribute} found'), { - issuableAttribute: this.issuableAttribute, - }), - updateError: sprintf( - s__( - 'DropdownWidget|Failed to set %{issuableAttribute} on this %{issuableType}. Please try again.', - ), - { issuableAttribute: this.issuableAttribute, issuableType: this.issuableType }, - ), - listFetchError: sprintf( - s__( - 'DropdownWidget|Failed to fetch the %{issuableAttribute} for this %{issuableType}. Please try again.', - ), - { issuableAttribute: this.issuableAttribute, issuableType: this.issuableType }, - ), - currentFetchError: sprintf( - s__( - 'DropdownWidget|An error occurred while fetching the assigned %{issuableAttribute} of the selected %{issuableType}.', - ), - { issuableAttribute: this.issuableAttribute, issuableType: this.issuableType }, - ), - }; + return dropdowni18nText(this.issuableAttribute, this.issuableType); }, isEpic() { + // MV to EE https://gitlab.com/gitlab-org/gitlab/-/issues/345311 return this.issuableAttribute === IssuableType.Epic; }, }, @@ -252,7 +231,7 @@ export default { const selectedAttribute = Boolean(attributeId) && this.attributesList.find((p) => p.id === attributeId); - this.selectedTitle = selectedAttribute ? selectedAttribute.title : this.$options.i18n.none; + this.selectedTitle = selectedAttribute ? selectedAttribute.title : this.widgetTitleText.none; const { current } = this.issuableAttributeQuery; const { mutation } = current[this.issuableType]; diff --git a/app/assets/javascripts/sidebar/constants.js b/app/assets/javascripts/sidebar/constants.js index ac34a75ac5c..c2e16bbe6f9 100644 --- a/app/assets/javascripts/sidebar/constants.js +++ b/app/assets/javascripts/sidebar/constants.js @@ -1,3 +1,4 @@ +import { s__, sprintf } from '~/locale'; import updateIssueLabelsMutation from '~/boards/graphql/issue_set_labels.mutation.graphql'; import { IssuableType, WorkspaceType } from '~/issue_show/constants'; import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants'; @@ -272,3 +273,35 @@ export const todoMutations = { [TodoMutationTypes.Create]: todoCreateMutation, [TodoMutationTypes.MarkDone]: todoMarkDoneMutation, }; + +export function dropdowni18nText(issuableAttribute, issuableType) { + return { + noAttribute: sprintf(s__('DropdownWidget|No %{issuableAttribute}'), { + issuableAttribute, + }), + assignAttribute: sprintf(s__('DropdownWidget|Assign %{issuableAttribute}'), { + issuableAttribute, + }), + noAttributesFound: sprintf(s__('DropdownWidget|No %{issuableAttribute} found'), { + issuableAttribute, + }), + updateError: sprintf( + s__( + 'DropdownWidget|Failed to set %{issuableAttribute} on this %{issuableType}. Please try again.', + ), + { issuableAttribute, issuableType }, + ), + listFetchError: sprintf( + s__( + 'DropdownWidget|Failed to fetch the %{issuableAttribute} for this %{issuableType}. Please try again.', + ), + { issuableAttribute, issuableType }, + ), + currentFetchError: sprintf( + s__( + 'DropdownWidget|An error occurred while fetching the assigned %{issuableAttribute} of the selected %{issuableType}.', + ), + { issuableAttribute, issuableType }, + ), + }; +} diff --git a/app/helpers/boards_helper.rb b/app/helpers/boards_helper.rb index c26a73028b9..57da04b38cc 100644 --- a/app/helpers/boards_helper.rb +++ b/app/helpers/boards_helper.rb @@ -23,6 +23,7 @@ module BoardsHelper labels_filter_base_path: build_issue_link_base, labels_fetch_path: labels_fetch_path, labels_manage_path: labels_manage_path, + releases_fetch_path: releases_fetch_path, board_type: board.to_type } end @@ -65,6 +66,14 @@ module BoardsHelper end end + def releases_fetch_path + if board.group_board? + group_releases_path(@group) + else + project_releases_path(@project) + end + end + def board_base_url if board.group_board? group_boards_url(@group) diff --git a/locale/gitlab.pot b/locale/gitlab.pot index d9e85ad9dd7..099cf345bae 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -12482,6 +12482,9 @@ msgstr "" msgid "DropdownWidget|No %{issuableAttribute} found" msgstr "" +msgid "DropdownWidget|No open %{issuableAttribute} found" +msgstr "" + msgid "Due Date" msgstr "" diff --git a/qa/qa/page/component/blob_content.rb b/qa/qa/page/component/blob_content.rb index 92763195c74..4d36a6dcefe 100644 --- a/qa/qa/page/component/blob_content.rb +++ b/qa/qa/page/component/blob_content.rb @@ -74,8 +74,11 @@ module QA end def within_file_by_number(element, file_number) - method = file_number ? 'within_element_by_index' : 'within_element' - send(method, element, file_number) { yield } + if file_number + within_element_by_index(element, file_number - 1) { yield } + else + within_element(element) { yield } + end end end end diff --git a/spec/features/boards/board_filters_spec.rb b/spec/features/boards/board_filters_spec.rb new file mode 100644 index 00000000000..5eb8f43df07 --- /dev/null +++ b/spec/features/boards/board_filters_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Issue board filters', :js do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let_it_be(:board) { create(:board, project: project) } + let_it_be(:milestone_1) { create(:milestone, project: project) } + let_it_be(:milestone_2) { create(:milestone, project: project) } + let_it_be(:release) { create(:release, tag: 'v1.0', project: project, milestones: [milestone_1]) } + let_it_be(:release_2) { create(:release, tag: 'v2.0', project: project, milestones: [milestone_2]) } + let_it_be(:issue) { create(:issue, project: project, milestone: milestone_1) } + let_it_be(:issue_2) { create(:issue, project: project, milestone: milestone_2) } + + let(:filtered_search) { find('[data-testid="issue-board-filtered-search"]') } + let(:filter_input) { find('.gl-filtered-search-term-input')} + let(:filter_dropdown) { find('.gl-filtered-search-suggestion-list') } + let(:filter_first_suggestion) { find('.gl-filtered-search-suggestion-list').first('.gl-filtered-search-suggestion') } + let(:filter_submit) { find('.gl-search-box-by-click-search-button') } + + before do + stub_feature_flags(issue_boards_filtered_search: true) + + project.add_maintainer(user) + sign_in(user) + + visit_project_board + end + + describe 'filters by releases' do + before do + filter_input.click + filter_input.set('release:') + filter_first_suggestion.click # Select `=` operator + end + + it 'loads all the releases when opened and submit one as filter', :aggregate_failures do + expect(find('.board:nth-child(1)')).to have_selector('.board-card', count: 2) + + expect_filtered_search_dropdown_results(filter_dropdown, 2) + + click_on release.tag + filter_submit.click + + expect(find('.board:nth-child(1)')).to have_selector('.board-card', count: 1) + end + end + + def expect_filtered_search_dropdown_results(filter_dropdown, count) + expect(filter_dropdown).to have_selector('.gl-new-dropdown-item', count: count) + end + + def visit_project_board + visit project_board_path(project, board) + wait_for_requests + end +end diff --git a/spec/frontend/boards/components/board_filtered_search_spec.js b/spec/frontend/boards/components/board_filtered_search_spec.js index 356cc22a2db..65a3ed2f788 100644 --- a/spec/frontend/boards/components/board_filtered_search_spec.js +++ b/spec/frontend/boards/components/board_filtered_search_spec.js @@ -124,6 +124,7 @@ describe('BoardFilteredSearch', () => { { type: 'types', value: { data: 'INCIDENT', operator: '=' } }, { type: 'weight', value: { data: '2', operator: '=' } }, { type: 'iteration', value: { data: '3341', operator: '=' } }, + { type: 'release', value: { data: 'v1.0.0', operator: '=' } }, ]; jest.spyOn(urlUtility, 'updateHistory'); findFilteredSearch().vm.$emit('onFilter', mockFilters); @@ -132,7 +133,7 @@ describe('BoardFilteredSearch', () => { title: '', replace: true, url: - 'http://test.host/?author_username=root&label_name[]=label&label_name[]=label2&milestone_title=New+Milestone&iteration_id=3341&types=INCIDENT&weight=2', + 'http://test.host/?author_username=root&label_name[]=label&label_name[]=label2&milestone_title=New+Milestone&iteration_id=3341&types=INCIDENT&weight=2&release_tag=v1.0.0', }); }); }); diff --git a/spec/frontend/boards/components/issue_board_filtered_search_spec.js b/spec/frontend/boards/components/issue_board_filtered_search_spec.js index 45c5c87d800..af2ad90396f 100644 --- a/spec/frontend/boards/components/issue_board_filtered_search_spec.js +++ b/spec/frontend/boards/components/issue_board_filtered_search_spec.js @@ -16,6 +16,7 @@ describe('IssueBoardFilter', () => { propsData: { fullPath: 'gitlab-org', boardType: 'group' }, provide: { isSignedIn, + releasesFetchPath: '/releases', }, }); }; diff --git a/spec/frontend/boards/mock_data.js b/spec/frontend/boards/mock_data.js index 25764269677..035f0ac2915 100644 --- a/spec/frontend/boards/mock_data.js +++ b/spec/frontend/boards/mock_data.js @@ -7,6 +7,7 @@ import AuthorToken from '~/vue_shared/components/filtered_search_bar/tokens/auth import EmojiToken from '~/vue_shared/components/filtered_search_bar/tokens/emoji_token.vue'; import LabelToken from '~/vue_shared/components/filtered_search_bar/tokens/label_token.vue'; import MilestoneToken from '~/vue_shared/components/filtered_search_bar/tokens/milestone_token.vue'; +import ReleaseToken from '~/vue_shared/components/filtered_search_bar/tokens/release_token.vue'; export const boardObj = { id: 1, @@ -615,6 +616,13 @@ export const mockTokens = (fetchLabels, fetchAuthors, fetchMilestones, hasEmoji) { icon: 'issue-type-incident', value: 'INCIDENT', title: 'Incident' }, ], }, + { + type: 'release', + title: __('Release'), + icon: 'rocket', + token: ReleaseToken, + fetchReleases: expect.any(Function), + }, ]; export const mockLabel1 = { diff --git a/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js b/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js index ca6e5ac5e7f..c9c121d12a6 100644 --- a/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js +++ b/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js @@ -369,16 +369,18 @@ describe('SidebarDropdownWidget', () => { describe('when a user is searching', () => { describe('when search result is not found', () => { - it('renders "No milestone found"', async () => { - createComponent(); + describe('when milestone', () => { + it('renders "No milestone found"', async () => { + createComponent(); - await toggleDropdown(); + await toggleDropdown(); - findSearchBox().vm.$emit('input', 'non existing milestones'); + findSearchBox().vm.$emit('input', 'non existing milestones'); - await wrapper.vm.$nextTick(); + await wrapper.vm.$nextTick(); - expect(findDropdownText().text()).toBe('No milestone found'); + expect(findDropdownText().text()).toBe('No milestone found'); + }); }); }); }); diff --git a/spec/views/layouts/_head.html.haml_spec.rb b/spec/views/layouts/_head.html.haml_spec.rb index 2c7289deaef..f9725c73d05 100644 --- a/spec/views/layouts/_head.html.haml_spec.rb +++ b/spec/views/layouts/_head.html.haml_spec.rb @@ -62,7 +62,7 @@ RSpec.describe 'layouts/_head' do expect(rendered).to match('') end - context 'when an asset_host is set and snowplow url is set' do + context 'when an asset_host is set and snowplow url is set', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/346542' do let(:asset_host) { 'http://test.host' } let(:snowplow_collector_hostname) { 'www.snow.plow' } -- cgit v1.2.3