Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Filter objects UI #489

Merged
merged 23 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/state/network/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@ export function makeApiRequest(requestId, root, endpoint, options = {}) {
const api = new APIClient(root, accessToken);
const request = getRequest(state, requestId);

// A "stealth API request" is one that doesn't update the state.
// This is useful when you generally "don't care" about the *state* of the request.
const stealth = options.stealth || false;
if (stealth) {
// Doing it this way because JavaScript doesn't have a `obj.pop(key, default)`
delete options.stealth;
}

if (request.inProgress) {
return true;
}

dispatch({
type: REQUEST_SEND,
requestId,
});
!stealth &&
Copy link
Contributor

@mythmon mythmon Oct 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write this as if (!stealth) { ... } instead? && version is useful when you need an expression, but we don't need an expression here.

Also, do we need/want to disable the REQUEST_SUCCESS/REQUEST_FAILURE? events when stealth is true as well?

dispatch({
type: REQUEST_SEND,
requestId,
});

let data;

Expand Down
13 changes: 9 additions & 4 deletions src/state/recipes/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,16 @@ export function fetchRecipeFilters() {
filters: JSON.parse(localFilters),
});
}
// XXX If we already had the filters in localStorage, can we avoid using this
// makeNormandyApiRequest() with an ID so that it doesn't cause any spinners to appear
// when the localStorage version almost definitely is good enough.

const options = {};
// If we already had the filters in localStorage, we can make a "stealth API request"
// which is the same as a regular request except it doesn't update the global state
// that there's a request we're waiting for.
if (localFilters) {
options.stealth = true;
}
const requestId = 'fetch-recipe-filters';
const filters = await dispatch(makeNormandyApiRequest(requestId, 'v3/filters/'));
const filters = await dispatch(makeNormandyApiRequest(requestId, 'v3/filters/', options));
// After it has been retrieved remotely, it's very possible that the lists
// haven't changed. If it hasn't changed compared to what we had in local Storage, then
// don't bother dispatching again.
Expand Down