diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-04 15:10:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-04 15:10:22 +0300 |
commit | 25f102516f8d77c397c768baa2e550779cc9c60b (patch) | |
tree | 1dd1bf83ad767d76933708bf948a7a7ccc6ff1ae /app/assets/javascripts/sidebar | |
parent | d246f33754d73408224d68e81e56fc2bd6f79301 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/sidebar')
3 files changed, 43 insertions, 11 deletions
diff --git a/app/assets/javascripts/sidebar/components/labels/labels_select_widget/dropdown_contents_create_view.vue b/app/assets/javascripts/sidebar/components/labels/labels_select_widget/dropdown_contents_create_view.vue index 8bbec6794ca..93e3cfba309 100644 --- a/app/assets/javascripts/sidebar/components/labels/labels_select_widget/dropdown_contents_create_view.vue +++ b/app/assets/javascripts/sidebar/components/labels/labels_select_widget/dropdown_contents_create_view.vue @@ -1,4 +1,5 @@ <script> +import { get } from 'lodash'; import { GlAlert, GlTooltipDirective, @@ -11,8 +12,7 @@ import produce from 'immer'; import { createAlert } from '~/alert'; import { WORKSPACE_GROUP } from '~/issues/constants'; import { __ } from '~/locale'; -import { workspaceLabelsQueries } from '../../../queries/constants'; -import createLabelMutation from './graphql/create_label.mutation.graphql'; +import { workspaceLabelsQueries, workspaceCreateLabelMutation } from '../../../queries/constants'; import { DEFAULT_LABEL_COLOR } from './constants'; const errorMessage = __('Error creating label.'); @@ -68,13 +68,19 @@ export default { return Object.keys(colorsMap).map((color) => ({ [color]: colorsMap[color] })); }, mutationVariables() { - const attributePath = this.labelCreateType === WORKSPACE_GROUP ? 'groupPath' : 'projectPath'; - - return { + const variables = { title: this.labelTitle, color: this.selectedColor, - [attributePath]: this.attrWorkspacePath, }; + + if (this.labelCreateType) { + const attributePath = + this.labelCreateType === WORKSPACE_GROUP ? 'groupPath' : 'projectPath'; + + return { ...variables, [attributePath]: this.attrWorkspacePath }; + } + + return variables; }, }, methods: { @@ -88,7 +94,7 @@ export default { this.selectedColor = this.getColorCode(color); }, updateLabelsInCache(store, label) { - const { query } = workspaceLabelsQueries[this.workspaceType]; + const { query, dataPath } = workspaceLabelsQueries[this.workspaceType]; const sourceData = store.readQuery({ query, @@ -97,7 +103,7 @@ export default { const collator = new Intl.Collator('en'); const data = produce(sourceData, (draftData) => { - const { nodes } = draftData.workspace.labels; + const { nodes } = get(draftData, dataPath); nodes.push(label); nodes.sort((a, b) => collator.compare(a.title, b.title)); }); @@ -114,7 +120,7 @@ export default { const { data: { labelCreate }, } = await this.$apollo.mutate({ - mutation: createLabelMutation, + mutation: workspaceCreateLabelMutation[this.workspaceType], variables: this.mutationVariables, update: ( store, diff --git a/app/assets/javascripts/sidebar/components/labels/labels_select_widget/dropdown_footer.vue b/app/assets/javascripts/sidebar/components/labels/labels_select_widget/dropdown_footer.vue index e67e704ffb8..d6b43698766 100644 --- a/app/assets/javascripts/sidebar/components/labels/labels_select_widget/dropdown_footer.vue +++ b/app/assets/javascripts/sidebar/components/labels/labels_select_widget/dropdown_footer.vue @@ -13,7 +13,13 @@ export default { }, footerManageLabelTitle: { type: String, - required: true, + required: false, + default: '', + }, + }, + computed: { + showManageLabelsItem() { + return this.footerManageLabelTitle && this.labelsManagePath; }, }, }; @@ -28,7 +34,12 @@ export default { > {{ footerCreateLabelTitle }} </gl-dropdown-item> - <gl-dropdown-item :href="labelsManagePath" @click.capture.native.stop> + <gl-dropdown-item + v-if="showManageLabelsItem" + data-testid="manage-labels-button" + :href="labelsManagePath" + @click.capture.native.stop + > {{ footerManageLabelTitle }} </gl-dropdown-item> </div> diff --git a/app/assets/javascripts/sidebar/queries/constants.js b/app/assets/javascripts/sidebar/queries/constants.js index 9f71091b8fc..05297795613 100644 --- a/app/assets/javascripts/sidebar/queries/constants.js +++ b/app/assets/javascripts/sidebar/queries/constants.js @@ -12,6 +12,9 @@ import { WORKSPACE_PROJECT, } from '~/issues/constants'; import updateAlertAssigneesMutation from '~/vue_shared/alert_details/graphql/mutations/alert_set_assignees.mutation.graphql'; +import abuseReportLabelsQuery from '~/admin/abuse_report/components/graphql/abuse_report_labels.query.graphql'; +import createAbuseReportLabelMutation from '~/admin/abuse_report/components/graphql/create_abuse_report_label.mutation.graphql'; +import createGroupOrProjectLabelMutation from '../components/labels/labels_select_widget/graphql/create_label.mutation.graphql'; import updateTestCaseLabelsMutation from '../components/labels/labels_select_widget/graphql/update_test_case_labels.mutation.graphql'; import epicLabelsQuery from '../components/labels/labels_select_widget/graphql/epic_labels.query.graphql'; import updateEpicLabelsMutation from '../components/labels/labels_select_widget/graphql/epic_update_labels.mutation.graphql'; @@ -134,10 +137,22 @@ export const referenceQueries = { export const workspaceLabelsQueries = { [WORKSPACE_PROJECT]: { query: projectLabelsQuery, + dataPath: 'workspace.labels', }, [WORKSPACE_GROUP]: { query: groupLabelsQuery, + dataPath: 'workspace.labels', }, + abuseReport: { + query: abuseReportLabelsQuery, + dataPath: 'labels', + }, +}; + +export const workspaceCreateLabelMutation = { + [WORKSPACE_PROJECT]: createGroupOrProjectLabelMutation, + [WORKSPACE_GROUP]: createGroupOrProjectLabelMutation, + abuseReport: createAbuseReportLabelMutation, }; export const issuableLabelsQueries = { |