Skip to content

Commit

Permalink
NGSTACK-346 dispatch search fetch when section changed
Browse files Browse the repository at this point in the history
  • Loading branch information
joezg committed Feb 10, 2020
1 parent 39e3caa commit ece3c3c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
18 changes: 18 additions & 0 deletions cypress/integration/browser_test.js
Expand Up @@ -230,6 +230,24 @@ describe('Multiple browse test', function() {
cy.get(withCyTag('search-panel')).find('select').find(':selected').contains("Users");
cy.window().its('store').invoke('getState').its('app').its('sectionId').should('eq', 1);
});
it('perfoms search when category is changed', () => {
cy.visit('/');
cy.openContentBrowser();
cy.get(withCyTag('tabs')).contains('Search').should('be.visible').click();

cy.get(withCyTag('search-form')).as('form').find('input').as('input').type('test');
cy.get('@form').submit();

cy.get(withCyTag('items-table')).should('be.visible').find('tbody').children().first().contains('Test');

cy.get(withCyTag('search-panel')).find('select').first().select('Users');
cy.get(withCyTag('items-table')).should('be.visible').find('tbody').children().first().contains('User');

cy.get(withCyTag('search-form')).as('form').find('input').as('input').clear();
cy.get(withCyTag('search-panel')).find('select').first().select('Home');
cy.get(withCyTag('items-table')).should('be.visible').find('tbody').children().first().contains('User');

});
});
describe('Closes content browser', () => {
it('clicks on Cancel in footer and closes content browser', () => {
Expand Down
3 changes: 2 additions & 1 deletion express/helpers.js
Expand Up @@ -101,9 +101,10 @@ const getPreview = (req) => {
}

const getSearchResults = (req) => {
const parentLocation = parseInt(req.query.sectionId, 10);
let children = [];
if (req.query.searchText.length > 2) items.forEach(item => {
if (children.length < 12) {
if (children.length < 12 && item.parent_id === parentLocation) {
const newItem = {...item};
delete newItem.id;
delete newItem.parent_id;
Expand Down
10 changes: 9 additions & 1 deletion src/components/Search.js
Expand Up @@ -11,12 +11,20 @@ function Search(props) {
props.fetchItems();
};

const handleSectionChange = id => {
props.setSectionId(id);

if (props.searchTerm){
props.fetchItems()
}
}

return (
<>
<div className={S.searchPanel}>
<Select
options={props.sections.map(section => ({value: section.id, label: section.name}))}
onChange={props.setSectionId}
onChange={handleSectionChange}
value={props.id.toString()}
/>
<div className={S.searchWrapper}>
Expand Down

0 comments on commit ece3c3c

Please sign in to comment.