cspace-ui
Version:
CollectionSpace user interface for browsers
152 lines (151 loc) • 8.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isSearchResultSidebarOpen = exports.isRecordSidebarOpen = exports.isPanelCollapsed = exports.getUseNewSearch = exports.getUploadType = exports.getToolTab = exports.getStickyFields = exports.getSearchToSelectPageSize = exports.getSearchResultPageView = exports.getSearchResultPagePageSize = exports.getSearchPanelPageSize = exports.getSearchPageVocabulary = exports.getSearchPageRecordType = exports.getSearchNewCondition = exports.getSearchCondition = exports.getRecordBrowserNavBarItems = exports.getQuickSearchVocabulary = exports.getQuickSearchRecordType = exports.getNewSearchShown = exports.getForm = exports.getAdvancedSearchNewBooleanOp = exports.getAdvancedSearchBooleanOp = exports.getAdminTab = exports.default = void 0;
var _immutable = _interopRequireDefault(require("immutable"));
var _searchOperators = require("../constants/searchOperators");
var _searchHelpers = require("../helpers/searchHelpers");
var _actionCodes = require("../constants/actionCodes");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const handleAdvancedSearchConditionChange = (state, action) => {
const {
recordType,
searchTermsGroup
} = action.meta;
if (!recordType) {
return state;
}
const condition = action.payload;
const op = condition ? condition.get('op') : null;
let nextState = state;
if (op === _searchOperators.OP_AND || op === _searchOperators.OP_OR) {
nextState = searchTermsGroup ? nextState.setIn(['advancedSearchNewBooleanOp', searchTermsGroup], op) : nextState.set('advancedSearchBooleanOp', op);
}
nextState = nextState.setIn(searchTermsGroup ? ['searchNewCond', recordType, searchTermsGroup] : ['searchCond', recordType], (0, _searchHelpers.clearAdvancedSearchConditionValues)(condition));
return nextState;
};
const handleToggleRecordSidebar = state => {
let isOpen = state.get('recordSidebarOpen');
if (typeof isOpen === 'undefined') {
isOpen = true;
}
return state.set('recordSidebarOpen', !isOpen);
};
const handleToggleSearchResultSidebar = state => {
let isOpen = state.get('searchResultSidebarOpen');
if (typeof isOpen === 'undefined') {
isOpen = true;
}
return state.set('searchResultSidebarOpen', !isOpen);
};
const setStickyFields = (state, action) => {
const data = action.payload;
const {
recordTypeConfig
} = action.meta;
return state.setIn(['stickyFields', recordTypeConfig.name], data);
};
var _default = (state = _immutable.default.Map(), action) => {
switch (action.type) {
case _actionCodes.PREFS_LOADED:
return action.payload || _immutable.default.Map();
case _actionCodes.COLLAPSE_PANEL:
return state.setIn(['panels', action.meta.recordType, action.meta.name, 'collapsed'], action.payload);
case _actionCodes.SET_ADMIN_TAB:
return state.set('adminTab', action.payload);
case _actionCodes.SET_TOOL_TAB:
return state.set('toolTab', action.payload);
case _actionCodes.SET_RECORD_BROWSER_NAV_BAR_ITEMS:
return state.setIn(['recordBrowserNavBarItems', action.meta.recordType], action.payload);
case _actionCodes.SET_SEARCH_PAGE_RECORD_TYPE:
return state.setIn(['searchPage', 'recordType'], action.payload);
case _actionCodes.SET_SEARCH_PAGE_VOCABULARY:
return state.setIn(['searchPage', 'vocabulary', state.getIn(['searchPage', 'recordType'])], action.payload);
case _actionCodes.SET_QUICK_SEARCH_RECORD_TYPE:
return state.setIn(['quickSearch', 'recordType'], action.payload);
case _actionCodes.SET_QUICK_SEARCH_VOCABULARY:
return state.setIn(['quickSearch', 'vocabulary', state.getIn(['quickSearch', 'recordType'])], action.payload);
case _actionCodes.SET_SEARCH_PANEL_PAGE_SIZE:
return state.setIn(['panels', action.meta.recordType, action.meta.name, 'pageSize'], action.payload);
case _actionCodes.SET_SEARCH_RESULT_PAGE_PAGE_SIZE:
return state.set('searchResultPagePageSize', action.payload);
case _actionCodes.SET_SEARCH_RESULT_PAGE_VIEW:
return state.set('searchResultPageView', action.payload);
case _actionCodes.SET_SEARCH_TO_SELECT_PAGE_SIZE:
return state.set('searchToSelectPageSize', action.payload);
case _actionCodes.SET_FORM:
return state.setIn(['form', action.meta.recordType], action.payload);
case _actionCodes.SET_UPLOAD_TYPE:
return state.set('uploadType', action.payload);
case _actionCodes.SET_SEARCH_PAGE_ADVANCED:
case _actionCodes.SET_SEARCH_TO_SELECT_ADVANCED:
case _actionCodes.SET_SEARCH_PAGE_ADVANCED_SEARCH_TERMS:
case _actionCodes.SET_SEARCH_PAGE_ADVANCED_LIMIT_BY:
return handleAdvancedSearchConditionChange(state, action);
case _actionCodes.TOGGLE_RECORD_SIDEBAR:
return handleToggleRecordSidebar(state, action);
case _actionCodes.TOGGLE_SEARCH_RESULT_SIDEBAR:
return handleToggleSearchResultSidebar(state, action);
case _actionCodes.SET_STICKY_FIELDS:
return setStickyFields(state, action);
case _actionCodes.TOGGLE_USE_NEW_SEARCH:
return state.set('useNewSearch', typeof state.get('useNewSearch') === 'undefined' ? false : !state.get('useNewSearch'));
case _actionCodes.SET_NEW_SEARCH_SHOWN:
return state.set('newSearchShown', true);
default:
return state;
}
};
exports.default = _default;
const getAdvancedSearchBooleanOp = state => state.get('advancedSearchBooleanOp');
exports.getAdvancedSearchBooleanOp = getAdvancedSearchBooleanOp;
const getSearchCondition = (state, recordType) => state.getIn(['searchCond', recordType]);
exports.getSearchCondition = getSearchCondition;
const getAdvancedSearchNewBooleanOp = (state, searchTermsGroup) => state.getIn(['advancedSearchNewBooleanOp', searchTermsGroup]);
exports.getAdvancedSearchNewBooleanOp = getAdvancedSearchNewBooleanOp;
const getSearchNewCondition = (state, recordType, searchTermsGroup) => state.getIn(['searchNewCond', recordType, searchTermsGroup]);
exports.getSearchNewCondition = getSearchNewCondition;
const getSearchPageRecordType = state => state.getIn(['searchPage', 'recordType']);
exports.getSearchPageRecordType = getSearchPageRecordType;
const getSearchPageVocabulary = (state, recordType) => state.getIn(['searchPage', 'vocabulary', recordType]);
exports.getSearchPageVocabulary = getSearchPageVocabulary;
const getQuickSearchRecordType = state => state.getIn(['quickSearch', 'recordType']);
exports.getQuickSearchRecordType = getQuickSearchRecordType;
const getQuickSearchVocabulary = (state, recordType) => state.getIn(['quickSearch', 'vocabulary', recordType]);
exports.getQuickSearchVocabulary = getQuickSearchVocabulary;
const getSearchPanelPageSize = (state, recordType, name) => state.getIn(['panels', recordType, name, 'pageSize']);
exports.getSearchPanelPageSize = getSearchPanelPageSize;
const getSearchResultPagePageSize = state => state.get('searchResultPagePageSize');
exports.getSearchResultPagePageSize = getSearchResultPagePageSize;
const getSearchResultPageView = state => state.get('searchResultPageView');
exports.getSearchResultPageView = getSearchResultPageView;
const getSearchToSelectPageSize = state => state.get('searchToSelectPageSize');
exports.getSearchToSelectPageSize = getSearchToSelectPageSize;
const isPanelCollapsed = (state, recordType, name) => state.getIn(['panels', recordType, name, 'collapsed']);
exports.isPanelCollapsed = isPanelCollapsed;
const getRecordBrowserNavBarItems = (state, recordType) => state.getIn(['recordBrowserNavBarItems', recordType]);
exports.getRecordBrowserNavBarItems = getRecordBrowserNavBarItems;
const getForm = (state, recordType) => state.getIn(['form', recordType]);
exports.getForm = getForm;
const getUploadType = state => state.get('uploadType');
exports.getUploadType = getUploadType;
const getAdminTab = state => state.get('adminTab');
exports.getAdminTab = getAdminTab;
const getToolTab = state => state.get('toolTab');
exports.getToolTab = getToolTab;
const getNewSearchShown = state => state.get('newSearchShown');
exports.getNewSearchShown = getNewSearchShown;
const getUseNewSearch = state => state.get('useNewSearch');
exports.getUseNewSearch = getUseNewSearch;
const isRecordSidebarOpen = state => state.get('recordSidebarOpen');
exports.isRecordSidebarOpen = isRecordSidebarOpen;
const isSearchResultSidebarOpen = state => state.get('searchResultSidebarOpen');
exports.isSearchResultSidebarOpen = isSearchResultSidebarOpen;
const getStickyFields = (state, recordType) => {
if (typeof recordType === 'undefined') {
return state.get('stickyFields');
}
return state.getIn(['stickyFields', recordType]);
};
exports.getStickyFields = getStickyFields;