@cccsaurora/howler-ui 2.14.0-dev.210 → 2.14.0-dev.211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { QueryStats, SavedSearch } from '@mui/icons-material';
|
|
3
3
|
import { useAppLeftNav, useAppUser } from '@cccsaurora/howler-ui/commons/components/app/hooks';
|
|
4
|
-
import { uniq } from 'lodash-es';
|
|
4
|
+
import { sortBy, uniq } from 'lodash-es';
|
|
5
5
|
import { createContext, useCallback, useContext, useEffect } from 'react';
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
import { useContextSelector } from 'use-context-selector';
|
|
@@ -30,7 +30,7 @@ const FavouriteProvider = ({ children }) => {
|
|
|
30
30
|
return viewElement;
|
|
31
31
|
}
|
|
32
32
|
const savedViews = await fetchViews(favourites);
|
|
33
|
-
const items = savedViews
|
|
33
|
+
const items = sortBy(savedViews, 'title')
|
|
34
34
|
.filter(view => !!view)
|
|
35
35
|
.map(view => ({
|
|
36
36
|
id: view.view_id,
|
|
@@ -25,14 +25,15 @@ const ViewProvider = ({ children }) => {
|
|
|
25
25
|
}));
|
|
26
26
|
return newViews;
|
|
27
27
|
}
|
|
28
|
-
const missingIds = ids.filter(_id => !views
|
|
28
|
+
const missingIds = ids.filter(_id => !has(views, _id));
|
|
29
29
|
if (missingIds.length < 1) {
|
|
30
30
|
return ids.map(id => views[id]);
|
|
31
31
|
}
|
|
32
32
|
try {
|
|
33
33
|
const response = await dispatchApi(api.search.view.post({
|
|
34
34
|
query: `view_id:(${missingIds.join(' OR ')})`,
|
|
35
|
-
rows: missingIds.length
|
|
35
|
+
rows: missingIds.length,
|
|
36
|
+
sort: 'title asc'
|
|
36
37
|
}));
|
|
37
38
|
const newViews = Object.fromEntries(response.items.map(_view => [_view.view_id, _view]));
|
|
38
39
|
setViews(_views => ({
|
|
@@ -95,17 +95,29 @@ describe('ViewContext', () => {
|
|
|
95
95
|
it('Should search for specified views when ids are provided', async () => {
|
|
96
96
|
const result = await act(async () => hook.result.current(['searched_view_id']));
|
|
97
97
|
expect(hpost).toHaveBeenCalledOnce();
|
|
98
|
-
expect(hpost).toBeCalledWith('/api/v1/search/view', {
|
|
98
|
+
expect(hpost).toBeCalledWith('/api/v1/search/view', {
|
|
99
|
+
query: 'view_id:(searched_view_id)',
|
|
100
|
+
rows: 1,
|
|
101
|
+
sort: 'title asc'
|
|
102
|
+
});
|
|
99
103
|
expect(result).toEqual(MOCK_RESPONSES['/api/v1/search/view'].items);
|
|
100
104
|
});
|
|
101
105
|
it('Should search only for new views when ids are provided', async () => {
|
|
102
106
|
await act(async () => hook.result.current(['searched_view_id']));
|
|
103
107
|
expect(hpost).toHaveBeenCalledOnce();
|
|
104
|
-
expect(hpost).toBeCalledWith('/api/v1/search/view', {
|
|
108
|
+
expect(hpost).toBeCalledWith('/api/v1/search/view', {
|
|
109
|
+
query: 'view_id:(searched_view_id)',
|
|
110
|
+
rows: 1,
|
|
111
|
+
sort: 'title asc'
|
|
112
|
+
});
|
|
105
113
|
vi.mocked(hpost).mockClear();
|
|
106
114
|
await act(async () => hook.result.current(['searched_view_id', 'searched_view_id_2']));
|
|
107
115
|
expect(hpost).toHaveBeenCalledOnce();
|
|
108
|
-
expect(hpost).toBeCalledWith('/api/v1/search/view', {
|
|
116
|
+
expect(hpost).toBeCalledWith('/api/v1/search/view', {
|
|
117
|
+
query: 'view_id:(searched_view_id_2)',
|
|
118
|
+
rows: 1,
|
|
119
|
+
sort: 'title asc'
|
|
120
|
+
});
|
|
109
121
|
});
|
|
110
122
|
it('Should provide cached instances as a response when the same views are requested', async () => {
|
|
111
123
|
let result = await act(async () => hook.result.current(['searched_view_id']));
|