2020-12-16 03:09:46 +00:00
|
|
|
import { transformBoardConfig } from 'ee_else_ce/boards/boards_util';
|
2021-02-14 18:09:20 +00:00
|
|
|
import FilteredSearchManager from 'ee_else_ce/filtered_search/filtered_search_manager';
|
|
|
|
import IssuableFilteredSearchTokenKeys from 'ee_else_ce/filtered_search/issuable_filtered_search_token_keys';
|
2021-02-01 15:08:56 +00:00
|
|
|
import { updateHistory } from '~/lib/utils/url_utility';
|
2020-08-17 21:09:56 +00:00
|
|
|
import FilteredSearchContainer from '../filtered_search/container';
|
2020-12-16 03:09:46 +00:00
|
|
|
import vuexstore from './stores';
|
2021-02-14 18:09:20 +00:00
|
|
|
import boardsStore from './stores/boards_store';
|
2017-03-15 10:52:49 +00:00
|
|
|
|
2018-02-21 20:22:56 +00:00
|
|
|
export default class FilteredSearchBoards extends FilteredSearchManager {
|
2020-12-16 03:09:46 +00:00
|
|
|
constructor(store, updateUrl = false, cantEdit = []) {
|
2018-03-01 07:34:24 +00:00
|
|
|
super({
|
|
|
|
page: 'boards',
|
2018-04-04 21:43:33 +00:00
|
|
|
isGroupDecendent: true,
|
2018-02-19 19:06:16 +00:00
|
|
|
stateFiltersSelector: '.issues-state-filters',
|
2019-07-04 11:36:49 +00:00
|
|
|
isGroup: IS_EE,
|
2020-08-11 18:10:06 +00:00
|
|
|
useDefaultState: false,
|
2019-04-08 12:53:02 +00:00
|
|
|
filteredSearchTokenKeys: IssuableFilteredSearchTokenKeys,
|
2018-03-01 07:34:24 +00:00
|
|
|
});
|
2017-03-07 11:05:37 +00:00
|
|
|
|
|
|
|
this.store = store;
|
2017-03-07 14:43:17 +00:00
|
|
|
this.updateUrl = updateUrl;
|
2017-03-09 12:32:43 +00:00
|
|
|
|
|
|
|
// Issue boards is slightly different, we handle all the requests async
|
|
|
|
// instead or reloading the page, we just re-fire the list ajax requests
|
2017-03-07 14:28:50 +00:00
|
|
|
this.isHandledAsync = true;
|
2020-12-23 21:10:24 +00:00
|
|
|
this.cantEdit = cantEdit.filter((i) => typeof i === 'string');
|
|
|
|
this.cantEditWithValue = cantEdit.filter((i) => typeof i === 'object');
|
2020-11-26 18:09:18 +00:00
|
|
|
|
2020-12-16 03:09:46 +00:00
|
|
|
if (vuexstore.getters.shouldUseGraphQL && vuexstore.state.boardConfig) {
|
|
|
|
const boardConfigPath = transformBoardConfig(vuexstore.state.boardConfig);
|
2021-04-29 15:10:07 +00:00
|
|
|
// TODO Refactor: https://gitlab.com/gitlab-org/gitlab/-/issues/329274
|
|
|
|
// here we are using "window.location.search" as a temporary store
|
|
|
|
// only to unpack the params and do another validation inside
|
|
|
|
// 'performSearch' and 'setFilter' vuex actions.
|
2020-12-16 03:09:46 +00:00
|
|
|
if (boardConfigPath !== '') {
|
|
|
|
const filterPath = window.location.search ? `${window.location.search}&` : '?';
|
|
|
|
updateHistory({
|
|
|
|
url: `${filterPath}${transformBoardConfig(vuexstore.state.boardConfig)}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-03-07 11:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateObject(path) {
|
2020-10-16 06:08:48 +00:00
|
|
|
const groupByParam = new URLSearchParams(window.location.search).get('group_by');
|
|
|
|
this.store.path = `${path.substr(1)}${groupByParam ? `&group_by=${groupByParam}` : ''}`;
|
2017-03-07 14:28:50 +00:00
|
|
|
|
2020-12-16 03:09:46 +00:00
|
|
|
if (vuexstore.getters.shouldUseGraphQL) {
|
|
|
|
updateHistory({
|
|
|
|
url: `?${path.substr(1)}${groupByParam ? `&group_by=${groupByParam}` : ''}`,
|
|
|
|
});
|
|
|
|
vuexstore.dispatch('performSearch');
|
2020-11-26 18:09:18 +00:00
|
|
|
} else if (this.updateUrl) {
|
2018-10-10 17:08:43 +00:00
|
|
|
boardsStore.updateFiltersUrl();
|
2017-03-07 14:43:17 +00:00
|
|
|
}
|
2017-03-07 09:24:01 +00:00
|
|
|
}
|
2017-03-08 12:17:01 +00:00
|
|
|
|
2017-03-15 10:52:49 +00:00
|
|
|
removeTokens() {
|
|
|
|
const tokens = FilteredSearchContainer.container.querySelectorAll('.js-visual-token');
|
2017-03-08 12:17:01 +00:00
|
|
|
|
|
|
|
// Remove all the tokens as they will be replaced by the search manager
|
2020-12-23 21:10:24 +00:00
|
|
|
[].forEach.call(tokens, (el) => {
|
2017-03-08 12:17:01 +00:00
|
|
|
el.parentNode.removeChild(el);
|
|
|
|
});
|
2017-03-21 14:44:51 +00:00
|
|
|
|
|
|
|
this.filteredSearchInput.value = '';
|
2017-03-15 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateTokens() {
|
|
|
|
this.removeTokens();
|
2017-03-08 12:17:01 +00:00
|
|
|
|
|
|
|
this.loadSearchParamsFromURL();
|
|
|
|
|
|
|
|
// Get the placeholder back if search is empty
|
|
|
|
this.filteredSearchInput.dispatchEvent(new Event('input'));
|
|
|
|
}
|
2017-05-22 19:58:23 +00:00
|
|
|
|
2017-10-24 13:48:41 +00:00
|
|
|
canEdit(tokenName, tokenValue) {
|
|
|
|
if (this.cantEdit.includes(tokenName)) return false;
|
2018-10-30 20:28:31 +00:00
|
|
|
return (
|
|
|
|
this.cantEditWithValue.findIndex(
|
2020-12-23 21:10:24 +00:00
|
|
|
(token) => token.name === tokenName && token.value === tokenValue,
|
2018-10-30 20:28:31 +00:00
|
|
|
) === -1
|
|
|
|
);
|
2017-05-22 19:58:23 +00:00
|
|
|
}
|
2017-03-07 09:24:01 +00:00
|
|
|
}
|