2021-03-11 19:13:27 +05:30
|
|
|
<script>
|
|
|
|
import { GlButton, GlLoadingIcon } from '@gitlab/ui';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { __ } from '~/locale';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
export default {
|
2021-06-08 01:23:25 +05:30
|
|
|
i18n: {
|
|
|
|
unassigned: __('Unassigned'),
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
components: { GlButton, GlLoadingIcon },
|
2021-04-17 20:07:23 +05:30
|
|
|
inject: {
|
|
|
|
canUpdate: {},
|
|
|
|
isClassicSidebar: {
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
props: {
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
initialLoading: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
isDirty: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-04-17 20:07:23 +05:30
|
|
|
tracking: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: () => ({
|
|
|
|
event: null,
|
|
|
|
label: null,
|
|
|
|
property: null,
|
|
|
|
}),
|
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
canEdit: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
edit: false,
|
|
|
|
};
|
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
computed: {
|
|
|
|
editButtonText() {
|
|
|
|
return this.isDirty ? __('Apply') : __('Edit');
|
|
|
|
},
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
destroyed() {
|
|
|
|
window.removeEventListener('click', this.collapseWhenOffClick);
|
|
|
|
window.removeEventListener('keyup', this.collapseOnEscape);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
collapseWhenOffClick({ target }) {
|
|
|
|
if (!this.$el.contains(target)) {
|
|
|
|
this.collapse();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
collapseOnEscape({ key }) {
|
|
|
|
if (key === 'Escape') {
|
|
|
|
this.collapse();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
expand() {
|
|
|
|
if (this.edit) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.edit = true;
|
|
|
|
this.$emit('open');
|
|
|
|
window.addEventListener('click', this.collapseWhenOffClick);
|
|
|
|
window.addEventListener('keyup', this.collapseOnEscape);
|
|
|
|
},
|
|
|
|
collapse({ emitEvent = true } = {}) {
|
|
|
|
if (!this.edit) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.edit = false;
|
|
|
|
if (emitEvent) {
|
|
|
|
this.$emit('close');
|
|
|
|
}
|
|
|
|
window.removeEventListener('click', this.collapseWhenOffClick);
|
|
|
|
window.removeEventListener('keyup', this.collapseOnEscape);
|
|
|
|
},
|
|
|
|
toggle({ emitEvent = true } = {}) {
|
|
|
|
if (this.edit) {
|
|
|
|
this.collapse({ emitEvent });
|
|
|
|
} else {
|
|
|
|
this.expand();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2021-09-04 01:27:46 +05:30
|
|
|
<div
|
|
|
|
class="gl-display-flex gl-align-items-center gl-line-height-20 gl-mb-2 gl-text-gray-900"
|
|
|
|
@click.self="collapse"
|
|
|
|
>
|
|
|
|
<span class="hide-collapsed" data-testid="title" @click="collapse">
|
|
|
|
{{ title }}
|
|
|
|
</span>
|
2021-06-08 01:23:25 +05:30
|
|
|
<slot name="title-extra"></slot>
|
2021-09-30 23:02:18 +05:30
|
|
|
<gl-loading-icon
|
|
|
|
v-if="loading || initialLoading"
|
|
|
|
size="sm"
|
|
|
|
inline
|
|
|
|
class="gl-ml-2 hide-collapsed"
|
|
|
|
/>
|
2021-04-17 20:07:23 +05:30
|
|
|
<gl-loading-icon
|
|
|
|
v-if="loading && isClassicSidebar"
|
2021-09-30 23:02:18 +05:30
|
|
|
size="sm"
|
2021-04-17 20:07:23 +05:30
|
|
|
inline
|
|
|
|
class="gl-mx-auto gl-my-0 hide-expanded"
|
|
|
|
/>
|
2021-06-08 01:23:25 +05:30
|
|
|
<slot name="collapsed-right"></slot>
|
2021-03-11 19:13:27 +05:30
|
|
|
<gl-button
|
2021-06-08 01:23:25 +05:30
|
|
|
v-if="canUpdate && !initialLoading && canEdit"
|
2021-10-27 15:23:28 +05:30
|
|
|
category="tertiary"
|
|
|
|
size="small"
|
|
|
|
class="gl-text-gray-900! gl-ml-auto hide-collapsed gl-mr-n2"
|
2021-03-11 19:13:27 +05:30
|
|
|
data-testid="edit-button"
|
2021-04-17 20:07:23 +05:30
|
|
|
:data-track-event="tracking.event"
|
|
|
|
:data-track-label="tracking.label"
|
|
|
|
:data-track-property="tracking.property"
|
|
|
|
data-qa-selector="edit_link"
|
2021-03-11 19:13:27 +05:30
|
|
|
@keyup.esc="toggle"
|
|
|
|
@click="toggle"
|
|
|
|
>
|
2021-04-29 21:17:54 +05:30
|
|
|
{{ editButtonText }}
|
2021-03-11 19:13:27 +05:30
|
|
|
</gl-button>
|
|
|
|
</div>
|
2021-04-29 21:17:54 +05:30
|
|
|
<template v-if="!initialLoading">
|
2021-09-04 01:27:46 +05:30
|
|
|
<div v-show="!edit" data-testid="collapsed-content" class="gl-line-height-14">
|
2021-04-29 21:17:54 +05:30
|
|
|
<slot name="collapsed">{{ __('None') }}</slot>
|
|
|
|
</div>
|
|
|
|
<div v-show="edit" data-testid="expanded-content" :class="{ 'gl-mt-3': !isClassicSidebar }">
|
|
|
|
<slot :edit="edit"></slot>
|
|
|
|
</div>
|
|
|
|
</template>
|
2021-03-11 19:13:27 +05:30
|
|
|
</div>
|
|
|
|
</template>
|