Skip to content

Server Views with React#753

Closed
djbarnwal wants to merge 31 commits intoiodide-project:masterfrom
djbarnwal:server-views
Closed

Server Views with React#753
djbarnwal wants to merge 31 commits intoiodide-project:masterfrom
djbarnwal:server-views

Conversation

@djbarnwal
Copy link
Copy Markdown
Contributor

@djbarnwal djbarnwal commented Aug 13, 2018

This Pull Request implements a MVP model of the Iodide website integrated with a server. The user can now -

  1. Save a Notebook on the server
  2. Update it
  3. Fork it
  4. See all notebooks
  5. See Notebooks associated with a user.

What isn't included -

  1. UI is very hacky
  2. Revisions and Versioning of notebooks needs to be hooked with the UI
  3. Handle edge cases (such as fetching 0 notebooks etc.)
  4. Deciding which APIs should be exposed publicly (like viewing all users is possible using api/v1/users/ route)
  5. Write better Webpack config using plugins like Uglify etc.
  6. Write tests for new APIs
  7. Add Linting
  8. Port notebook server options to iframe-2

Closes #669 and #633

@bcolloran bcolloran requested a review from wlach August 14, 2018 18:58
@bcolloran
Copy link
Copy Markdown
Contributor

@djbarnwal the small amount client-side code looks good. requesting review from @wlach on the server stuff.

@djbarnwal please also merge in the latest master

Copy link
Copy Markdown
Contributor

@wlach wlach left a comment

Choose a reason for hiding this comment

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

On the whole this looks ok. After looking at the patch, I am not crazy about django-webpack-loader. It feels pretty unwieldly, and I would rather we just have one static bundle rather than two seperate web configs with the server. However, this will probably be ok for initial testing.

I don't think we need the user api's (at least not yet). Please see if you can get things working with a filter on the notebook endpoints as I suggest, as it will reduce the surface we need to validate and test.

I haven't tested how this actually works, let me know once you've addressed the main points here and I'll take a closer look.

Comment thread readme.md Outdated
In dev mode, resource paths are set to be relative to the `dev/` directory. Thus, you export a notebook from a dev notebook, you need to be sure save the exported HTML file in the `dev/` folder for the relative paths to correctly resolve the required js/css/font files.

### Production mode
### Production mode
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please try not to let these kind of unrelated changes into your pull requests, as they make them more difficult to review.

Comment thread server/base/api_urls.py Outdated
urlpatterns = [
url(r'^users/$', UserList.as_view(), name='user-list'),
url(r'^users/(?P<pk>[0-9]+)/$', UserDetail.as_view(), name='user-detail'),
url(r'^users/username/(?P<username>\w+)$', UserDetailFromUsername.as_view(), name='user-detail-username'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we were going to keep these methods, use rest_framework's router framework here (see server/notebooks/api_urls.py for an example of this)

}

render() {
console.log('state', this.state.user)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please do a search for all console.log statements in your patch and remove them.

Comment thread server/base/api_urls.py Outdated
@@ -0,0 +1,9 @@
from django.conf.urls import url
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure we don't need these user api's. Instead we can add a "filter by user" on the existing notebooks endpoint:

e.g. /api/v1/notebooks/?user=djbarnwal

See: http://www.django-rest-framework.org/api-guide/filtering/

You can see some examples of setting up filtering with rest framework in @jaredkerim's experimenter project:

https://github.com/mozilla/experimenter/tree/master/app/experimenter/experiments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@wlach This can be done but this way we won't be able to fetch the meta data of the user (such as first name, avatar etc.) for the profile page.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it would be more sensible to add such filtering to already existing users route instead of creating another users/username/ route

Comment thread server/base/api_views.py Outdated
from server.base.serializers import UserSerializer


class UserList(generics.ListCreateAPIView):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you're going to keep this, use viewsets (probably ReadOnlyModelViewSet) here: http://www.django-rest-framework.org/api-guide/viewsets/

Comment thread server/urls.py Outdated
url(r'^notebooks/', include('server.notebooks.urls')),

# various views to help with the authentication pipeline
# various views to help with the authentication pipe line
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

revert this change

Comment thread server/urls.py Outdated
url(r'^logout/$', server.views.logout, name='logout'),

# route for creating new notebooks
url(r'^notebook', server.views.notebook, name='notebook'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably make this /server/notebooks/new and serve it under the existing notebook urls, above ^^^

}

render() {
return (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's take the advertising spiel out for now, and just focus on presenting a reasonable user interface when people are using the alpha server.

Comment thread server/urls.py Outdated
url(r'^$', server.views.index, name='index'),
# url(r'^$', server.views.index, name='index'),
# react bundles to views
url(r'^(?!oauth/|notebooks)', server.views.index, name='index'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure what the comment here means, or the rationale behind this change? I'm sure there is one, I just don't understand. :)

</head>

<body>
<div id="react"></div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we pick a more meaningful identifier than react?

@wlach wlach mentioned this pull request Aug 16, 2018
@wlach
Copy link
Copy Markdown
Contributor

wlach commented Aug 20, 2018

This PR seems to have gotten disconnected from master somehow, there's a lot of commits in here that duplicate things already landed.

In any case, after some discussion and thinking, I'd like to fork this PR and try an alternate approach described here:

https://hackernoon.com/reconciling-djangos-mvc-templates-with-react-components-3aa986cf510a

The key benefits are that we won't need seperate package.json files, or a seperate webpack server running on the host or in production. Everything can be generated in the existing npm build step. This should also make load times considerably faster (since we can just prepopulate what's visible on each page on the server side, instead of having the client make a round trip to the server after loading the assets)

I'll do up some experiments based on the code here and we can see how it plays out.

@wlach
Copy link
Copy Markdown
Contributor

wlach commented Sep 5, 2018

I think we can close this for now, thank you @djbarnwal for taking the first crack at this! Even though we decided to move in a slightly different direction for the implementation in the end, the learnings we got from this PR were extremely valuable.

@wlach wlach closed this Sep 5, 2018
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.

3 participants