debian-mirror-gitlab/app/assets/javascripts/issuable/components/status_box.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

134 lines
3.1 KiB
Vue
Raw Normal View History

2021-06-08 01:23:25 +05:30
<script>
2022-07-16 23:28:13 +05:30
import { GlBadge, GlIcon } from '@gitlab/ui';
2021-06-08 01:23:25 +05:30
import Vue from 'vue';
2022-07-16 23:28:13 +05:30
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2021-06-08 01:23:25 +05:30
import { fetchPolicies } from '~/lib/graphql';
import { __ } from '~/locale';
2023-04-23 21:23:45 +05:30
import { IssuableType, TYPE_ISSUE } from '~/issues/constants';
2022-07-16 23:28:13 +05:30
import { IssuableStates } from '~/vue_shared/issuable/list/constants';
2021-06-08 01:23:25 +05:30
2022-07-16 23:28:13 +05:30
export const badgeState = Vue.observable({
2021-06-08 01:23:25 +05:30
state: '',
updateStatus: null,
});
const CLASSES = {
2022-07-16 23:28:13 +05:30
opened: 'issuable-status-badge-open',
locked: 'issuable-status-badge-open',
closed: 'issuable-status-badge-closed',
merged: 'issuable-status-badge-merged',
};
const ISSUE_ICONS = {
opened: 'issues',
locked: 'issues',
closed: 'issue-closed',
};
const MERGE_REQUEST_ICONS = {
opened: 'merge-request-open',
locked: 'merge-request-open',
closed: 'merge-request-close',
merged: 'merge',
2021-06-08 01:23:25 +05:30
};
const STATUS = {
2022-07-16 23:28:13 +05:30
opened: __('Open'),
locked: __('Open'),
closed: __('Closed'),
merged: __('Merged'),
2021-06-08 01:23:25 +05:30
};
export default {
components: {
2022-07-16 23:28:13 +05:30
GlBadge,
2021-06-08 01:23:25 +05:30
GlIcon,
},
2022-07-16 23:28:13 +05:30
mixins: [glFeatureFlagMixin()],
2021-06-08 01:23:25 +05:30
inject: {
query: { default: null },
projectPath: { default: null },
iid: { default: null },
},
props: {
initialState: {
type: String,
required: false,
default: null,
},
issuableType: {
type: String,
required: false,
default: '',
},
},
data() {
2022-07-23 23:45:48 +05:30
if (!this.iid) return { state: this.initialState };
2022-10-11 01:57:18 +05:30
if (this.initialState && !badgeState.state) {
2022-07-16 23:28:13 +05:30
badgeState.state = this.initialState;
2021-06-08 01:23:25 +05:30
}
2022-07-16 23:28:13 +05:30
return badgeState;
2021-06-08 01:23:25 +05:30
},
computed: {
2022-07-16 23:28:13 +05:30
badgeClass() {
return [
CLASSES[this.state],
{
2022-07-23 23:45:48 +05:30
'gl-vertical-align-bottom': this.issuableType === IssuableType.MergeRequest,
2022-07-16 23:28:13 +05:30
},
];
},
badgeVariant() {
if (this.state === IssuableStates.Opened) {
return 'success';
} else if (this.state === IssuableStates.Closed) {
return this.issuableType === IssuableType.MergeRequest ? 'danger' : 'info';
}
return 'info';
2021-06-08 01:23:25 +05:30
},
2022-07-16 23:28:13 +05:30
badgeText() {
return STATUS[this.state];
2021-06-08 01:23:25 +05:30
},
2022-07-16 23:28:13 +05:30
badgeIcon() {
2023-04-23 21:23:45 +05:30
if (this.issuableType === TYPE_ISSUE) {
2022-07-16 23:28:13 +05:30
return ISSUE_ICONS[this.state];
}
return MERGE_REQUEST_ICONS[this.state];
2021-06-08 01:23:25 +05:30
},
},
created() {
2022-07-16 23:28:13 +05:30
if (!badgeState.updateStatus) {
badgeState.updateStatus = this.fetchState;
2021-06-08 01:23:25 +05:30
}
},
beforeDestroy() {
2022-07-16 23:28:13 +05:30
if (badgeState.updateStatus && this.query) {
badgeState.updateStatus = null;
2021-06-08 01:23:25 +05:30
}
},
methods: {
async fetchState() {
const { data } = await this.$apollo.query({
query: this.query,
variables: {
projectPath: this.projectPath,
iid: this.iid,
},
fetchPolicy: fetchPolicies.NO_CACHE,
});
2022-07-16 23:28:13 +05:30
badgeState.state = data?.workspace?.issuable?.state;
2021-06-08 01:23:25 +05:30
},
},
};
</script>
<template>
2022-07-16 23:28:13 +05:30
<gl-badge class="issuable-status-badge gl-mr-3" :class="badgeClass" :variant="badgeVariant">
<gl-icon :name="badgeIcon" />
<span class="gl-display-none gl-sm-display-block gl-ml-2">{{ badgeText }}</span>
</gl-badge>
2021-06-08 01:23:25 +05:30
</template>