Skip to content

Commit

Permalink
refactor: rm .reverse() from chat messages-related client api's [WTEL…
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Nov 18, 2024
1 parent 651a148 commit a0c150c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webitel/ui-sdk",
"version": "24.10.81",
"version": "24.10.82",
"private": false,
"scripts": {
"dev": "vite",
Expand Down
4 changes: 2 additions & 2 deletions src/api/clients/сontacts/contactChatMessagesHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const getChat = async ({ contactId, chatId }) => {
const response = await contactChatService.getContactChatHistory(contactId, chatId);
const { messages, peers } = applyTransform(response.data, [snakeToCamel()]);
return {
items: applyTransform({ messages, peers }, [mergeChatMessagesData]).reverse(),
items: applyTransform({ messages, peers }, [mergeChatMessagesData]),
peers,
};
} catch (err) {
Expand Down Expand Up @@ -70,7 +70,7 @@ const getAllMessages = async (params) => {
merge(getDefaultGetListResponse()),
]);
return {
items: applyTransform({ messages, peers, chats }, [mergeMessagesData]).reverse(),
items: applyTransform({ messages, peers, chats }, [mergeMessagesData]),
next,
};
} catch (err) {
Expand Down
44 changes: 30 additions & 14 deletions src/modules/QueryFilters/mixins/sortFilterMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ const decodeSortQuery = ({ value }) => {
};
};

const changeHeadersSort = ({ headers, sortedHeader, order }) => {
return headers.map((header) => {
if (header.sort === undefined) return header;

// reset all headers by default
let newSort = null;

if (header.field === sortedHeader.field) {
newSort = order;
}

return {
...header,
sort: newSort,
};
});
};

export default {
mixins: [baseFilterMixin],
data: () => ({
Expand All @@ -40,21 +58,12 @@ export default {
},

setValue({ column, order }) {
const headers = this.headers.map((header) => {
if (header.sort === undefined) return header;

// reset all headers by default
let newSort = null;

if (header.value === column.value) {
newSort = order;
}

return {
...header,
sort: newSort,
};
const headers = changeHeadersSort({
headers: this.headers,
sortedHeader: column,
order,
});

const value = encodeSortQuery({ column, order });
this.setHeaders(headers);
this.setValueToQuery({
Expand All @@ -65,6 +74,13 @@ export default {

restoreValue(value) {
const sortedColumns = decodeSortQuery({ value });

debugger;

// const sortedHeader =

// const headers = changeHeadersSort({ headers: this.headers, sortedHeader: { field: sortedColumns[0] }, order });

const headers = this.headers.map((header) => ({
...header,
sort: sortedColumns[header.field] || null,
Expand Down

0 comments on commit a0c150c

Please sign in to comment.