Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(release): Resource & Entity loader/reader components #21

Merged
merged 10 commits into from
Apr 30, 2018

Conversation

orther
Copy link
Member

@orther orther commented Apr 29, 2018

Loader Components

These components request resources and return the results. If an entityType is provide that matches a schema that is defined for the entities redux-module it will normalize the resource.

ResourceDetailLoader

<ResourceDetailLoader
  resource={'user'}
  resourceId={1}
  renderInitial={() => <div>Initial</div>}
  renderError={error => <div>{error}</div>}
  renderLoading={() => <div>Loading...</div> />}
  renderSuccess={user => <div>{user.id}:{user.name}</div>}
  loadOnMount
>
  {({statusView, onEventLoadResource}) => (
    <div>
      <div>
        <button onClick={onEventLoadResource}>
          Reload Resource
        </button>
      </div>
      {statusView}
    </div>
  )}
</ResourceDetailLoader>

ResourceListLoader

<ResourceListLoader
  resource={'user'}
  renderInitial={() => <div>Initial</div>}
  renderError={error => <div>{error}</div>}
  renderLoading={() => <div>Loading...</div> />}
  renderSuccess={userList => (
    <div>
      {userList.map(user => (
        <div key={user.id}>
          {user.id}:{user.name}
        </div>
      ))}
    </div>
  )}
  loadOnMount
>
  {({statusView, onEventLoadResource}) => (
    <div>
      <div>
        <button onClick={onEventLoadResource}>
          Reload Resource
        </button>
      </div>
      {statusView}
    </div>
  )}
</ResourceListLoader>

Reader Components

These components "read" data from the entity state in the global redux store and return the matching entity.

EntityDetail

<EntityDetail entityType="member" entityId={123}>
  {member => <h1 key={member.id}>{member.name}</h1>}
</EntityDetail>

EntityList

<EntityList entityType="member" entityIds={[1,2,3]}>
  {memberList => <p key={member.id}>{member.name}</p>)}
</EntityDetail>

Currently the API lib we use uses `data` as the key in the response object that
holds the response body from the API. Our backend APIs use the key `data` in the
response JSON to hold the actual data requested. This results in the response
data being accessed from by the (odd looking) `response.data.data`. This updates
the resource sagas to correctly extract the data. Before this fix results were
handed back wrapped in object like: `{data: <actual data here>}`
Exposed through: createResourceHelper
@orther
Copy link
Member Author

orther commented Apr 29, 2018

Closes #19

@orther orther changed the title feat(release): Resource & Entity loader/reader components WIP feat(release): Resource & Entity loader/reader components Apr 30, 2018
@orther orther changed the title WIP feat(release): Resource & Entity loader/reader components WIP - feat(release): Resource & Entity loader/reader components Apr 30, 2018
@orther orther changed the title WIP - feat(release): Resource & Entity loader/reader components feat(release): Resource & Entity loader/reader components Apr 30, 2018
@orther orther merged commit 4dceb0a into master Apr 30, 2018
@orther orther deleted the resource-loader-component branch April 30, 2018 23:10
@codecov
Copy link

codecov bot commented Apr 30, 2018

Codecov Report

Merging #21 into master will decrease coverage by 5.44%.
The diff coverage is 69.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #21      +/-   ##
==========================================
- Coverage   93.07%   87.62%   -5.45%     
==========================================
  Files          14       21       +7     
  Lines         231      299      +68     
  Branches       21       34      +13     
==========================================
+ Hits          215      262      +47     
- Misses         16       36      +20     
- Partials        0        1       +1
Impacted Files Coverage Δ
src/modules/resource/sagas.js 82.92% <ø> (ø) ⬆️
src/helpers/entities/components/EntityList.js 0% <0%> (ø)
src/helpers/entities/components/EntityDetail.js 0% <0%> (ø)
src/helpers/entities/index.js 0% <0%> (ø)
src/utils/test/api.js 100% <100%> (ø)
.../helpers/resource/components/ResourceListLoader.js 100% <100%> (ø)
src/helpers/resource/index.js 100% <100%> (ø)
...elpers/resource/components/ResourceDetailLoader.js 66.66% <66.66%> (ø)
src/helpers/resource/components/ResourceLoader.js 83.33% <83.33%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b83c7b...afb8bb2. Read the comment docs.

@orther orther mentioned this pull request Apr 30, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant