feat: Adds the ability to delete the saved custom views (#3780)

* feat: Adds the ability to delete the saved custom views

* Removed unused tag

* Review fixes

* Review fixes

* Update DeleteCustomViews.vue
This commit is contained in:
Sivin Varghese 2022-01-19 09:40:32 +05:30 committed by GitHub
parent 4a68d13310
commit 185f916b2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 135 additions and 8 deletions

View file

@ -32,8 +32,20 @@
@click="resetAndFetchData" @click="resetAndFetchData"
/> />
</div> </div>
<div v-if="hasActiveCustomViews">
<woot-button
v-tooltip.top-end="$t('FILTER.CUSTOM_VIEWS.DELETE.DELETE_BUTTON')"
size="tiny"
variant="smooth"
color-scheme="alert"
icon="delete"
class="delete-custom-view__button"
@click="onClickOpenDeleteCustomViewsModal"
/>
</div>
<woot-button <woot-button
v-if="!hasActiveCustomViews" v-else
v-tooltip.top-end="$t('FILTER.TOOLTIP_LABEL')" v-tooltip.top-end="$t('FILTER.TOOLTIP_LABEL')"
variant="clear" variant="clear"
color-scheme="secondary" color-scheme="secondary"
@ -52,6 +64,14 @@
@close="onCloseAddCustomViewsModal" @close="onCloseAddCustomViewsModal"
/> />
<delete-custom-views
v-if="showDeleteCustomViewsModal"
:show-delete-popup.sync="showDeleteCustomViewsModal"
:active-custom-view="activeCustomView"
:custom-views-id="customViewsId"
@close="onCloseDeleteCustomViewsModal"
/>
<chat-type-tabs <chat-type-tabs
v-if="!hasAppliedFiltersOrActiveCustomViews" v-if="!hasAppliedFiltersOrActiveCustomViews"
:items="assigneeTabItems" :items="assigneeTabItems"
@ -129,6 +149,7 @@ import wootConstants from '../constants';
import advancedFilterTypes from './widgets/conversation/advancedFilterItems'; import advancedFilterTypes from './widgets/conversation/advancedFilterItems';
import filterQueryGenerator from '../helper/filterQueryGenerator.js'; import filterQueryGenerator from '../helper/filterQueryGenerator.js';
import AddCustomViews from 'dashboard/routes/dashboard/customviews/AddCustomViews'; import AddCustomViews from 'dashboard/routes/dashboard/customviews/AddCustomViews';
import DeleteCustomViews from 'dashboard/routes/dashboard/customviews/DeleteCustomViews.vue';
import { import {
hasPressedAltAndJKey, hasPressedAltAndJKey,
@ -142,6 +163,7 @@ export default {
ConversationCard, ConversationCard,
ChatFilter, ChatFilter,
ConversationAdvancedFilter, ConversationAdvancedFilter,
DeleteCustomViews,
}, },
mixins: [timeMixin, conversationMixin, eventListenerMixins], mixins: [timeMixin, conversationMixin, eventListenerMixins],
props: { props: {
@ -177,6 +199,7 @@ export default {
})), })),
customViewsQuery: {}, customViewsQuery: {},
showAddCustomViewsModal: false, showAddCustomViewsModal: false,
showDeleteCustomViewsModal: false,
}; };
}, },
computed: { computed: {
@ -197,14 +220,14 @@ export default {
return this.appliedFilters.length; return this.appliedFilters.length;
}, },
hasActiveCustomViews() { hasActiveCustomViews() {
return this.activeCustomView.length > 0 && this.customViewsId !== 0; return this.activeCustomView && this.customViewsId !== 0;
}, },
hasAppliedFiltersOrActiveCustomViews() { hasAppliedFiltersOrActiveCustomViews() {
return this.hasAppliedFilters || this.hasActiveCustomViews; return this.hasAppliedFilters || this.hasActiveCustomViews;
}, },
savedCustomViewsValue() { savedCustomViewsValue() {
if (this.hasActiveCustomViews) { if (this.hasActiveCustomViews) {
const payload = this.activeCustomView[0].query; const payload = this.activeCustomView.query;
this.fetchSavedFilteredConversations(payload); this.fetchSavedFilteredConversations(payload);
} }
return {}; return {};
@ -275,7 +298,7 @@ export default {
return this.$t('CHAT_LIST.MENTION_HEADING'); return this.$t('CHAT_LIST.MENTION_HEADING');
} }
if (this.hasActiveCustomViews) { if (this.hasActiveCustomViews) {
return this.activeCustomView[0].name; return this.activeCustomView.name;
} }
return this.$t('CHAT_LIST.TAB_HEADING'); return this.$t('CHAT_LIST.TAB_HEADING');
}, },
@ -298,11 +321,13 @@ export default {
}, },
activeCustomView() { activeCustomView() {
if (this.customViewsId) { if (this.customViewsId) {
return this.customViews.filter( const activeView = this.customViews.filter(
view => view.id === Number(this.customViewsId) view => view.id === Number(this.customViewsId)
); );
const [firstValue] = activeView;
return firstValue;
} }
return []; return undefined;
}, },
activeTeam() { activeTeam() {
if (this.teamId) { if (this.teamId) {
@ -352,6 +377,12 @@ export default {
onCloseAddCustomViewsModal() { onCloseAddCustomViewsModal() {
this.showAddCustomViewsModal = false; this.showAddCustomViewsModal = false;
}, },
onClickOpenDeleteCustomViewsModal() {
this.showDeleteCustomViewsModal = true;
},
onCloseDeleteCustomViewsModal() {
this.showDeleteCustomViewsModal = false;
},
onToggleAdvanceFiltersModal() { onToggleAdvanceFiltersModal() {
this.showAdvancedFilters = !this.showAdvancedFilters; this.showAdvancedFilters = !this.showAdvancedFilters;
}, },
@ -404,7 +435,7 @@ export default {
this.$store.dispatch('emptyAllConversations'); this.$store.dispatch('emptyAllConversations');
this.$store.dispatch('clearConversationFilters'); this.$store.dispatch('clearConversationFilters');
if (this.hasActiveCustomViews) { if (this.hasActiveCustomViews) {
const payload = this.activeCustomView[0].query; const payload = this.activeCustomView.query;
this.fetchSavedFilteredConversations(payload); this.fetchSavedFilteredConversations(payload);
} }
if (this.customViewsId) { if (this.customViewsId) {
@ -422,7 +453,7 @@ export default {
this.fetchConversations(); this.fetchConversations();
} }
if (this.hasActiveCustomViews) { if (this.hasActiveCustomViews) {
const payload = this.activeCustomView[0].query; const payload = this.activeCustomView.query;
this.fetchSavedFilteredConversations(payload); this.fetchSavedFilteredConversations(payload);
} else { } else {
this.fetchFilteredConversations(this.appliedFilters); this.fetchFilteredConversations(this.appliedFilters);
@ -504,4 +535,8 @@ export default {
padding: 0 0 var(--space-slab) 0 !important; padding: 0 0 var(--space-slab) 0 !important;
border-bottom: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border);
} }
.delete-custom-view__button {
margin-right: var(--space-normal);
}
</style> </style>

View file

@ -45,6 +45,21 @@
"SUCCESS_MESSAGE": "Custom view created successfully", "SUCCESS_MESSAGE": "Custom view created successfully",
"ERROR_MESSAGE": "Error while creating custom view" "ERROR_MESSAGE": "Error while creating custom view"
} }
},
"DELETE": {
"DELETE_BUTTON": "Delete filter",
"MODAL": {
"CONFIRM": {
"TITLE": "Confirm Deletion",
"MESSAGE": "Are you sure to delete the filter ",
"YES": "Yes, Delete ",
"NO": "No, Keep "
}
},
"API": {
"SUCCESS_MESSAGE": "Custom view deleted successfully",
"ERROR_MESSAGE": "Error while deleting custom view"
}
} }
} }
} }

View file

@ -0,0 +1,77 @@
<template>
<div>
<woot-delete-modal
v-if="showDeletePopup"
:show.sync="showDeletePopup"
:on-close="closeDeletePopup"
:on-confirm="deleteSavedCustomViews"
:title="$t('FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.TITLE')"
:message="deleteMessage"
:confirm-text="deleteConfirmText"
:reject-text="deleteRejectText"
/>
</div>
</template>
<script>
import alertMixin from 'shared/mixins/alertMixin';
export default {
mixins: [alertMixin],
props: {
showDeletePopup: {
type: Boolean,
default: false,
},
activeCustomView: {
type: Object,
default: () => {},
},
customViewsId: {
type: [String, Number],
default: 0,
},
},
computed: {
deleteMessage() {
return `${this.$t(
'FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.MESSAGE'
)} ${this.activeCustomView && this.activeCustomView.name} ?`;
},
deleteConfirmText() {
return `${this.$t('FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.YES')} ${this
.activeCustomView && this.activeCustomView.name}`;
},
deleteRejectText() {
return `${this.$t('FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.NO')} ${this
.activeCustomView && this.activeCustomView.name}`;
},
},
methods: {
async deleteSavedCustomViews() {
try {
await this.$store.dispatch(
'customViews/delete',
Number(this.customViewsId)
);
this.closeDeletePopup();
this.showAlert(
this.$t('FILTER.CUSTOM_VIEWS.DELETE.API.SUCCESS_MESSAGE')
);
} catch (error) {
const errorMessage =
error?.response?.message ||
this.$t('FILTER.CUSTOM_VIEWS.DELETE.API.ERROR_MESSAGE');
this.showAlert(errorMessage);
}
if (this.$route.name !== 'home') {
this.$router.push({ name: 'home' });
}
},
closeDeletePopup() {
this.$emit('close');
},
},
};
</script>