Compare commits

...
Author SHA1 Message Date
Sivin VargheseandGitHub b4ede973e9 Merge branch 'develop' into feat/PR-1352 2024-09-25 09:33:01 +05:30
Muhsin KelothandGitHub 2ae545b394 Merge branch 'develop' into feat/PR-1352 2024-09-18 00:50:35 +05:30
iamsivin 42586e6b1e chore: Minor fixes 2024-09-17 17:03:13 +05:30
iamsivin 7baa7d8c62 chore: Clean up 2024-09-17 16:58:42 +05:30
iamsivin 82dec3cee9 feat: Save contact sort config 2024-09-17 16:04:42 +05:30
2 changed files with 37 additions and 44 deletions
@@ -32,18 +32,13 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
sortParam: { activeSortConfig: {
type: String, type: Object,
default: 'last_activity_at', default: () => ({ last_activity_at: 'desc' }),
},
sortOrder: {
type: String,
default: 'desc',
}, },
}, },
data() { data() {
return { return {
sortConfig: {},
sortOption: { sortOption: {
sortAlways: true, sortAlways: true,
sortChange: params => this.$emit('onSortChange', params), sortChange: params => this.$emit('onSortChange', params),
@@ -88,7 +83,7 @@ export default {
title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.NAME'), title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.NAME'),
fixed: 'left', fixed: 'left',
align: this.isRTL ? 'right' : 'left', align: this.isRTL ? 'right' : 'left',
sortBy: this.sortConfig.name || '', sortBy: this.activeSortConfig.name || '',
width: 300, width: 300,
renderBodyCell: ({ row }) => ( renderBodyCell: ({ row }) => (
<woot-button <woot-button
@@ -124,7 +119,7 @@ export default {
key: 'email', key: 'email',
title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.EMAIL_ADDRESS'), title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.EMAIL_ADDRESS'),
align: this.isRTL ? 'right' : 'left', align: this.isRTL ? 'right' : 'left',
sortBy: this.sortConfig.email || '', sortBy: this.activeSortConfig.email || '',
width: 240, width: 240,
renderBodyCell: ({ row }) => { renderBodyCell: ({ row }) => {
if (row.email) if (row.email)
@@ -145,21 +140,21 @@ export default {
{ {
field: 'phone_number', field: 'phone_number',
key: 'phone_number', key: 'phone_number',
sortBy: this.sortConfig.phone_number || '', sortBy: this.activeSortConfig.phone_number || '',
title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.PHONE_NUMBER'), title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.PHONE_NUMBER'),
align: this.isRTL ? 'right' : 'left', align: this.isRTL ? 'right' : 'left',
}, },
{ {
field: 'company', field: 'company',
key: 'company', key: 'company',
sortBy: this.sortConfig.company_name || '', sortBy: this.activeSortConfig.company || '',
title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.COMPANY'), title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.COMPANY'),
align: this.isRTL ? 'right' : 'left', align: this.isRTL ? 'right' : 'left',
}, },
{ {
field: 'city', field: 'city',
key: 'city', key: 'city',
sortBy: this.sortConfig.city || '', sortBy: this.activeSortConfig.city || '',
title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.CITY'), title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.CITY'),
align: this.isRTL ? 'right' : 'left', align: this.isRTL ? 'right' : 'left',
}, },
@@ -168,7 +163,7 @@ export default {
key: 'country', key: 'country',
title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.COUNTRY'), title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.COUNTRY'),
align: this.isRTL ? 'right' : 'left', align: this.isRTL ? 'right' : 'left',
sortBy: this.sortConfig.country || '', sortBy: this.activeSortConfig.country || '',
renderBodyCell: ({ row }) => { renderBodyCell: ({ row }) => {
if (row.country) { if (row.country) {
return ( return (
@@ -213,36 +208,20 @@ export default {
{ {
field: 'last_activity_at', field: 'last_activity_at',
key: 'last_activity_at', key: 'last_activity_at',
sortBy: this.sortConfig.last_activity_at || '', sortBy: this.activeSortConfig.last_activity_at || '',
title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.LAST_ACTIVITY'), title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.LAST_ACTIVITY'),
align: this.isRTL ? 'right' : 'left', align: this.isRTL ? 'right' : 'left',
}, },
{ {
field: 'created_at', field: 'created_at',
key: 'created_at', key: 'created_at',
sortBy: this.sortConfig.created_at || '', sortBy: this.activeSortConfig.created_at || '',
title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.CREATED_AT'), title: this.$t('CONTACTS_PAGE.LIST.TABLE_HEADER.CREATED_AT'),
align: this.isRTL ? 'right' : 'left', align: this.isRTL ? 'right' : 'left',
}, },
]; ];
}, },
}, },
watch: {
sortOrder() {
this.setSortConfig();
},
sortParam() {
this.setSortConfig();
},
},
mounted() {
this.setSortConfig();
},
methods: {
setSortConfig() {
this.sortConfig = { [this.sortParam]: this.sortOrder };
},
},
}; };
</script> </script>
@@ -1,6 +1,7 @@
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { useAlert } from 'dashboard/composables'; import { useAlert } from 'dashboard/composables';
import { useUISettings } from 'dashboard/composables/useUISettings';
import ContactsHeader from './Header.vue'; import ContactsHeader from './Header.vue';
import ContactsTable from './ContactsTable.vue'; import ContactsTable from './ContactsTable.vue';
@@ -39,6 +40,10 @@ export default {
default: 0, default: 0,
}, },
}, },
setup() {
const { uiSettings, updateUISettings } = useUISettings();
return { uiSettings, updateUISettings };
},
data() { data() {
return { return {
searchQuery: '', searchQuery: '',
@@ -148,6 +153,9 @@ export default {
}, },
}, },
mounted() { mounted() {
if (this.uiSettings?.contacts_sort_config) {
this.sortConfig = this.uiSettings.contacts_sort_config;
}
this.fetchContacts(this.pageParameter); this.fetchContacts(this.pageParameter);
}, },
methods: { methods: {
@@ -155,19 +163,21 @@ export default {
window.history.pushState({}, null, `${this.$route.path}?page=${page}`); window.history.pushState({}, null, `${this.$route.path}?page=${page}`);
}, },
getSortAttribute() { getSortAttribute() {
let sortAttr = Object.keys(this.sortConfig).reduce((acc, sortKey) => { // Use UI settings if available, otherwise use the current sortConfig
const sortOrder = this.sortConfig[sortKey]; const sortConfig =
if (sortOrder) { this.uiSettings.contacts_sort_config || this.sortConfig;
const sortOrderSign = sortOrder === 'asc' ? '' : '-';
return `${sortOrderSign}${sortKey}`; const [sortKey, sortOrder] =
} Object.entries(sortConfig).find(([, order]) => order) || [];
return acc;
}, ''); if (sortKey && sortOrder) {
if (!sortAttr) { const sortOrderSign = sortOrder === 'asc' ? '' : '-';
this.sortConfig = { last_activity_at: 'desc' }; return `${sortOrderSign}${sortKey}`;
sortAttr = '-last_activity_at';
} }
return sortAttr;
// If no sort attribute is found, use the default
this.sortConfig = { last_activity_at: 'desc' };
return '-last_activity_at';
}, },
fetchContacts(page) { fetchContacts(page) {
if (this.isContactAndLabelDashboard) { if (this.isContactAndLabelDashboard) {
@@ -267,6 +277,9 @@ export default {
}, },
onSortChange(params) { onSortChange(params) {
this.sortConfig = params; this.sortConfig = params;
this.updateUISettings({
contacts_sort_config: params,
});
this.fetchContacts(this.meta.currentPage); this.fetchContacts(this.meta.currentPage);
const sortBy = const sortBy =
@@ -412,6 +425,7 @@ export default {
:is-loading="uiFlags.isFetching" :is-loading="uiFlags.isFetching"
:on-click-contact="openContactInfoPanel" :on-click-contact="openContactInfoPanel"
:active-contact-id="selectedContactId" :active-contact-id="selectedContactId"
:active-sort-config="sortConfig"
@onSortChange="onSortChange" @onSortChange="onSortChange"
/> />
<TableFooter <TableFooter