diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-04 15:10:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-04 15:10:04 +0300 |
commit | 998adcc422d4161515bf2960ef4dce71258f69a3 (patch) | |
tree | 34ffbf53b8587d3367457d4175fc8dfd71477dca /app/assets/javascripts/issuable | |
parent | e2c471038ab2b4f09487c1feb74520f74f834986 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/issuable')
-rw-r--r-- | app/assets/javascripts/issuable/components/status_box.vue | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/app/assets/javascripts/issuable/components/status_box.vue b/app/assets/javascripts/issuable/components/status_box.vue new file mode 100644 index 00000000000..cb768f2bc5b --- /dev/null +++ b/app/assets/javascripts/issuable/components/status_box.vue @@ -0,0 +1,103 @@ +<script> +import { GlIcon } from '@gitlab/ui'; +import Vue from 'vue'; +import { fetchPolicies } from '~/lib/graphql'; +import { __ } from '~/locale'; + +export const statusBoxState = Vue.observable({ + state: '', + updateStatus: null, +}); + +const CLASSES = { + opened: 'status-box-open', + locked: 'status-box-open', + closed: 'status-box-mr-closed', + merged: 'status-box-mr-merged', +}; + +const STATUS = { + opened: [__('Open'), 'issue-open-m'], + locked: [__('Open'), 'issue-open-m'], + closed: [__('Closed'), 'issue-close'], + merged: [__('Merged'), 'git-merge'], +}; + +export default { + components: { + GlIcon, + }, + 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() { + if (this.initialState) { + statusBoxState.state = this.initialState; + } + + return statusBoxState; + }, + computed: { + statusBoxClass() { + return CLASSES[`${this.issuableType}_${this.state}`] || CLASSES[this.state]; + }, + statusHumanName() { + return (STATUS[`${this.issuableType}_${this.state}`] || STATUS[this.state])[0]; + }, + statusIconName() { + return (STATUS[`${this.issuableType}_${this.state}`] || STATUS[this.state])[1]; + }, + }, + created() { + if (!statusBoxState.updateStatus) { + statusBoxState.updateStatus = this.fetchState; + } + }, + beforeDestroy() { + if (statusBoxState.updateStatus && this.query) { + statusBoxState.updateStatus = null; + } + }, + methods: { + async fetchState() { + const { data } = await this.$apollo.query({ + query: this.query, + variables: { + projectPath: this.projectPath, + iid: this.iid, + }, + fetchPolicy: fetchPolicies.NO_CACHE, + }); + + statusBoxState.state = data?.workspace?.issuable?.state; + }, + }, +}; +</script> + +<template> + <div :class="statusBoxClass" class="issuable-status-box status-box"> + <gl-icon + :name="statusIconName" + class="gl-display-block gl-sm-display-none!" + data-testid="status-icon" + /> + <span class="gl-display-none gl-sm-display-block"> + {{ statusHumanName }} + </span> + </div> +</template> |