Skip to content

Add DataDoc show page - #48084

Merged
megcrenshaw merged 18 commits into
stagingfrom
add-show-page
Sep 14, 2022
Merged

Add DataDoc show page#48084
megcrenshaw merged 18 commits into
stagingfrom
add-show-page

Conversation

@megcrenshaw

@megcrenshaw megcrenshaw commented Sep 14, 2022

Copy link
Copy Markdown

This work is part of https://codedotorg.atlassian.net/browse/PLAT-1279 –– Curriculum Writers can add new Data Docs.

This PR allows you to see the data doc after you've created it. To see functionality, go to http://localhost-studio.code.org:3000/data_docs/new. It should make you add Levelbuilder permissions to your local account before you can view the page, and after putting in info, the site redirects to the newly-created data doc.

image

See functionality: https://watch.screencastify.com/v/kVoYeC6J8jnxu5iugfNK

Links

Spec
Engineering Plan

Testing story

I added unit tests for these. In a separate PR, will add a UI test, ensuring a user can create and then see the data doc.

Deployment strategy

Follow-up work

Add UI test, and move asset out of curriculum builder (tracked here https://codedotorg.atlassian.net/browse/PLAT-1956)

Add UI test

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

<div style={styles.container}>
<div style={{marginBottom: 5}}>Markdown:</div>
<MarkdownEnabledTextarea
name={this.props.name}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This attribute gets passed to the textarea field, which triggers the HTML5 form to send its contents in the post request

@megcrenshaw
megcrenshaw requested a review from a team September 14, 2022 14:45
<a href="https://creativecommons.org/">
<img src="https://curriculum.code.org/static/img/creativeCommons-by-nc-sa.png" />
<img
src="https://curriculum.code.org/static/img/creativeCommons-by-nc-sa.png"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Since we're deprecating this URL, this asset will need to be moved, right? If so, I'll create a ticket for it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, good catch!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Great –– tracked here https://codedotorg.atlassian.net/browse/PLAT-1956, and mentioned in follow-up work

@davidsbailey davidsbailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

awesome progress! I love the sizing of these PRs 👍

Comment thread apps/Gruntfile.js Outdated
'courses/edit': './src/sites/studio/pages/courses/edit.js',
'courses/new': './src/sites/studio/pages/courses/new.js',
'data_docs/new': './src/sites/studio/pages/data_docs/new.js',
'data_docs/show': './src/sites/studio/pages/data_docs/show.js', // TODO [meg]: move to codeStudioEntries once launched

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am curious, why not put it there now?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sounds good –– will move this

<a href="https://creativecommons.org/">
<img src="https://curriculum.code.org/static/img/creativeCommons-by-nc-sa.png" />
<img
src="https://curriculum.code.org/static/img/creativeCommons-by-nc-sa.png"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, good catch!

const {dataDocName, dataDocContent} = props;

return (
<>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TIL about fragments! 💡

@@ -1,5 +1,5 @@
class DataDocsController < ApplicationController
before_action :require_levelbuilder_mode_or_test_env
before_action :require_levelbuilder_mode_or_test_env # TODO [meg]: add except: [:show] to launch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

waiting is fine, but also this seems safe to do now -- as long as we are not linking to this page yet, the risk of a legit user ending up on this page and then becoming confused seems very low.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Great, sounds good –– will change permissions for the show page!

@@ -0,0 +1,2 @@
%script{src: webpack_asset_path('js/data_docs/show.js'), data: {dataDocName: @data_doc_name.to_json, dataDocContent: @data_doc_content.to_json}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see that this use of to_json works today, but is a little concerning because technically only things wrapped in [] and {} are valid json, and we have run into problems like this before when we try to upgrade. my recommendation would be to wrap these two fields in a single object like data: {dataDocs: {...}.to_json}. you could also just pass them as plain strings without to_json or getScriptData.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oo, good to know! I ran into an error without the to_json but didn't investigate further ... will look into changing this

sign_in @levelbuilder
new_key = "doc_key"
get :create, params: {key: new_key}
assert_match %r{/data_docs/#{new_key}$}, @response.headers['Location']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

great test! one nit: rails provides a... railsier way to do this assertion:

assert_redirected_to controller: 'sections', action: 'show', id: @picture_section.code

that's what I'd recommend since it seems less fragile. if that seems too abstract, this could be a possible compromise:

assert_redirected_to '/projects/public'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh, that's cool! Will do that 👍

test_user_gets_response_for :create, params: -> {@test_params}, user: :levelbuilder, response: :success

# TODO [meg] : all should be able to see `show` page, once launched
# for now, only levelbuilder can see it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

again, this strategy is perfectly valid, but seems like unnecessary work to take these extra steps to protect these pages

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sounds good –– will move these

@davidsbailey davidsbailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks great!


# GET /data_docs/:key
def show
@data_doc = DataDoc.find_by(key: params[:key])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am curious, do you get this for free due to the combination of load_and_authorize_resource her and param: :key in routes.rb ? I would suggest removing this statement and seeing if everything still works (CanCan should define @data_doc for you). if not... no need to investigate too much, sometimes CanCan doesn't quite work as expected when the param is not id.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Just tried it: @data_doc isn't defined ... also, in the create method, I originally tried

    if @data_doc.save
      redirect_to @data_doc

and got the same problem (it tried to use the id in the URL, which I was surprised by given the param: :key in routes)

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.

2 participants