[ARVADOS-WORKBENCH2] created: 1.2.0-674-gaca5731
Git user
git at public.curoverse.com
Tue Oct 16 07:52:27 EDT 2018
at aca5731485b1a79ee2305e08fd198950c7a34b42 (commit)
commit aca5731485b1a79ee2305e08fd198950c7a34b42
Author: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
Date: Tue Oct 16 13:52:10 2018 +0200
editing saved queries
Feature #14277
Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
diff --git a/src/services/search-service/search-service.ts b/src/services/search-service/search-service.ts
index 8a41fbc..5817275 100644
--- a/src/services/search-service/search-service.ts
+++ b/src/services/search-service/search-service.ts
@@ -27,6 +27,12 @@ export class SearchService {
localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries));
}
+ editSavedQueries(data: SearchBarAdvanceFormData) {
+ const itemIndex = this.savedQueries.findIndex(item => item.searchQuery === data.searchQuery);
+ this.savedQueries[itemIndex] = {...data};
+ localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries));
+ }
+
getSavedQueries() {
return JSON.parse(localStorage.getItem('savedQueries') || '[]') as SearchBarAdvanceFormData[];
}
diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts
index 9ddfc9c..e73db64 100644
--- a/src/store/search-bar/search-bar-actions.ts
+++ b/src/store/search-bar/search-bar-actions.ts
@@ -24,7 +24,8 @@ export const searchBarActions = unionize({
CLOSE_SEARCH_VIEW: ofType<{}>(),
SET_SEARCH_RESULTS: ofType<GroupContentsResource[]>(),
SET_SEARCH_VALUE: ofType<string>(),
- SET_SAVED_QUERIES: ofType<SearchBarAdvanceFormData[]>()
+ SET_SAVED_QUERIES: ofType<SearchBarAdvanceFormData[]>(),
+ UPDATE_SAVED_QUERY: ofType<SearchBarAdvanceFormData[]>()
});
export type SearchBarActions = UnionOf<typeof searchBarActions>;
@@ -46,13 +47,24 @@ export const loadRecentQueries = () =>
return recentSearchQueries || [];
};
+ // Todo: create ids for particular searchQuery
export const saveQuery = (data: SearchBarAdvanceFormData) =>
(dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ const savedSearchQueries = services.searchService.getSavedQueries();
+ const filteredQuery = savedSearchQueries.find(query => query.searchQuery === data.searchQuery);
if (data.saveQuery && data.searchQuery) {
- services.searchService.saveQuery(data);
- dispatch(searchBarActions.SET_SAVED_QUERIES(services.searchService.getSavedQueries()));
- dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Query has been sucessfully saved', kind: SnackbarKind.SUCCESS }));
+ if (filteredQuery) {
+ services.searchService.editSavedQueries(data);
+ dispatch(searchBarActions.UPDATE_SAVED_QUERY(savedSearchQueries));
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Query has been sucessfully updated', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
+ } else {
+ services.searchService.saveQuery(data);
+ dispatch(searchBarActions.SET_SAVED_QUERIES(savedSearchQueries));
+ dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Query has been sucessfully saved', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
+ }
}
+ dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.BASIC));
+ dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
};
export const deleteSavedQuery = (id: number) =>
@@ -63,9 +75,10 @@ export const deleteSavedQuery = (id: number) =>
return savedSearchQueries || [];
};
-export const editSavedQuery = (data: SearchBarAdvanceFormData, id: number) =>
+export const editSavedQuery = (data: SearchBarAdvanceFormData) =>
(dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
dispatch(searchBarActions.SET_CURRENT_VIEW(SearchView.ADVANCED));
+ dispatch(searchBarActions.SET_SEARCH_VALUE(data.searchQuery));
dispatch<any>(initialize(SEARCH_BAR_ADVANCE_FORM_NAME, data));
};
@@ -121,17 +134,17 @@ export const getFilters = (filterName: string, searchValue: string): string => {
.getFilters();
};
-export const initAdvanceFormProjectsTree = () =>
+export const initAdvanceFormProjectsTree = () =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
dispatch<any>(initUserProject(SEARCH_BAR_ADVANCE_FORM_PICKER_ID));
};
-export const changeAdvanceFormProperty = (property: string, value: PropertyValues[] | string = '') =>
+export const changeAdvanceFormProperty = (property: string, value: PropertyValues[] | string = '') =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
dispatch(change(SEARCH_BAR_ADVANCE_FORM_NAME, property, value));
};
-export const updateAdvanceFormProperties = (propertyValues: PropertyValues) =>
+export const updateAdvanceFormProperties = (propertyValues: PropertyValues) =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
dispatch(arrayPush(SEARCH_BAR_ADVANCE_FORM_NAME, 'properties', propertyValues));
};
\ No newline at end of file
diff --git a/src/store/search-bar/search-bar-reducer.ts b/src/store/search-bar/search-bar-reducer.ts
index a956043..e7e3517 100644
--- a/src/store/search-bar/search-bar-reducer.ts
+++ b/src/store/search-bar/search-bar-reducer.ts
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: AGPL-3.0
-import { searchBarActions, SearchBarActions } from '~/store/search-bar/search-bar-actions';
+import { searchBarActions, SearchBarActions, saveQuery } from '~/store/search-bar/search-bar-actions';
import { GroupContentsResource } from '~/services/groups-service/groups-service';
import { SearchBarAdvanceFormData } from '~/models/search-bar';
@@ -36,5 +36,6 @@ export const searchBarReducer = (state = initialState, action: SearchBarActions)
SET_SEARCH_RESULTS: (searchResults) => ({ ...state, searchResults }),
SET_SEARCH_VALUE: (searchValue) => ({ ...state, searchValue }),
SET_SAVED_QUERIES: savedQueries => ({ ...state, savedQueries }),
+ UPDATE_SAVED_QUERY: searchQuery => ({ ...state, savedQueries: searchQuery }),
default: () => state
});
\ No newline at end of file
diff --git a/src/views-components/search-bar/search-bar.tsx b/src/views-components/search-bar/search-bar.tsx
index 9eae717..2d487e0 100644
--- a/src/views-components/search-bar/search-bar.tsx
+++ b/src/views-components/search-bar/search-bar.tsx
@@ -40,7 +40,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
deleteSavedQuery: (id: number) => dispatch<any>(deleteSavedQuery(id)),
openSearchView: () => dispatch<any>(openSearchView()),
navigateTo: (uuid: string) => dispatch<any>(navigateToItem(uuid)),
- editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => dispatch<any>(editSavedQuery(data, id))
+ editSavedQuery: (data: SearchBarAdvanceFormData) => dispatch<any>(editSavedQuery(data))
});
export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);
\ No newline at end of file
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list