Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Support viewing older requests #751

Merged
merged 7 commits into from
Feb 20, 2018

Conversation

cdosborn
Copy link
Contributor

@cdosborn cdosborn commented Jan 24, 2018

Description

Depends on:

Problem: No way to view older requests.

Features:

  • All resource requests are listed (not just pending ones) (we only fetch first 1000)
    • If the url refers to a model outside the 1000, we fetch it individually
  • Requests that have been approved/denied/closed present an overlay over the Update Resources section, so that admins don't unintentionally update processed requests
  • Each request includes a created field and status field now

support-older-requests

Checklist before merging Pull Requests

  • New test(s) included to reproduce the bug/verify the feature
  • Documentation created/updated at Example link to documentation to give context to the feature
  • Reviewed and approved by at least one other contributor.
  • New variables supported in Clank
  • New variables committed to secrets repos

For collections of models we support `fetchModels` and `getAll`, for individual
models we have `fetchModel` and `get`. However the latter methods don't work
like you might hope.

Problem: 1
If you call `get(modelId)` that checks if the model exists and then fetches the
first page of the models from the server. If `modelId` isn't in the first page,
then `get` won't work.

Problem: 2
`fetchModel` actually fetches the modelId from the server, so theres no concern
about pagination, but it sticks its result `this.models`. If this.models
doesn't exist, then you'll get a runtime error. So `fetchModel` only works if
you implicitly have called `getAll` or `fetchModels` first. Not nice.

Solution to: 1
I created a `getModel` analog to `get` which actually fetches the model. I
couldn't replace `get` because the current behavior is used in many places.

Solution to: 2
I fixed `fetchedModels` in a backwards compatible way to prevent the runtime
error. When it fetches a model it adds it to the model cache (like it used to)
and it adds it to `this.fetchedModels`, which is a cache for model instances.
This fixes the implicit need to call store.getAll() as mentioned.
There are a few caveats, I'll comment on the diff of this commit

When a resource request gets updated to approved/closed/denied, we no longer
remove it from the store, we show all requests of all status types now

    diff --git a/troposphere/static/js/actions/AdminResourceRequestActions.js b/troposphere/static/js/actions/AdminResourceRequestActions.js
    index 10dc13abd..f31263844 100644
    --- a/troposphere/static/js/actions/AdminResourceRequestActions.js
    +++ b/troposphere/static/js/actions/AdminResourceRequestActions.js
    @@ -14,9 +14,6 @@ export default {
                     Utils.dispatch(AdminResourceConstants.UPDATE, {
                         model: request
                     });
    -                Utils.dispatch(AdminResourceConstants.REMOVE, {
    -                    model: request
    -                });
                 });
             return promise;
         }

We want to make permalink work for admin resource requests. Normally we fetch
all resource request (AdminResourceRequestStore.getAll()) and lookup the
request id in the url from those requests. However, getAll only returns the
first page, sometimes the id is not in the url, so we sometimes fetch the
specific request.

    diff --git a/troposphere/static/js/components/admin/ResourceMaster.jsx b/troposphere/static/js/components/admin/ResourceMaster.jsx
    index d594c2643..111c9c2f7 100644
    @@ -96,57 +94,48 @@ const ResourceMaster = React.createClass({
    +        // Lookup selectedRequest by requestId, or make a separate request for
    +        // the model specifically
    +        let selectedRequest =
    +            (requests.get(requestId) || stores.AdminResourceRequestStore.getModel(requestId));

We sort resource requests first by status then by creation date. The api
returns results sorted by creation date, that's implicit, not great.

    diff --git a/troposphere/static/js/components/admin/ResourceRequest/ResourceRequestNav.jsx b/troposphere/static/js/components/admin/ResourceRequest/ResourceRequestNav.jsx
    index 6eb23462b..72992a2f0 100644
    --- a/troposphere/static/js/components/admin/ResourceRequest/ResourceRequestNav.jsx
    +++ b/troposphere/static/js/components/admin/ResourceRequest/ResourceRequestNav.jsx
    @@ -1,6 +1,13 @@
     import React from "react";
     import Backbone from "backbone";

    +function sortByStatus(request) {
    +    if (request.get('status').name == "pending") {
    +        return 1;
    +    }
    +    return 2;
    +}

    ...

    @@ -51,7 +69,12 @@ export default React.createClass({

             return (
             <ul style={list}>
    -            { requests.map(this.renderListItem) }
    +            {
    +                // Requests are assumed to be sorted by start date, we then
    +                // further sort to render the pending requests first (sortBy
    +                // is stable)
    +                requests.sortBy(sortByStatus).map(this.renderListItem)
    +            }
When an admin views a resource request that has already been
approved/closed/denied, require interaction to prevent accidental changing of
resources.

Not a huge fan of this approach, think we can redesign this view to be
simpler, more intuitive, but the primary goal is to make the view more usable.
This fixes the not so nice experience of approving/denying reloading the app.
@cdosborn cdosborn changed the title WIP - Support older requests Support viewing older requests Jan 24, 2018
@lenards
Copy link
Contributor

lenards commented Jan 24, 2018

Quick note, #750 has been merged now.

@cdosborn
Copy link
Contributor Author

Thanks, rebased onto latest master

@cdosborn cdosborn requested review from jchansen and removed request for jchansen February 19, 2018 22:42
@cdosborn cdosborn removed the WIP label Feb 19, 2018
@@ -51,7 +50,7 @@ const ResourceMaster = React.createClass({

onSelect(request) {
// Navigate to a request at the top of the list
browserHistory.push(`/application/admin/resource-requests/${request.id}`);
this.props.router.push(`/admin/resource-requests/${request.id}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Connor knows this - but for folks reading and observing ... or, for inquiring minds - this change leverages that withRouter knows the basename for Troposphere is /application

Copy link
Contributor

@lenards lenards left a comment

Choose a reason for hiding this comment

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

👍

@lenards
Copy link
Contributor

lenards commented Feb 20, 2018

✅ merged: cyverse/atmosphere#575

@lenards
Copy link
Contributor

lenards commented Feb 20, 2018

🎉

@lenards lenards merged commit 3ffd9b9 into cyverse:master Feb 20, 2018
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.

2 participants