feat: Adds the ability to delete a segment (#3836)

* feat: Adds the ability to delete a segment

* Minor fixes

* Small changes
This commit is contained in:
Sivin Varghese 2022-01-24 17:37:43 +05:30 committed by GitHub
parent e90d064648
commit b304f5a826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 18 deletions

View file

@ -9,6 +9,10 @@ class CustomViewsAPI extends ApiClient {
getCustomViewsByFilterType(type) { getCustomViewsByFilterType(type) {
return axios.get(`${this.url}?filter_type=${type}`); return axios.get(`${this.url}?filter_type=${type}`);
} }
deleteCustomViews(id, type) {
return axios.delete(`${this.url}/${id}?filter_type=${type}`);
}
} }
export default new CustomViewsAPI(); export default new CustomViewsAPI();

View file

@ -52,8 +52,8 @@
"CONFIRM": { "CONFIRM": {
"TITLE": "Confirm Deletion", "TITLE": "Confirm Deletion",
"MESSAGE": "Are you sure to delete the filter ", "MESSAGE": "Are you sure to delete the filter ",
"YES": "Yes, Delete ", "YES": "Yes, Delete",
"NO": "No, Keep " "NO": "No, Keep it"
} }
}, },
"API": { "API": {

View file

@ -180,6 +180,7 @@
"SEARCH_INPUT_PLACEHOLDER": "Search for contacts", "SEARCH_INPUT_PLACEHOLDER": "Search for contacts",
"FILTER_CONTACTS": "Filter", "FILTER_CONTACTS": "Filter",
"FILTER_CONTACTS_SAVE": "Save filter", "FILTER_CONTACTS_SAVE": "Save filter",
"FILTER_CONTACTS_DELETE": "Delete filter",
"LIST": { "LIST": {
"LOADING_MESSAGE": "Loading contacts...", "LOADING_MESSAGE": "Loading contacts...",
"404": "No contacts matches your search 🔍", "404": "No contacts matches your search 🔍",

View file

@ -12,6 +12,7 @@
:on-toggle-filter="onToggleFilters" :on-toggle-filter="onToggleFilters"
:header-title="pageTitle" :header-title="pageTitle"
@on-toggle-save-filter="onToggleSaveFilters" @on-toggle-save-filter="onToggleSaveFilters"
@on-toggle-delete-filter="onToggleDeleteFilters"
/> />
<contacts-table <contacts-table
:contacts="records" :contacts="records"
@ -28,12 +29,22 @@
:total-count="meta.count" :total-count="meta.count"
/> />
</div> </div>
<add-custom-views <add-custom-views
v-if="showAddCustomViewsModal" v-if="showAddCustomViewsModal"
:custom-views-query="customViewsQuery" :custom-views-query="customViewsQuery"
:filter-type="filterType" :filter-type="filterType"
@close="onCloseAddCustomViewsModal" @close="onCloseAddCustomViewsModal"
/> />
<delete-custom-views
v-if="showDeleteCustomViewsModal"
:show-delete-popup.sync="showDeleteCustomViewsModal"
:active-custom-view="activeCustomView"
:custom-views-id="customViewsId"
:active-filter-type="filterType"
@close="onCloseDeleteCustomViewsModal"
/>
<contact-info-panel <contact-info-panel
v-if="showContactViewPane" v-if="showContactViewPane"
:contact="selectedContact" :contact="selectedContact"
@ -72,6 +83,7 @@ import ContactsAdvancedFilters from './ContactsAdvancedFilters.vue';
import contactFilterItems from '../contactFilterItems'; import contactFilterItems from '../contactFilterItems';
import filterQueryGenerator from '../../../../helper/filterQueryGenerator'; import filterQueryGenerator from '../../../../helper/filterQueryGenerator';
import AddCustomViews from 'dashboard/routes/dashboard/customviews/AddCustomViews'; import AddCustomViews from 'dashboard/routes/dashboard/customviews/AddCustomViews';
import DeleteCustomViews from 'dashboard/routes/dashboard/customviews/DeleteCustomViews';
const DEFAULT_PAGE = 1; const DEFAULT_PAGE = 1;
const FILTER_TYPE_CONTACT = 1; const FILTER_TYPE_CONTACT = 1;
@ -86,6 +98,7 @@ export default {
ImportContacts, ImportContacts,
ContactsAdvancedFilters, ContactsAdvancedFilters,
AddCustomViews, AddCustomViews,
DeleteCustomViews,
}, },
props: { props: {
label: { type: String, default: '' }, label: { type: String, default: '' },
@ -111,6 +124,7 @@ export default {
customViewsQuery: {}, customViewsQuery: {},
filterType: FILTER_TYPE_CONTACT, filterType: FILTER_TYPE_CONTACT,
showAddCustomViewsModal: false, showAddCustomViewsModal: false,
showDeleteCustomViewsModal: false,
}; };
}, },
computed: { computed: {
@ -272,6 +286,12 @@ export default {
onCloseAddCustomViewsModal() { onCloseAddCustomViewsModal() {
this.showAddCustomViewsModal = false; this.showAddCustomViewsModal = false;
}, },
onToggleDeleteFilters() {
this.showDeleteCustomViewsModal = true;
},
onCloseDeleteCustomViewsModal() {
this.showDeleteCustomViewsModal = false;
},
onToggleImport() { onToggleImport() {
this.showImportModal = !this.showImportModal; this.showImportModal = !this.showImportModal;
}, },

View file

@ -26,6 +26,17 @@
{{ $t('CONTACTS_PAGE.SEARCH_BUTTON') }} {{ $t('CONTACTS_PAGE.SEARCH_BUTTON') }}
</woot-button> </woot-button>
</div> </div>
<woot-button
v-if="hasActiveCustomViews && !hasAppliedFilters"
class="margin-right-small clear"
color-scheme="alert"
icon="delete"
@click="onToggleDeleteCustomViewsModal"
>
{{ $t('CONTACTS_PAGE.FILTER_CONTACTS_DELETE') }}
</woot-button>
<div v-if="!hasActiveCustomViews" class="filters__button-wrap"> <div v-if="!hasActiveCustomViews" class="filters__button-wrap">
<div v-if="hasAppliedFilters" class="filters__applied-indicator" /> <div v-if="hasAppliedFilters" class="filters__applied-indicator" />
<woot-button <woot-button
@ -38,6 +49,7 @@
{{ $t('CONTACTS_PAGE.FILTER_CONTACTS') }} {{ $t('CONTACTS_PAGE.FILTER_CONTACTS') }}
</woot-button> </woot-button>
</div> </div>
<woot-button <woot-button
v-if="hasAppliedFilters && !hasActiveCustomViews" v-if="hasAppliedFilters && !hasActiveCustomViews"
class="margin-right-small clear" class="margin-right-small clear"
@ -133,6 +145,9 @@ export default {
onToggleCustomViewsModal() { onToggleCustomViewsModal() {
this.$emit('on-toggle-save-filter'); this.$emit('on-toggle-save-filter');
}, },
onToggleDeleteCustomViewsModal() {
this.$emit('on-toggle-delete-filter');
},
}, },
}; };
</script> </script>

View file

@ -30,31 +30,49 @@ export default {
type: [String, Number], type: [String, Number],
default: 0, default: 0,
}, },
activeFilterType: {
type: Number,
default: 0,
},
}, },
computed: { computed: {
activeCustomViews() {
if (this.activeFilterType === 0) {
return 'conversation';
}
if (this.activeFilterType === 1) {
return 'contact';
}
return '';
},
deleteMessage() { deleteMessage() {
return `${this.$t( return `${this.$t(
'FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.MESSAGE' 'FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.MESSAGE'
)} ${this.activeCustomView && this.activeCustomView.name} ?`; )} ${this.activeCustomView && this.activeCustomView.name} ?`;
}, },
deleteConfirmText() { deleteConfirmText() {
return `${this.$t('FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.YES')} ${this return `${this.$t('FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.YES')}`;
.activeCustomView && this.activeCustomView.name}`;
}, },
deleteRejectText() { deleteRejectText() {
return `${this.$t('FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.NO')} ${this return `${this.$t('FILTER.CUSTOM_VIEWS.DELETE.MODAL.CONFIRM.NO')}`;
.activeCustomView && this.activeCustomView.name}`; },
isFolderSection() {
return this.activeFilterType === 0 && this.$route.name !== 'home';
},
isSegmentSection() {
return (
this.activeFilterType === 1 && this.$route.name !== 'contacts_dashboard'
);
}, },
}, },
methods: { methods: {
async deleteSavedCustomViews() { async deleteSavedCustomViews() {
try { try {
await this.$store.dispatch( const id = Number(this.customViewsId);
'customViews/delete', const filterType = this.activeCustomViews;
Number(this.customViewsId) await this.$store.dispatch('customViews/delete', { id, filterType });
);
this.closeDeletePopup(); this.closeDeletePopup();
this.showAlert( this.showAlert(
this.$t('FILTER.CUSTOM_VIEWS.DELETE.API.SUCCESS_MESSAGE') this.$t('FILTER.CUSTOM_VIEWS.DELETE.API.SUCCESS_MESSAGE')
@ -65,9 +83,12 @@ export default {
this.$t('FILTER.CUSTOM_VIEWS.DELETE.API.ERROR_MESSAGE'); this.$t('FILTER.CUSTOM_VIEWS.DELETE.API.ERROR_MESSAGE');
this.showAlert(errorMessage); this.showAlert(errorMessage);
} }
if (this.$route.name !== 'home') { if (this.isFolderSection) {
this.$router.push({ name: 'home' }); this.$router.push({ name: 'home' });
} }
if (this.isSegmentSection) {
this.$router.push({ name: 'contacts_dashboard' });
}
}, },
closeDeletePopup() { closeDeletePopup() {
this.$emit('close'); this.$emit('close');

View file

@ -49,10 +49,10 @@ export const actions = {
commit(types.SET_CUSTOM_VIEW_UI_FLAG, { isCreating: false }); commit(types.SET_CUSTOM_VIEW_UI_FLAG, { isCreating: false });
} }
}, },
delete: async ({ commit }, id) => { delete: async ({ commit }, { id, filterType }) => {
commit(types.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true }); commit(types.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true });
try { try {
await CustomViewsAPI.delete(id); await CustomViewsAPI.deleteCustomViews(id, filterType);
commit(types.DELETE_CUSTOM_VIEW, id); commit(types.DELETE_CUSTOM_VIEW, id);
} catch (error) { } catch (error) {
throw new Error(error); throw new Error(error);

View file

@ -51,18 +51,16 @@ describe('#actions', () => {
describe('#delete', () => { describe('#delete', () => {
it('sends correct actions if API is success', async () => { it('sends correct actions if API is success', async () => {
axios.delete.mockResolvedValue({ data: customViewList[0] }); axios.delete.mockResolvedValue({ data: customViewList[0] });
await actions.delete({ commit }, customViewList[0].id); await actions.delete({ commit }, { id: 1, filterType: 'contact' });
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
[types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true }], [types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true }],
[types.default.DELETE_CUSTOM_VIEW, customViewList[0].id], [types.default.DELETE_CUSTOM_VIEW, 1],
[types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: false }], [types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: false }],
]); ]);
}); });
it('sends correct actions if API is error', async () => { it('sends correct actions if API is error', async () => {
axios.delete.mockRejectedValue({ message: 'Incorrect header' }); axios.delete.mockRejectedValue({ message: 'Incorrect header' });
await expect( await expect(actions.delete({ commit }, 1)).rejects.toThrow(Error);
actions.delete({ commit }, customViewList[0].id)
).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
[types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true }], [types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true }],
[types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: false }], [types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: false }],