-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(saved-search): Create saved search store (#12729)
Update saved search store whenever a saved search is fetched. Data from this store will be used in various saved search components in future.
- Loading branch information
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Reflux from 'reflux'; | ||
|
||
export default Reflux.createActions(['loadSavedSearches', 'updateSavedSearches']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Reflux from 'reflux'; | ||
|
||
import SavedSearchActions from 'app/actions/savedSearchActions'; | ||
|
||
const SavedSearchesStore = Reflux.createStore({ | ||
init() { | ||
this.reset(); | ||
this.listenTo(SavedSearchActions.loadSavedSearches, this.onLoadSavedSearches); | ||
this.listenTo(SavedSearchActions.updateSavedSearches, this.onUpdateSavedSearches); | ||
}, | ||
|
||
reset() { | ||
this.state = { | ||
isLoading: true, | ||
savedSearches: [], | ||
}; | ||
}, | ||
|
||
get() { | ||
return this.state; | ||
}, | ||
|
||
onLoadSavedSearches() { | ||
this.reset(); | ||
this.trigger(this.state); | ||
}, | ||
|
||
onUpdateSavedSearches(savedSearches) { | ||
this.state = { | ||
isLoading: false, | ||
savedSearches, | ||
}; | ||
this.trigger(this.state); | ||
}, | ||
}); | ||
|
||
export default SavedSearchesStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import SavedSearchStore from 'app/stores/savedSearchStore'; | ||
import {fetchSavedSearches} from 'app/actionCreators/savedSearches'; | ||
import {Client} from 'app/api'; | ||
|
||
describe('SavedSearchStore', function() { | ||
beforeEach(function() { | ||
Client.addMockResponse({ | ||
url: '/organizations/org-1/searches/', | ||
body: TestStubs.Searches(), | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
Client.clearMockResponses(); | ||
}); | ||
|
||
it('get', function() { | ||
expect(SavedSearchStore.get()).toEqual({isLoading: true, savedSearches: []}); | ||
}); | ||
|
||
it('fetching saved searches updates store', async function() { | ||
const api = new Client(); | ||
fetchSavedSearches(api, 'org-1'); | ||
await tick(); | ||
expect(SavedSearchStore.get().savedSearches).toHaveLength(2); | ||
expect(SavedSearchStore.get().isLoading).toBe(false); | ||
}); | ||
}); |