Skip to content

Commit 86129df

Browse files
authored
DRYD-1975: Search > Show empty form when starting a new session (#301)
1 parent b64d759 commit 86129df

File tree

3 files changed

+99
-12
lines changed

3 files changed

+99
-12
lines changed

src/components/search/AdvancedSearchBuilder.jsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,36 @@ export default class AdvancedSearchBuilder extends Component {
122122

123123
if (recordType && onConditionCommit) {
124124
let normalizedCondition;
125+
let initialCondition;
125126

126127
if (condition) {
127128
normalizedCondition = ensureRootBooleanOp(condition, preferredBooleanOp);
128129
} else {
129-
let initialCondition = searchTermsGroup === SEARCH_TERMS_GROUP_LIMIT_BY
130-
|| searchTermsGroup === SEARCH_TERMS_GROUP_SEARCH_TERMS
131-
? preferredConditionNew : preferredCondition;
132-
133-
if (!initialCondition) {
134-
initialCondition = searchTermsGroup === SEARCH_TERMS_GROUP_LIMIT_BY
135-
? null
136-
: Immutable.fromJS(
137-
get(config, ['recordTypes', recordType, 'advancedSearch']),
138-
);
130+
const isNewSearchForm = searchTermsGroup === SEARCH_TERMS_GROUP_LIMIT_BY
131+
|| searchTermsGroup === SEARCH_TERMS_GROUP_SEARCH_TERMS;
132+
133+
// use preferred condition when not using new search form
134+
// or for both new "search terms, limit by" groups when recordType is not collectionobject
135+
if (isNewSearchForm && recordType !== 'collectionobject') {
136+
initialCondition = preferredConditionNew;
137+
} else if (!isNewSearchForm) {
138+
initialCondition = preferredCondition;
139+
} else {
140+
initialCondition = null;
141+
}
142+
143+
// use config condition when there is no preferred condition
144+
// and not using new search form or for new search terms group
145+
// when recordType is not collectionobject
146+
if (
147+
!initialCondition && (
148+
!isNewSearchForm
149+
|| (searchTermsGroup === SEARCH_TERMS_GROUP_SEARCH_TERMS && recordType !== 'collectionobject')
150+
)
151+
) {
152+
initialCondition = Immutable.fromJS(
153+
get(config, ['recordTypes', recordType, 'advancedSearch']),
154+
);
139155
}
140156

141157
normalizedCondition = ensureRootBooleanOp(initialCondition, preferredBooleanOp);

src/components/search/SearchFormContentNew.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ const SearchFormContentNew = ({
7878
</div>
7979
<ConnectedPanel
8080
collapsible
81-
collapsed={!newSearchShown}
8281
name="searchTermsPanel"
8382
header={<h3>{intl.formatMessage(messages.enterSearchTerms)}</h3>}
8483
>
@@ -104,7 +103,6 @@ const SearchFormContentNew = ({
104103
<div className={styles.mb12}><b>{intl.formatMessage(messages.and)}</b></div>
105104
<ConnectedPanel
106105
collapsible
107-
collapsed={!newSearchShown}
108106
name="limitByPanel"
109107
header={<h3>{intl.formatMessage(messages.limitBySpecificFields)}</h3>}
110108
>

test/specs/components/search/AdvancedSearchBuilder.spec.jsx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import {
2222
OP_GT,
2323
OP_RANGE,
2424
} from '../../../../src/constants/searchOperators';
25+
import {
26+
SEARCH_TERMS_GROUP_SEARCH_TERMS,
27+
} from '../../../../src/constants/searchNames';
2528

2629
chai.use(chaiImmutable);
2730
chai.should();
@@ -129,6 +132,17 @@ const config = {
129132
},
130133
},
131134
},
135+
all: {
136+
advancedSearch: {
137+
op: OP_OR,
138+
value: [
139+
{
140+
op: OP_EQ,
141+
path: 'ns2:collectionobjects_common/objectNumber',
142+
},
143+
],
144+
},
145+
},
132146
},
133147
};
134148

@@ -340,6 +354,65 @@ describe('AdvancedSearchBuilder', () => {
340354
}));
341355
});
342356

357+
it('should normalize an undefined condition to an empty condition for search terms group when recordType is collectionobject', function test() {
358+
let committedCondition = null;
359+
360+
const handleConditionCommit = (conditionArg) => {
361+
committedCondition = conditionArg;
362+
};
363+
364+
render(
365+
<IntlProvider locale="en">
366+
<ConfigProvider config={config}>
367+
<StoreProvider store={store}>
368+
<AdvancedSearchBuilder
369+
config={config}
370+
recordType="collectionobject"
371+
searchTermsGroup={SEARCH_TERMS_GROUP_SEARCH_TERMS}
372+
onConditionCommit={handleConditionCommit}
373+
/>
374+
</StoreProvider>
375+
</ConfigProvider>
376+
</IntlProvider>, this.container,
377+
);
378+
379+
committedCondition.should
380+
.equal(
381+
Immutable.fromJS({
382+
op: OP_OR,
383+
value: [],
384+
}),
385+
);
386+
});
387+
388+
it('should normalize an undefined condition to the default condition for search terms group when recordType is not collectionobject', function test() {
389+
let committedCondition = null;
390+
391+
const handleConditionCommit = (conditionArg) => {
392+
committedCondition = conditionArg;
393+
};
394+
395+
render(
396+
<IntlProvider locale="en">
397+
<ConfigProvider config={config}>
398+
<StoreProvider store={store}>
399+
<AdvancedSearchBuilder
400+
config={config}
401+
recordType="all"
402+
searchTermsGroup={SEARCH_TERMS_GROUP_SEARCH_TERMS}
403+
onConditionCommit={handleConditionCommit}
404+
/>
405+
</StoreProvider>
406+
</ConfigProvider>
407+
</IntlProvider>, this.container,
408+
);
409+
410+
committedCondition.should
411+
.equal(
412+
Immutable.fromJS(config.recordTypes.all.advancedSearch),
413+
);
414+
});
415+
343416
it('should render a field condition as a FieldConditionInput if onConditionCommit is not supplied', function test() {
344417
const condition = Immutable.fromJS({
345418
op: OP_EQ,

0 commit comments

Comments
 (0)