Skip to content

Commit e2891ae

Browse files
committed
Move away from passing listType prop to using functions to get the derived list type
1 parent cd3b5c0 commit e2891ae

File tree

9 files changed

+118
-49
lines changed

9 files changed

+118
-49
lines changed

src/actions/search.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import get from 'lodash/get';
22
import { getSearchResult, isSearchDirty, isSearchPending } from '../reducers';
33
import getSession from '../helpers/session';
4-
import { convertAdvancedSearchConditionToNXQL } from '../helpers/searchHelpers';
4+
import { convertAdvancedSearchConditionToNXQL, deriveSearchType } from '../helpers/searchHelpers';
55

66
import {
77
ERR_UNKNOWN_RECORD_TYPE,
@@ -100,12 +100,10 @@ const buildAdvancedSearchPath = () => '/advancedsearch';
100100
* @param {*} config The cspace configuration
101101
* @param {*} searchName The search being executed (e.g. SEARCH_RESULT_PAGE_SEARCH_NAME)
102102
* @param {*} searchDescriptor The search descriptor (record type, query params, etc)
103-
* @param {*} listType The type of list being returned by the API (common, advancedsearch, etc)
104103
* @param {*} columnSetName The columns for the view being returned, used for sort fields
105-
* @param {*} isNewSearch If the search should use the new API
106104
* @returns
107105
*/
108-
export const search = (config, searchName, searchDescriptor, listType = 'common', columnSetName = 'default', isNewSearch = false) => (dispatch, getState) => {
106+
export const search = (config, searchName, searchDescriptor, columnSetName = 'default') => (dispatch, getState) => {
109107
const recordType = searchDescriptor.get('recordType');
110108
const vocabulary = searchDescriptor.get('vocabulary');
111109
const csid = searchDescriptor.get('csid');
@@ -132,6 +130,11 @@ export const search = (config, searchName, searchDescriptor, listType = 'common'
132130
return Promise.resolve();
133131
}
134132

133+
const {
134+
listType,
135+
searchType,
136+
} = deriveSearchType(config, searchName, searchDescriptor);
137+
135138
const listTypeConfig = config.listTypes[listType];
136139

137140
dispatch({
@@ -280,7 +283,7 @@ export const search = (config, searchName, searchDescriptor, listType = 'common'
280283
pathParts.push(subresourceServicePath);
281284
}
282285

283-
const path = isNewSearch
286+
const path = searchType === 'advanced'
284287
? buildAdvancedSearchPath()
285288
: buildSearchPath(csid, subresource, config, recordTypeServicePath, vocabularyServicePath);
286289

src/components/media/MediaViewerPanel.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ export default class MediaViewerPanel extends Component {
6565
const {
6666
columnSetName,
6767
config,
68-
listType,
6968
name,
7069
search,
7170
searchDescriptor,
7271
} = this.props;
7372

7473
if (search) {
75-
search(config, name, searchDescriptor, listType, columnSetName);
74+
search(config, name, searchDescriptor, columnSetName);
7675
}
7776
}
7877

src/components/pages/SearchResultPage.jsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import ExportModalContainer from '../../containers/search/ExportModalContainer';
1919
import WatchedSearchResultTableContainer from '../../containers/search/WatchedSearchResultTableContainer';
2020
import SearchToRelateModalContainer from '../../containers/search/SearchToRelateModalContainer';
2121
import { canRelate } from '../../helpers/permissionHelpers';
22-
import { getListType } from '../../helpers/searchHelpers';
22+
import { deriveSearchType, getListType, getListTypeForResult } from '../../helpers/searchHelpers';
2323
import { SEARCH_RESULT_PAGE_SEARCH_NAME } from '../../constants/searchNames';
2424

2525
import {
@@ -206,8 +206,11 @@ export default class SearchResultPage extends Component {
206206
} = this.context;
207207

208208
if (onItemSelectChange) {
209+
// certainly we could use the search result at this point
209210
const searchDescriptor = this.getSearchDescriptor();
210-
const listType = this.getListType(searchDescriptor);
211+
const {
212+
listType,
213+
} = deriveSearchType(config, SEARCH_RESULT_PAGE_SEARCH_NAME, searchDescriptor);
211214

212215
onItemSelectChange(
213216
config, SEARCH_RESULT_PAGE_SEARCH_NAME, searchDescriptor, listType, index, selected,
@@ -574,9 +577,7 @@ export default class SearchResultPage extends Component {
574577
// has set them to the defaults.
575578

576579
if (!Number.isNaN(searchQuery.get('p')) && !Number.isNaN(searchQuery.get('size')) && search) {
577-
const listType = this.getListType(searchDescriptor);
578-
579-
search(config, SEARCH_RESULT_PAGE_SEARCH_NAME, searchDescriptor, listType);
580+
search(config, SEARCH_RESULT_PAGE_SEARCH_NAME, searchDescriptor);
580581
}
581582
}
582583

@@ -663,7 +664,7 @@ export default class SearchResultPage extends Component {
663664
} = this.context;
664665

665666
const searchDescriptor = this.getSearchDescriptor();
666-
const listType = this.getListType(searchDescriptor);
667+
const { listType } = deriveSearchType(config, SEARCH_RESULT_PAGE_SEARCH_NAME, searchDescriptor);
667668

668669
let selectBar;
669670

@@ -731,8 +732,7 @@ export default class SearchResultPage extends Component {
731732
config,
732733
} = this.context;
733734

734-
const searchDescriptor = this.getSearchDescriptor();
735-
const listType = this.getListType(searchDescriptor);
735+
const listType = getListTypeForResult(config, searchResult);
736736
const listTypeConfig = config.listTypes[listType];
737737
const { listNodeName } = listTypeConfig;
738738

@@ -783,7 +783,7 @@ export default class SearchResultPage extends Component {
783783

784784
const searchDescriptor = this.getSearchDescriptor();
785785

786-
const listType = this.getListType(searchDescriptor);
786+
const { listType } = deriveSearchType(config, SEARCH_RESULT_PAGE_SEARCH_NAME, searchDescriptor);
787787

788788
const recordType = searchDescriptor.get('recordType');
789789
const vocabulary = searchDescriptor.get('vocabulary');

src/components/search/SearchPanel.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { baseComponents as inputComponents } from 'cspace-input';
88
import { ConnectedPanel as Panel } from '../../containers/layout/PanelContainer';
99
import SearchResultTableContainer from '../../containers/search/SearchResultTableContainer';
1010
import SearchToRelateModalContainer from '../../containers/search/SearchToRelateModalContainer';
11-
import { searchDescriptorToLocation } from '../../helpers/searchHelpers';
11+
import { getListTypeForResult, searchDescriptorToLocation } from '../../helpers/searchHelpers';
1212
import Pager from './Pager';
1313
import styles from '../../../styles/cspace-ui/SearchPanel.css';
1414

@@ -235,14 +235,13 @@ export default class SearchPanel extends Component {
235235
const {
236236
columnSetName,
237237
config,
238-
listType,
239238
name,
240239
search,
241240
searchDescriptor,
242241
} = this.props;
243242

244243
if (search) {
245-
search(config, name, searchDescriptor, listType, columnSetName);
244+
search(config, name, searchDescriptor, columnSetName);
246245
}
247246
}
248247

@@ -285,11 +284,13 @@ export default class SearchPanel extends Component {
285284
const {
286285
config,
287286
isFiltered,
288-
listType,
289287
searchResult,
290288
title,
291289
} = this.props;
292290

291+
// can the search result ever be null here?
292+
const listType = getListTypeForResult(config, searchResult);
293+
293294
const listTypeConfig = config.listTypes[listType];
294295

295296
const totalItems = searchResult
@@ -322,11 +323,11 @@ export default class SearchPanel extends Component {
322323
renderFooter({ searchResult }) {
323324
const {
324325
config,
325-
listType,
326326
pageSizeOptionListName,
327327
} = this.props;
328328

329329
if (searchResult) {
330+
const listType = getListTypeForResult(config, searchResult);
330331
const listTypeConfig = config.listTypes[listType];
331332
const list = searchResult.get(listTypeConfig.listNodeName);
332333

src/components/search/SearchResultTable.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Table } from 'cspace-layout';
88
import dimensions from '../../../styles/dimensions.css';
99
import styles from '../../../styles/cspace-ui/SearchResultTable.css';
1010
import emptyResultStyles from '../../../styles/cspace-ui/SearchResultEmpty.css';
11+
import { deriveSearchType, getListTypeForResult } from '../../helpers/searchHelpers';
1112

1213
const rowHeight = parseInt(dimensions.inputHeight, 10);
1314

@@ -185,12 +186,12 @@ export default class SearchResultTable extends Component {
185186
handleRowClick(index) {
186187
const {
187188
config,
188-
listType,
189189
searchResult,
190190
onItemClick,
191191
} = this.props;
192192

193193
if (onItemClick) {
194+
const listType = getListTypeForResult(config, searchResult);
194195
const listTypeConfig = config.listTypes[listType];
195196
const { listNodeName, itemNodeName } = listTypeConfig;
196197

@@ -234,11 +235,12 @@ export default class SearchResultTable extends Component {
234235
const {
235236
config,
236237
linkState,
237-
listType,
238238
perms,
239+
searchResult,
239240
searchDescriptor,
240241
} = this.props;
241242

243+
const listType = getListTypeForResult(config, searchResult);
242244
const getItemLocationPath = get(config, ['listTypes', listType, 'getItemLocationPath']);
243245

244246
if (!getItemLocationPath) {
@@ -342,14 +344,14 @@ export default class SearchResultTable extends Component {
342344
config,
343345
formatCellData,
344346
formatColumnLabel,
345-
listType,
346347
searchDescriptor,
347348
searchResult,
348349
showCheckboxColumn,
349350
renderCheckbox,
350351
} = this.props;
351352

352353
if (searchResult) {
354+
const listType = getListTypeForResult(config, searchResult);
353355
const searchQuery = searchDescriptor.get('searchQuery');
354356

355357
const listTypeConfig = config.listTypes[listType];

src/components/search/SearchResultTraverser.jsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Immutable from 'immutable';
66
import SearchResultItemLink from './SearchResultItemLink';
77

88
import {
9-
getListType,
9+
deriveSearchType,
1010
searchDescriptorToLocation,
1111
} from '../../helpers/searchHelpers';
1212

@@ -66,7 +66,6 @@ export default class SearchResultTraverser extends Component {
6666
const {
6767
config,
6868
csid,
69-
listType: listTypeProp,
7069
searchDescriptor,
7170
searchState,
7271
nextPageSearchDescriptor,
@@ -77,15 +76,15 @@ export default class SearchResultTraverser extends Component {
7776
search,
7877
} = this.props;
7978

80-
const listType = listTypeProp || getListType(config, searchDescriptor);
79+
const { listType } = deriveSearchType(config, searchName, searchDescriptor);
8180
if (search) {
8281
if (searchDescriptor && !searchState) {
8382
// We have a search descriptor, but it's not associated with any state. This happens when
8483
// navigating to a record from a search, and reloading -- the search descriptor is
8584
// maintained in history state, but the search state is gone, since the app has been
8685
// reloaded. Initiate the search.
8786

88-
search(config, searchName, searchDescriptor, listType);
87+
search(config, searchName, searchDescriptor);
8988
}
9089

9190
if (searchState && !searchState.get('isPending') && searchState.get('result')) {
@@ -127,7 +126,6 @@ export default class SearchResultTraverser extends Component {
127126
config,
128127
searchName,
129128
prevPageSearchDescriptor,
130-
listType,
131129
);
132130
}
133131

@@ -144,17 +142,15 @@ export default class SearchResultTraverser extends Component {
144142
config,
145143
searchName,
146144
nextPageSearchDescriptor,
147-
listType,
148145
);
149146
}
150147
}
151148
}
152149
}
153150

154-
renderPrevLink(items, index, currentNum, totalItems, locationState) {
151+
renderPrevLink(items, index, currentNum, totalItems, locationState, listType) {
155152
const {
156153
config,
157-
listType: listTypeProp,
158154
searchName,
159155
prevPageSearchState,
160156
prevPageSearchDescriptor,
@@ -178,7 +174,6 @@ export default class SearchResultTraverser extends Component {
178174
// We're at the beginning of the current page, but we have data for the previous page. Link
179175
// to the last item in its results.
180176

181-
const listType = listTypeProp || getListType(config, prevPageSearchDescriptor);
182177
const listTypeConfig = config.listTypes[listType];
183178
const { listNodeName, itemNodeName } = listTypeConfig;
184179

@@ -213,10 +208,9 @@ export default class SearchResultTraverser extends Component {
213208
return <FormattedMessage {...messages.prev} />;
214209
}
215210

216-
renderNextLink(items, index, currentNum, totalItems, locationState) {
211+
renderNextLink(items, index, currentNum, totalItems, locationState, listType) {
217212
const {
218213
config,
219-
listType: listTypeProp,
220214
searchName,
221215
nextPageSearchState,
222216
nextPageSearchDescriptor,
@@ -240,7 +234,6 @@ export default class SearchResultTraverser extends Component {
240234
// We're at the end of the current page, but we have data for the next page. Link to the
241235
// first item in its results.
242236

243-
const listType = listTypeProp || getListType(config, nextPageSearchDescriptor);
244237
const listTypeConfig = config.listTypes[listType];
245238
const { listNodeName, itemNodeName } = listTypeConfig;
246239

@@ -279,7 +272,6 @@ export default class SearchResultTraverser extends Component {
279272
const {
280273
config,
281274
csid,
282-
listType: listTypeProp,
283275
searchDescriptor,
284276
searchName,
285277
searchState,
@@ -301,7 +293,7 @@ export default class SearchResultTraverser extends Component {
301293
) {
302294
resultMessage = <FormattedMessage {...messages.resultPending} />;
303295
} else {
304-
const listType = listTypeProp || getListType(config, searchDescriptor);
296+
const { listType } = deriveSearchType(config, searchName, searchDescriptor);
305297
const listTypeConfig = config.listTypes[listType];
306298
const { listNodeName, itemNodeName } = listTypeConfig;
307299

@@ -337,20 +329,16 @@ export default class SearchResultTraverser extends Component {
337329
originSearchPage: originSearchPageState,
338330
};
339331

340-
console.log('renderprev');
341-
prevLink = this.renderPrevLink(items, index, currentNum, totalItems, locationState);
342-
console.log('rendernext');
343-
nextLink = this.renderNextLink(items, index, currentNum, totalItems, locationState);
332+
prevLink = this.renderPrevLink(items, index, currentNum, totalItems, locationState, listType);
333+
nextLink = this.renderNextLink(items, index, currentNum, totalItems, locationState, listType);
344334
}
345335

346-
console.log('searchloc');
347336
const searchLocation = Object.assign(searchDescriptorToLocation(searchDescriptor), {
348337
state: {
349338
originSearchPage: originSearchPageState,
350339
},
351340
});
352341

353-
console.log('return');
354342
return (
355343
<nav className={styles.common}>
356344
<div>

0 commit comments

Comments
 (0)