Commit 479c6eb8 authored by lauraMon's avatar lauraMon

Updates component with mutation

parent 1ae4a35a
...@@ -4,19 +4,22 @@ import { ...@@ -4,19 +4,22 @@ import {
GlAlert, GlAlert,
GlIcon, GlIcon,
GlLoadingIcon, GlLoadingIcon,
GlNewDropdown, GlDropdown,
GlNewDropdownItem, GlDropdownItem,
GlSprintf, GlSprintf,
GlTabs, GlTabs,
GlTab, GlTab,
GlButton, GlButton,
} from '@gitlab/ui'; } from '@gitlab/ui';
import createFlash from '~/flash';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import query from '../graphql/queries/details.query.graphql'; import query from '../graphql/queries/details.query.graphql';
import { fetchPolicies } from '~/lib/graphql'; import { fetchPolicies } from '~/lib/graphql';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { ALERTS_SEVERITY_LABELS } from '../constants'; import { ALERTS_SEVERITY_LABELS } from '../constants';
import updateAlertStatus from '../graphql/mutations/update_alert_status.graphql'
export default { export default {
statuses: { statuses: {
...@@ -38,9 +41,9 @@ export default { ...@@ -38,9 +41,9 @@ export default {
GlAlert, GlAlert,
GlIcon, GlIcon,
GlLoadingIcon, GlLoadingIcon,
GlNewDropdown,
GlNewDropdownItem,
GlSprintf, GlSprintf,
GlDropdown,
GlDropdownItem,
GlTab, GlTab,
GlTabs, GlTabs,
GlButton, GlButton,
...@@ -97,9 +100,28 @@ export default { ...@@ -97,9 +100,28 @@ export default {
}, },
}, },
methods: { methods: {
capitalizeFirstCharacter,
dismissError() { dismissError() {
this.isErrorDismissed = true; this.isErrorDismissed = true;
}, },
updateAlertStatus(status) {
this.$apollo
.mutate({
mutation: updateAlertStatus,
variables: {
iid: this.alertId,
status: status.toUpperCase(),
projectPath: this.projectPath,
},
})
.catch(() => {
createFlash(
s__(
'AlertManagement|There was an error while updating the status of the alert. Please try again.',
),
);
});
},
}, },
}; };
</script> </script>
...@@ -148,15 +170,24 @@ export default { ...@@ -148,15 +170,24 @@ export default {
class="gl-display-flex gl-justify-content-space-between gl-align-items-center" class="gl-display-flex gl-justify-content-space-between gl-align-items-center"
> >
<h2 data-testid="title">{{ alert.title }}</h2> <h2 data-testid="title">{{ alert.title }}</h2>
<gl-new-dropdown right> <gl-dropdown :text="capitalizeFirstCharacter(alert.status.toLowerCase())" class="mt-2 mb-n2" right>
<gl-new-dropdown-item <gl-dropdown-item
v-for="(label, field) in $options.statuses" v-for="(label, field) in $options.statuses"
:key="field" :key="field"
data-testid="statusDropdownItem" data-testid="statusDropdownItem"
class="gl-vertical-align-middle" class="gl-vertical-align-middle"
>{{ label }} @click="updateAlertStatus(label)"
</gl-new-dropdown-item> >
</gl-new-dropdown> <span class="d-flex">
<gl-icon
class="flex-shrink-0 append-right-4"
:class="{ invisible: label.toUpperCase() !== alert.status }"
name="mobile-issue-close"
/>
{{ label }}
</span>
</gl-dropdown-item>
</gl-dropdown>
</div> </div>
<gl-tabs v-if="alert" data-testid="alertDetailsTabs"> <gl-tabs v-if="alert" data-testid="alertDetailsTabs">
<gl-tab data-testid="overviewTab" :title="$options.i18n.overviewTitle"> <gl-tab data-testid="overviewTab" :title="$options.i18n.overviewTitle">
......
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
import AlertDetails from './components/alert_details.vue'; import AlertDetails from './components/alert_details.vue';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -10,7 +11,20 @@ export default selector => { ...@@ -10,7 +11,20 @@ export default selector => {
const { alertId, projectPath, newIssuePath } = domEl.dataset; const { alertId, projectPath, newIssuePath } = domEl.dataset;
const apolloProvider = new VueApollo({ const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(), defaultClient: createDefaultClient(
{},
{
cacheConfig: {
dataIdFromObject: object => {
// eslint-disable-next-line no-underscore-dangle
if (object.__typename === 'AlertManagementAlert') {
return object.iid;
}
return defaultDataIdFromObject(object);
},
},
},
),
}); });
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment