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

Implement basic loading component #423

Merged
merged 22 commits into from
Jul 7, 2016
Merged

Implement basic loading component #423

merged 22 commits into from
Jul 7, 2016

Conversation

jeremiak
Copy link
Contributor

@jeremiak jeremiak commented Jul 2, 2016

Changes the stores to have a .fetching attribute, which will be a boolean. How the stores implement the toggling of this value is up to each individual store. Then the components can check for requests that are currently in flight and use the <Loading /> component to display a standardized loading message.

We still need to design the loading component, as it is pretty stark right now but it is a first pass.

Refs #383

@jeremiak jeremiak force-pushed the jk-loading-state branch 2 times, most recently from 0462f16 to 8d5b58e Compare July 6, 2016 14:16
@jeremiak jeremiak changed the title [WIP] Implement basic loading component Implement basic loading component Jul 6, 2016
@jeremiak
Copy link
Contributor Author

jeremiak commented Jul 6, 2016

This is ready for review @msecret

@coveralls
Copy link

Coverage Status

Coverage remained the same at 70.958% when pulling 8d5b58e on jk-loading-state into f379557 on master.

@jcscottiii
Copy link
Contributor

jcscottiii commented Jul 6, 2016

@jeremiak This might be more for another PR / I'm missing something but I'm wondering does this account for a certain model type (e.g. users) doing multiple fetching at the same time on the page. I'm sure it doesn't happen now but just in case it happens in the future. I'm wondering if fetching will get flipped before all the loading is done for a particular store.

@jeremiak
Copy link
Contributor Author

jeremiak commented Jul 6, 2016

@jcscottiii it is a great point. Just to clarify, you're saying that if:

  • Request A is made and fetching is set to true
  • Request B is made and fetching is set to true, which means it doesn’t change
  • Request A comes back and changes fetching to false and therefore the store is fetching false but there is still a request in flight

Therefore, the store is actually waiting for a request but it's fetching value doesn't reflect that. This is definitely a problem with this design/implementation. I was trying to keep the mechanism really simple and made that tradeoff. I haven't seen it be a problem with any of the stores yet, but it could just be that my network connection has worked.

Even if we were to keep track of each request going out, it would still be hard to know if every request an interface needed had come back with fresh data or if it was stale. Thoughts on how we might want to do this otherwise?

@jcscottiii
Copy link
Contributor

let me think of it this way:

# single store emits requests all while rendering a single fetch 
requests (1..N) <- single store (contains) single fetching <-> render single loading state

instead let's do it this way make the fetching as part of the component instead of the store. thoughts @msecret @jeremiak ?

@msecret
Copy link
Contributor

msecret commented Jul 6, 2016

According to our design, only the store can keep state, such as fetching. But the components can be listening to the store.

@jcscottiii
Copy link
Contributor

@msecret ahh yeah. hmmm. so could each component get a way to know that the store is changing it's particular fetching state?

@msecret
Copy link
Contributor

msecret commented Jul 6, 2016

Yea I mean, we coudl keep fetching in the stores but separate different fetching out more so each fetching is more specific? Then components could be more specific about what fetching they're waiting for?

@jcscottiii
Copy link
Contributor

@msecret i got ya!

@msecret
Copy link
Contributor

msecret commented Jul 6, 2016

If this works, we should use it for the time being, and get these merge conflicts fixed. @jcscottiii if you're interested in taking a look at improving the fetching tracking in the next few days as we just discussed, you definitely should, I think it could be a good improvement.

Jeremia Kimelman added 16 commits July 6, 2016 22:08
This is a potential implementation for loading states. Adds a fetching
attribute to the base store, which should always be a boolean value.

Includes basic tests
Right now, it is hard to use a single `fetching` value on the store
because a store might have a few different requests that have to be
received before the full state can be constructed. For example, on the
app page we need to not only get the app but also the app states and
routes. If we only have one attribute on the store, then it is hard to
time when the attribute gets set to false or true
assertAction() was not checking anything about the “type” variable,
which means that if it was undefined the tests would pass.
Add event constant types to represent when we have multiple requests in
flight for an app’s information and when they’ve all come back. We want
to keep these in one action so that we can ensure that `.fetching` will
be set appropriately on the AppStore.
We have two new action types to help us coordinate when we have
multiple requests in flight. We want to know when all the requests have
been made and when the responses have come back so we can set the
`.fetching` attribute on the store appropriately. This will be used for
showing loading states in the UI.
All actions are dispatched by action creators, so we need two new
action creators to represent our two new appActionTypes.
Added a new function to the cfApi helper library called `fetchAllApp`,
which takes an app guid. It then calls the `fetchApp` and the
`fetchAppStats` functions, and once both promises have resolved, it
calls the `receivedAppAll` app action.
Instead of making two individual requests for the app and the app
stats, we’ll use the fetchAll app action creator to set the `fetching`
value of AppStore to `true`, initiate the HTTP requests and then switch
`fetching` back to `false` once both promises have resolved.
This component is to be used as a loading component, and takes a text
prop and displays it.
Use the <Loading /> component in the <AppPage /> to display some basic
loading text while the requests are being made. This will allow us to
have a display for the following states:
* Fetch in progress
* Fetch returned with no results
* Fetch returned with results
Changes the OrgStore so that the `.fetching` attribute is set
appropriately.
Set the fetching attribute on the SpaceStore depending on the action
type.

Modifies the tests to properly test the behavior, while relying on the
BaseStore specs to test the inherited function behavior
Use a spaceAction to trigger the cfApi.fetchSpace call so that the
store can be notified of a request being made and update the fetching
attribute appropriately.
Leverage the Loading component in the AppList component so that the
user can understand if there are no apps, the requests are inflight, or
if the request has already come back.
Set value of `.fetching` in UserStore depending on which action types.

Adjust tests to pass and make sure the new behavior is tested.
Show loading component when looking at the Users in a space
Jeremia Kimelman added 6 commits July 6, 2016 22:16
Adds behavior to set `.fetching` on the ServiceInstanceStore depending
on the serviceAction type.

Change tests to test this new behavior
Add the loading component to the service instance list so that users
can have a better understanding if the app is:
1. Requesting data from the server
2. Has received data from the server
3. There are no services in the space
* Sets fetching to true on SERVICES_FETCH
* Sets fetching to false on SERVICES_RECEIVED

Change tests to capture this behavior
To ensure that the stores set their respective `.fetching` value
appropriately, we should use actions to trigger API requests instead of
calling the API directly
The marketplace component relies on four different stores, so it will
show the loading component if any of them are currently fetching data
from the server.
@jeremiak
Copy link
Contributor Author

jeremiak commented Jul 7, 2016

@msecret @jcscottiii I fixed the merge conflicts so this should be ready for review now

@coveralls
Copy link

Coverage Status

Coverage remained the same at 70.958% when pulling 5bf0872 on jk-loading-state into 4c2ff46 on master.

@msecret msecret merged commit d3347dc into master Jul 7, 2016

import React from 'react';

const propTypes = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you defined these into separate variables rather then directly like other components:

Loading.proptTypes = {
  text
  ...

Is this a better pattern we should adopt?

@jeremiak jeremiak deleted the jk-loading-state branch July 19, 2016 20:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants