Commit 2c57281a authored by Clement Ho's avatar Clement Ho

Merge branch 'update-search-functionality' into 'master'

Update search functionality / fix sort by for sentry errors

See merge request gitlab-org/gitlab!21981
parents 12520e50 6895b6c4
...@@ -113,6 +113,7 @@ export default { ...@@ -113,6 +113,7 @@ export default {
'sortField', 'sortField',
'recentSearches', 'recentSearches',
'pagination', 'pagination',
'cursor',
]), ]),
paginationRequired() { paginationRequired() {
return !_.isEmpty(this.pagination); return !_.isEmpty(this.pagination);
...@@ -142,6 +143,7 @@ export default { ...@@ -142,6 +143,7 @@ export default {
'clearRecentSearches', 'clearRecentSearches',
'loadRecentSearches', 'loadRecentSearches',
'setIndexPath', 'setIndexPath',
'fetchPaginatedResults',
]), ]),
setSearchText(text) { setSearchText(text) {
this.errorSearchQuery = text; this.errorSearchQuery = text;
...@@ -152,10 +154,10 @@ export default { ...@@ -152,10 +154,10 @@ export default {
}, },
goToNextPage() { goToNextPage() {
this.pageValue = this.$options.NEXT_PAGE; this.pageValue = this.$options.NEXT_PAGE;
this.startPolling(`${this.indexPath}?cursor=${this.pagination.next.cursor}`); this.fetchPaginatedResults(this.pagination.next.cursor);
}, },
goToPrevPage() { goToPrevPage() {
this.startPolling(`${this.indexPath}?cursor=${this.pagination.previous.cursor}`); this.fetchPaginatedResults(this.pagination.previous.cursor);
}, },
goToPage(page) { goToPage(page) {
window.scrollTo(0, 0); window.scrollTo(0, 0);
......
...@@ -17,12 +17,14 @@ export function startPolling({ state, commit, dispatch }) { ...@@ -17,12 +17,14 @@ export function startPolling({ state, commit, dispatch }) {
params: { params: {
search_term: state.searchQuery, search_term: state.searchQuery,
sort: state.sortField, sort: state.sortField,
cursor: state.cursor,
}, },
}, },
successCallback: ({ data }) => { successCallback: ({ data }) => {
if (!data) { if (!data) {
return; return;
} }
commit(types.SET_PAGINATION, data.pagination); commit(types.SET_PAGINATION, data.pagination);
commit(types.SET_ERRORS, data.errors); commit(types.SET_ERRORS, data.errors);
commit(types.SET_LOADING, false); commit(types.SET_LOADING, false);
...@@ -74,6 +76,7 @@ export function clearRecentSearches({ commit }) { ...@@ -74,6 +76,7 @@ export function clearRecentSearches({ commit }) {
export const searchByQuery = ({ commit, dispatch }, query) => { export const searchByQuery = ({ commit, dispatch }, query) => {
const searchQuery = query.trim(); const searchQuery = query.trim();
commit(types.SET_CURSOR, null);
commit(types.SET_SEARCH_QUERY, searchQuery); commit(types.SET_SEARCH_QUERY, searchQuery);
commit(types.ADD_RECENT_SEARCH, searchQuery); commit(types.ADD_RECENT_SEARCH, searchQuery);
dispatch('stopPolling'); dispatch('stopPolling');
...@@ -81,6 +84,7 @@ export const searchByQuery = ({ commit, dispatch }, query) => { ...@@ -81,6 +84,7 @@ export const searchByQuery = ({ commit, dispatch }, query) => {
}; };
export const sortByField = ({ commit, dispatch }, field) => { export const sortByField = ({ commit, dispatch }, field) => {
commit(types.SET_CURSOR, null);
commit(types.SET_SORT_FIELD, field); commit(types.SET_SORT_FIELD, field);
dispatch('stopPolling'); dispatch('stopPolling');
dispatch('startPolling'); dispatch('startPolling');
...@@ -90,4 +94,10 @@ export const setEndpoint = ({ commit }, endpoint) => { ...@@ -90,4 +94,10 @@ export const setEndpoint = ({ commit }, endpoint) => {
commit(types.SET_ENDPOINT, endpoint); commit(types.SET_ENDPOINT, endpoint);
}; };
export const fetchPaginatedResults = ({ commit, dispatch }, cursor) => {
commit(types.SET_CURSOR, cursor);
dispatch('stopPolling');
dispatch('startPolling');
};
export default () => {}; export default () => {};
...@@ -8,3 +8,4 @@ export const SET_PAGINATION = 'SET_PAGINATION'; ...@@ -8,3 +8,4 @@ export const SET_PAGINATION = 'SET_PAGINATION';
export const SET_ENDPOINT = 'SET_ENDPOINT'; export const SET_ENDPOINT = 'SET_ENDPOINT';
export const SET_SORT_FIELD = 'SET_SORT_FIELD'; export const SET_SORT_FIELD = 'SET_SORT_FIELD';
export const SET_SEARCH_QUERY = 'SET_SEARCH_QUERY'; export const SET_SEARCH_QUERY = 'SET_SEARCH_QUERY';
export const SET_CURSOR = 'SET_CURSOR';
...@@ -47,6 +47,9 @@ export default { ...@@ -47,6 +47,9 @@ export default {
[types.SET_PAGINATION](state, pagination) { [types.SET_PAGINATION](state, pagination) {
state.pagination = pagination; state.pagination = pagination;
}, },
[types.SET_CURSOR](state, cursor) {
state.cursor = cursor;
},
[types.SET_SORT_FIELD](state, field) { [types.SET_SORT_FIELD](state, field) {
state.sortField = field; state.sortField = field;
}, },
......
...@@ -7,4 +7,5 @@ export default () => ({ ...@@ -7,4 +7,5 @@ export default () => ({
indexPath: '', indexPath: '',
recentSearches: [], recentSearches: [],
pagination: {}, pagination: {},
cursor: null,
}); });
...@@ -71,6 +71,7 @@ describe('ErrorTrackingList', () => { ...@@ -71,6 +71,7 @@ describe('ErrorTrackingList', () => {
setEndpoint: jest.fn(), setEndpoint: jest.fn(),
searchByQuery: jest.fn(), searchByQuery: jest.fn(),
sortByField: jest.fn(), sortByField: jest.fn(),
fetchPaginatedResults: jest.fn(),
}; };
const state = { const state = {
...@@ -305,10 +306,10 @@ describe('ErrorTrackingList', () => { ...@@ -305,10 +306,10 @@ describe('ErrorTrackingList', () => {
it('fetches the previous page of results', () => { it('fetches the previous page of results', () => {
expect(wrapper.find('.prev-page-item').attributes('aria-disabled')).toBe(undefined); expect(wrapper.find('.prev-page-item').attributes('aria-disabled')).toBe(undefined);
wrapper.vm.goToPrevPage(); wrapper.vm.goToPrevPage();
expect(actions.startPolling).toHaveBeenCalledTimes(2); expect(actions.fetchPaginatedResults).toHaveBeenCalled();
expect(actions.startPolling).toHaveBeenLastCalledWith( expect(actions.fetchPaginatedResults).toHaveBeenLastCalledWith(
expect.anything(), expect.anything(),
'/path?cursor=previousCursor', 'previousCursor',
undefined, undefined,
); );
}); });
...@@ -324,10 +325,10 @@ describe('ErrorTrackingList', () => { ...@@ -324,10 +325,10 @@ describe('ErrorTrackingList', () => {
window.scrollTo = jest.fn(); window.scrollTo = jest.fn();
findPagination().vm.$emit('input', 2); findPagination().vm.$emit('input', 2);
expect(window.scrollTo).toHaveBeenCalledWith(0, 0); expect(window.scrollTo).toHaveBeenCalledWith(0, 0);
expect(actions.startPolling).toHaveBeenCalledTimes(2); expect(actions.fetchPaginatedResults).toHaveBeenCalled();
expect(actions.startPolling).toHaveBeenLastCalledWith( expect(actions.fetchPaginatedResults).toHaveBeenLastCalledWith(
expect.anything(), expect.anything(),
'/path?cursor=nextCursor', 'nextCursor',
undefined, undefined,
); );
}); });
......
...@@ -79,6 +79,7 @@ describe('error tracking actions', () => { ...@@ -79,6 +79,7 @@ describe('error tracking actions', () => {
query, query,
{}, {},
[ [
{ type: types.SET_CURSOR, payload: null },
{ type: types.SET_SEARCH_QUERY, payload: query }, { type: types.SET_SEARCH_QUERY, payload: query },
{ type: types.ADD_RECENT_SEARCH, payload: query }, { type: types.ADD_RECENT_SEARCH, payload: query },
], ],
...@@ -93,15 +94,15 @@ describe('error tracking actions', () => { ...@@ -93,15 +94,15 @@ describe('error tracking actions', () => {
testAction( testAction(
actions.sortByField, actions.sortByField,
{ field }, field,
{}, {},
[{ type: types.SET_SORT_FIELD, payload: { field } }], [{ type: types.SET_CURSOR, payload: null }, { type: types.SET_SORT_FIELD, payload: field }],
[{ type: 'stopPolling' }, { type: 'startPolling' }], [{ type: 'stopPolling' }, { type: 'startPolling' }],
); );
}); });
}); });
describe('setEnpoint', () => { describe('setEndpoint', () => {
it('should set search endpoint', () => { it('should set search endpoint', () => {
const endpoint = 'https://sentry.io'; const endpoint = 'https://sentry.io';
...@@ -114,4 +115,17 @@ describe('error tracking actions', () => { ...@@ -114,4 +115,17 @@ describe('error tracking actions', () => {
); );
}); });
}); });
describe('fetchPaginatedResults', () => {
it('should start polling the selected page cursor', () => {
const cursor = '1576637570000:1:1';
testAction(
actions.fetchPaginatedResults,
cursor,
{},
[{ type: types.SET_CURSOR, payload: cursor }],
[{ type: 'stopPolling' }, { type: 'startPolling' }],
);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment