Skip to content
Snippets Groups Projects

Allow urlText to be saved on metric images

Merged Sean Arnold requested to merge 346171-frontend-for-metric-image-url-text into master
All threads resolved!
Files
4
<script>
<script>
import { GlButton, GlCard, GlIcon, GlLink, GlModal, GlSprintf } from '@gitlab/ui';
import {
 
GlButton,
 
GlFormGroup,
 
GlFormInput,
 
GlCard,
 
GlIcon,
 
GlLink,
 
GlModal,
 
GlSprintf,
 
GlTooltipDirective,
 
} from '@gitlab/ui';
import { mapActions } from 'vuex';
import { mapActions } from 'vuex';
import { __, s__ } from '~/locale';
import { __, s__ } from '~/locale';
@@ -9,15 +19,24 @@ export default {
@@ -9,15 +19,24 @@ export default {
modalDescription: s__('Incident|Are you sure you wish to delete this image?'),
modalDescription: s__('Incident|Are you sure you wish to delete this image?'),
modalCancel: __('Cancel'),
modalCancel: __('Cancel'),
modalTitle: s__('Incident|Deleting %{filename}'),
modalTitle: s__('Incident|Deleting %{filename}'),
 
editModalUpdate: __('Update'),
 
editModalTitle: s__('Incident|Editing %{filename}'),
 
editIconTitle: s__('Incident|Edit image text or link'),
 
deleteIconTitle: s__('Incident|Delete image'),
},
},
components: {
components: {
GlButton,
GlButton,
 
GlFormGroup,
 
GlFormInput,
GlCard,
GlCard,
GlIcon,
GlIcon,
GlLink,
GlLink,
GlModal,
GlModal,
GlSprintf,
GlSprintf,
},
},
 
directives: {
 
GlTooltip: GlTooltipDirective,
 
},
inject: ['canUpdate'],
inject: ['canUpdate'],
props: {
props: {
id: {
id: {
@@ -37,16 +56,25 @@ export default {
@@ -37,16 +56,25 @@ export default {
required: false,
required: false,
default: null,
default: null,
},
},
 
urlText: {
 
type: String,
 
required: false,
 
default: null,
 
},
},
},
data() {
data() {
return {
return {
isCollapsed: false,
isCollapsed: false,
isDeleting: false,
isDeleting: false,
 
isUpdating: false,
modalVisible: false,
modalVisible: false,
 
editModalVisible: false,
 
modalUrl: this.url,
 
modalUrlText: this.urlText,
};
};
},
},
computed: {
computed: {
actionPrimaryProps() {
deleteActionPrimaryProps() {
return {
return {
text: this.$options.i18n.modalDelete,
text: this.$options.i18n.modalDelete,
attributes: {
attributes: {
@@ -57,6 +85,17 @@ export default {
@@ -57,6 +85,17 @@ export default {
},
},
};
};
},
},
 
updateActionPrimaryProps() {
 
return {
 
text: this.$options.i18n.editModalUpdate,
 
attributes: {
 
loading: this.isUpdating,
 
disabled: this.isUpdating,
 
category: 'primary',
 
variant: 'confirm',
 
},
 
};
 
},
arrowIconName() {
arrowIconName() {
return this.isCollapsed ? 'chevron-right' : 'chevron-down';
return this.isCollapsed ? 'chevron-right' : 'chevron-down';
},
},
@@ -70,10 +109,16 @@ export default {
@@ -70,10 +109,16 @@ export default {
},
},
},
},
methods: {
methods: {
...mapActions(['deleteImage']),
...mapActions(['deleteImage', 'updateImage']),
toggleCollapsed() {
toggleCollapsed() {
this.isCollapsed = !this.isCollapsed;
this.isCollapsed = !this.isCollapsed;
},
},
 
resetEditFields() {
 
this.modalUrl = this.url;
 
this.modalUrlText = this.urlText;
 
this.editModalVisible = false;
 
this.modalVisible = false;
 
},
async onDelete() {
async onDelete() {
try {
try {
this.isDeleting = true;
this.isDeleting = true;
@@ -83,6 +128,21 @@ export default {
@@ -83,6 +128,21 @@ export default {
this.modalVisible = false;
this.modalVisible = false;
}
}
},
},
 
async onUpdate() {
 
try {
 
this.isUpdating = true;
 
await this.updateImage({
 
imageId: this.id,
 
url: this.modalUrl,
 
urlText: this.modalUrlText,
 
});
 
} finally {
 
this.isUpdating = false;
 
this.modalUrl = '';
 
this.modalUrlText = '';
 
this.editModalVisible = false;
 
}
 
},
},
},
};
};
</script>
</script>
@@ -98,10 +158,10 @@ export default {
@@ -98,10 +158,10 @@ export default {
modal-id="delete-metric-modal"
modal-id="delete-metric-modal"
size="sm"
size="sm"
:visible="modalVisible"
:visible="modalVisible"
:action-primary="actionPrimaryProps"
:action-primary="deleteActionPrimaryProps"
:action-cancel="{ text: $options.i18n.modalCancel }"
:action-cancel="{ text: $options.i18n.modalCancel }"
@primary.prevent="onDelete"
@primary.prevent="onDelete"
@hidden="modalVisible = false"
@hidden="resetEditFields"
>
>
<template #modal-title>
<template #modal-title>
<gl-sprintf :message="$options.i18n.modalTitle">
<gl-sprintf :message="$options.i18n.modalTitle">
@@ -112,6 +172,46 @@ export default {
@@ -112,6 +172,46 @@ export default {
</template>
</template>
<p>{{ $options.i18n.modalDescription }}</p>
<p>{{ $options.i18n.modalDescription }}</p>
</gl-modal>
</gl-modal>
 
 
<gl-modal
 
modal-id="edit-metric-modal"
 
size="sm"
 
:action-primary="updateActionPrimaryProps"
 
:action-cancel="{ text: $options.i18n.modalCancel }"
 
:visible="editModalVisible"
 
data-testid="metric-image-edit-modal"
 
@hidden="resetEditFields"
 
@primary.prevent="onUpdate"
 
>
 
<template #modal-title>
 
<gl-sprintf :message="$options.i18n.editModalTitle">
 
<template #filename>
 
{{ filename }}
 
</template>
 
</gl-sprintf>
 
</template>
 
 
<gl-form-group :label="__('Text (optional)')" label-for="upload-text-input">
 
<gl-form-input
 
id="upload-text-input"
 
v-model="modalUrlText"
 
data-testid="metric-image-text-field"
 
/>
 
</gl-form-group>
 
 
<gl-form-group
 
:label="__('Link (optional)')"
 
label-for="upload-url-input"
 
:description="s__('Incidents|Must start with http or https')"
 
>
 
<gl-form-input
 
id="upload-url-input"
 
v-model="modalUrl"
 
data-testid="metric-image-url-field"
 
/>
 
</gl-form-group>
 
</gl-modal>
 
<template #header>
<template #header>
<div class="gl-w-full gl-display-flex gl-flex-direction-row gl-justify-content-space-between">
<div class="gl-w-full gl-display-flex gl-flex-direction-row gl-justify-content-space-between">
<div class="gl-display-flex gl-flex-direction-row gl-align-items-center gl-w-full">
<div class="gl-display-flex gl-flex-direction-row gl-align-items-center gl-w-full">
@@ -125,18 +225,33 @@ export default {
@@ -125,18 +225,33 @@ export default {
>
>
<gl-icon class="gl-mr-2" :name="arrowIconName" />
<gl-icon class="gl-mr-2" :name="arrowIconName" />
</gl-button>
</gl-button>
<gl-link v-if="url" :href="url">
<gl-link v-if="url" :href="url" target="_blank" data-testid="metric-image-label-span">
{{ filename }}
{{ urlText == null || urlText == '' ? filename : urlText }}
 
<gl-icon name="external-link" class="gl-vertical-align-middle" />
</gl-link>
</gl-link>
<span v-else>{{ filename }}</span>
<span v-else data-testid="metric-image-label-span">{{
<gl-button
urlText == null || urlText == '' ? filename : urlText
v-if="canUpdate"
}}</span>
class="gl-ml-auto"
<div class="gl-ml-auto btn-group">
icon="remove"
<gl-button
:aria-label="__('Delete')"
v-if="canUpdate"
data-testid="delete-button"
v-gl-tooltip.bottom
@click="modalVisible = true"
icon="pencil"
/>
:aria-label="__('Edit')"
 
:title="$options.i18n.editIconTitle"
 
data-testid="edit-button"
 
@click="editModalVisible = true"
 
/>
 
<gl-button
 
v-if="canUpdate"
 
v-gl-tooltip.bottom
 
icon="remove"
 
:aria-label="__('Delete')"
 
:title="$options.i18n.deleteIconTitle"
 
data-testid="delete-button"
 
@click="modalVisible = true"
 
/>
 
</div>
</div>
</div>
</div>
</div>
</template>
</template>
Loading