From b1b510be3d78daa8a37c4e058fa573a99ea62f2c Mon Sep 17 00:00:00 2001 From: Yarin Dekel Date: Sun, 4 Nov 2018 15:10:26 +0200 Subject: cache search result workflow Issue-ID: SDC-1889 Change-Id: I4a29b9954d3ce50ea9745e8aa8996f46f12501f1 Signed-off-by: Yarin Dekel --- .../main/frontend/src/features/catalog/Catalog.js | 5 ++--- .../frontend/src/features/catalog/CatalogView.jsx | 24 +++++++++------------- .../catalog/__tests__/catalogActions-test.js | 13 +----------- .../catalog/__tests__/catalogReducer-test.js | 8 +------- .../src/features/catalog/catalogActions.js | 5 ++--- .../src/features/catalog/catalogReducer.js | 17 +++++++-------- 6 files changed, 23 insertions(+), 49 deletions(-) (limited to 'workflow-designer-ui') diff --git a/workflow-designer-ui/src/main/frontend/src/features/catalog/Catalog.js b/workflow-designer-ui/src/main/frontend/src/features/catalog/Catalog.js index a7ddd147..867aeebd 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/catalog/Catalog.js +++ b/workflow-designer-ui/src/main/frontend/src/features/catalog/Catalog.js @@ -19,7 +19,6 @@ import { connect } from 'react-redux'; import CatalogView from 'features/catalog/CatalogView'; import { fetchWorkflow, - resetWorkflow, searchChangedAction } from 'features/catalog/catalogActions'; @@ -28,13 +27,13 @@ import { NEW_WORKFLOW_MODAL } from 'shared/modal/modalWrapperComponents'; import { clearWorkflowAction } from 'features/workflow/workflowConstants'; const mapStateToProps = state => ({ - catalog: state.catalog + catalog: state.catalog, + searchNameFilter: state.searchNameFilter }); const mapDispatchToProps = dispatch => ({ handleFetchWorkflow: (sort, offset, searchNameFilter) => dispatch(fetchWorkflow(sort, offset, searchNameFilter)), - handleResetWorkflow: () => dispatch(resetWorkflow()), clearWorkflow: () => dispatch(clearWorkflowAction), showNewWorkflowModal: () => dispatch( diff --git a/workflow-designer-ui/src/main/frontend/src/features/catalog/CatalogView.jsx b/workflow-designer-ui/src/main/frontend/src/features/catalog/CatalogView.jsx index 4fdcc786..3f002523 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/catalog/CatalogView.jsx +++ b/workflow-designer-ui/src/main/frontend/src/features/catalog/CatalogView.jsx @@ -27,9 +27,6 @@ import { NAME, ASC, DESC } from 'features/catalog/catalogConstants'; class CatalogView extends Component { constructor(props) { super(props); - this.state = { - searchValue: '' - }; } componentDidMount() { @@ -38,34 +35,31 @@ class CatalogView extends Component { clearWorkflow(); } - componentWillUnmount() { - this.props.handleResetWorkflow(); - } - handleAlphabeticalOrderByClick = e => { e.preventDefault(); const { handleFetchWorkflow, - catalog: { sort } + catalog: { sort, searchNameFilter } } = this.props; const payload = { ...sort }; payload[NAME] = payload[NAME] === ASC ? DESC : ASC; - handleFetchWorkflow(payload, undefined, this.state.searchValue); + handleFetchWorkflow(payload, undefined, searchNameFilter); }; handleScroll = () => { const { catalog: { paging: { offset }, - sort + sort, + searchNameFilter }, handleFetchWorkflow } = this.props; - handleFetchWorkflow(sort, offset, this.state.searchValue); + handleFetchWorkflow(sort, offset, searchNameFilter); }; goToOverviewPage = id => { @@ -91,7 +85,8 @@ class CatalogView extends Component { const { sort, paging: { hasMore, total }, - items + items, + searchNameFilter } = catalog; const alphabeticalOrder = sort[NAME]; @@ -99,7 +94,7 @@ class CatalogView extends Component {
{ it('should have `fetchWorkflow` action', () => { @@ -65,10 +60,4 @@ describe('Catalog Actions', () => { payload }); }); - - it('should have `resetWorkflow` action', () => { - expect(resetWorkflow()).toEqual({ - type: RESET_WORKFLOW - }); - }); }); diff --git a/workflow-designer-ui/src/main/frontend/src/features/catalog/__tests__/catalogReducer-test.js b/workflow-designer-ui/src/main/frontend/src/features/catalog/__tests__/catalogReducer-test.js index 5444bf94..b31aa2ea 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/catalog/__tests__/catalogReducer-test.js +++ b/workflow-designer-ui/src/main/frontend/src/features/catalog/__tests__/catalogReducer-test.js @@ -18,7 +18,7 @@ import { NAME, ASC, DESC } from 'features/catalog/catalogConstants'; import catalogReducer, { initialState } from 'features/catalog/catalogReducer'; -import { updateWorkflow, resetWorkflow } from 'features/catalog/catalogActions'; +import { updateWorkflow } from 'features/catalog/catalogActions'; describe('Catalog Reducer', () => { const state = { @@ -107,10 +107,4 @@ describe('Catalog Reducer', () => { ); }); - it('should reset state', () => { - expect(catalogReducer({ ...state, sort }, resetWorkflow())).toEqual({ - ...initialState, - sort - }); - }); }); diff --git a/workflow-designer-ui/src/main/frontend/src/features/catalog/catalogActions.js b/workflow-designer-ui/src/main/frontend/src/features/catalog/catalogActions.js index 6262da0d..f2cb0435 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/catalog/catalogActions.js +++ b/workflow-designer-ui/src/main/frontend/src/features/catalog/catalogActions.js @@ -24,11 +24,10 @@ import { } from 'features/catalog/catalogConstants'; export const { - [NAMESPACE]: { updateWorkflow, resetWorkflow } + [NAMESPACE]: { updateWorkflow } } = createActions({ [NAMESPACE]: { - UPDATE_WORKFLOW: undefined, - RESET_WORKFLOW: undefined + UPDATE_WORKFLOW: undefined } }); diff --git a/workflow-designer-ui/src/main/frontend/src/features/catalog/catalogReducer.js b/workflow-designer-ui/src/main/frontend/src/features/catalog/catalogReducer.js index 78d8e529..e5f887b6 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/catalog/catalogReducer.js +++ b/workflow-designer-ui/src/main/frontend/src/features/catalog/catalogReducer.js @@ -14,12 +14,8 @@ * limitations under the License. */ -import { - NAME, - ASC, - UPDATE_WORKFLOW, - RESET_WORKFLOW -} from 'features/catalog/catalogConstants'; +import { NAME, ASC, UPDATE_WORKFLOW } from 'features/catalog/catalogConstants'; +import { SEARCH_CHANGED } from './catalogConstants'; export const initialState = { paging: { @@ -35,9 +31,6 @@ const catalogReducer = (state = initialState, action) => { const { type, payload } = action; switch (type) { - case RESET_WORKFLOW: - return { ...initialState, sort: state.sort }; - case UPDATE_WORKFLOW: return { ...state, @@ -47,7 +40,11 @@ const catalogReducer = (state = initialState, action) => { ? [...payload.items] : [...state.items, ...payload.items] }; - + case SEARCH_CHANGED: + return { + ...state, + searchNameFilter: action.payload.searchNameFilter + }; default: return state; } -- cgit 1.2.3-korg