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

Fixes #11379: Made the subtopics method #11380

Closed
wants to merge 12 commits into from

Conversation

KarishmaVanwari
Copy link
Contributor

@KarishmaVanwari KarishmaVanwari commented Sep 2, 2022

Fixes #11379

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

@gitpod-io
Copy link

gitpod-io bot commented Sep 2, 2022

@codecov
Copy link

codecov bot commented Sep 2, 2022

Codecov Report

Merging #11380 (e220ca5) into main (e184230) will increase coverage by 2.66%.
The diff coverage is 100.00%.

❗ Current head e220ca5 differs from pull request most recent head 11cdb1c. Consider uploading reports for the commit 11cdb1c to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11380      +/-   ##
==========================================
+ Coverage   79.75%   82.42%   +2.66%     
==========================================
  Files          96       96              
  Lines        5968     5952      -16     
==========================================
+ Hits         4760     4906     +146     
+ Misses       1208     1046     -162     
Impacted Files Coverage Δ
app/controllers/tag_controller.rb 85.79% <100.00%> (+7.95%) ⬆️
app/models/node.rb 91.18% <0.00%> (+0.16%) ⬆️
app/models/comment.rb 77.70% <0.00%> (+0.32%) ⬆️
app/models/user.rb 86.49% <0.00%> (+0.72%) ⬆️
app/controllers/spam2_controller.rb 71.84% <0.00%> (+0.97%) ⬆️
app/controllers/users_controller.rb 80.78% <0.00%> (+1.06%) ⬆️
app/api/srch/search.rb 66.66% <0.00%> (+1.28%) ⬆️
app/controllers/user_tags_controller.rb 83.78% <0.00%> (+1.35%) ⬆️
app/controllers/admin_controller.rb 80.24% <0.00%> (+1.64%) ⬆️
app/helpers/application_helper.rb 88.65% <0.00%> (+2.06%) ⬆️
... and 15 more

config/routes.rb Outdated Show resolved Hide resolved
@jywarren
Copy link
Member

jywarren commented Sep 2, 2022

Hi @KarishmaVanwari ok, so, this actually relates to this PR, on topic trees: #11230 (comment)

I'm so sorry i mixed these up. But I've made some suggestions and explanations to refine this PR a bit, and you have to expand the "Show resolved" sections above to read them -- please do! Let me know if they make sense?

nodes = Tag.find_by(name: "parent:#{params[:topic]}") # here, we look for this special tag marking a node as having a parent
.nodes
.collect(&:slug) # collect the "slugs" i.e. the unique part of the URL, which should correspond to a tagname
render "tags/subtopic", layout: false
Copy link
Member

Choose a reason for hiding this comment

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

OK, so here, i think we also have to actually make the partial template, at: /app/views/tags/_subtopics.html.erb, and for now it can just print out the subtopics. If you'd like, you can look at the HTML you made in #11230 and use that?

Copy link
Contributor Author

@KarishmaVanwari KarishmaVanwari Sep 4, 2022

Choose a reason for hiding this comment

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

@jywarren :
I created the file _subtopics.html.erb with the following code so as to only print the subtopics when pointed at a URL say http://localhost:3000/tags/subtopic/one or http://localhost:3000/tags/subtopic/two:

<% @subtopics.each do |subtopic| %>
    <h1><%= subtopic %></h1>
<% end %>

However, it gives an error -

image

Is it because the tags "one" or "two" do not have any specified subtopics as such? But it doesn't seem so, since I just tried adding a check to see if @subtopics is nil. Let me know your thoughts on this!

Thanks!

@KarishmaVanwari
Copy link
Contributor Author

Hi @KarishmaVanwari ok, so, this actually relates to this PR, on topic trees: #11230 (comment)

I'm so sorry i mixed these up. But I've made some suggestions and explanations to refine this PR a bit, and you have to expand the "Show resolved" sections above to read them -- please do! Let me know if they make sense?

Hi @jywarren, I've gone through the explanations and understood my shortcomings and the respective explanations. Thank you so much Jeff for the detailed explanation and for bearing with me while I try to figure out stuff, thanks again! ❤️

@jywarren
Copy link
Member

jywarren commented Sep 5, 2022 via email

@jywarren
Copy link
Member

jywarren commented Sep 5, 2022

Aha - the subtopics method is in the private area of the controller. I've made changes and will push them in a moment.

As much as possible please do push up your local changes to the PR so I can see exactly what you're working with when i open it. Thanks!

@github-actions
Copy link

github-actions bot commented Sep 5, 2022

This pull request generated screenshots of many common pages in the running app. You should be able to download and view them here:
https://github.com/publiclab/plots2/suites/8142492360/artifacts/353102091

@@ -568,4 +579,5 @@ def fetch_counts
end

def topic_tree; end

Copy link

Choose a reason for hiding this comment

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

Extra empty line detected at class body end.

render "tag/_subtopics", layout: false
end


Copy link

Choose a reason for hiding this comment

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

Extra blank line detected.

# collect the "slugs" i.e. the unique part of the URL, which should correspond to a tagname
subtopic_names = Tag.find_by(name: "parent:#{params[:topic]}")
&.nodes
&.collect(&:slug)
Copy link
Member

Choose a reason for hiding this comment

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

OK, I pushed a couple commits to fix minor issues. See how I moved this up out of the "private" section.

Also I added &. which fails gracefully if the value is nil, instead of erroring - it just doesn't continue trying.

I think it should work now, but I think it's worth writing a functional test for this. That will mean adding a tag to a wiki page with name parent:TAGNAME such that the code actually gets used.

The reason is that for most tags we might test this with, there won't be any subtopics. We need to create some test data to make that situation appear so that we can write a test around it. Make sense? I'm happy to help with the test data, let me know if you'd like some support on that!

Copy link
Member

Choose a reason for hiding this comment

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

And great work getting this far. It's complex!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jywarren
I tried opening the page: /tags/subtopic/one, I am able to successfully render the page (blank although), and I can render topic name also on the page by extracting it from the URL. I created a wiki page with tag parent:one but I am still unable to fetch subtopics on the page. I doubt if @subtopics actually carries the subtopics in it.

Also, a mention, on line 531 here, we have

Tag.find_by(name: "parent:#{params[:topic]}")

Here, tag is compared with parent:#{params[:topic]}, right? So I also tried creating a wiki page with tag parent:#one but still can't fetch it on the /tags/subtopic/one page. Conversely, I also tried to change the line 531 to this -

Tag.find_by(name: "parent:{params[:topic]}")

and created a wiki page with tag parent:one, but still I can't obtain desired result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, do you think I have this test data (the wiki pages I created), so as to write a test? Also, I am totally new to writing tests, could you please guide me with it? PS: Sharing resources also would do.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Hi @KarishmaVanwari ok so you are doing really well then, if it rendered a blank page. We just need to debug the controller.

A controller test is known as a functional test -- there is documentation here, but it's pretty dense: https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers

I might start by looking at other tests:

test 'tag show' do
get :show, params: { id: tags(:spectrometer).name }
assert :success
assert_not_nil :tags
# assert_equal assigns['tags'].length, 1
assert_select '#wiki-summary', 1
end

And at how we create test data -- by creating entries in https://github.com/publiclab/plots2/blob/main/test/fixtures/

For tags, we'll have to create not only a tag fixture entry in https://github.com/publiclab/plots2/blob/main/test/fixtures/tags.yml

but also a record to link that tag to a node: https://github.com/publiclab/plots2/blob/main/test/fixtures/node_tags.yml

Does that make sense? Let's start with that, can you add that to this PR? Once it's in place, I can help you write a simple test, then narrow the test assertions until we find what was wrong with our assumptions. How does that sound?

Copy link
Member

Choose a reason for hiding this comment

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

And, as far as I can tell, your parent:one tag should work! And here is hopefully a helpful tip - the "line of text with #{something} in the middle" syntax is a way to insert Ruby code into a string. It must use " double quotes, and the inserted Ruby code to be evaluated is surrounded by #{ }. It's a little weird looking but it is smoother than adding a bunch of separate strings together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@github-actions
Copy link

github-actions bot commented Sep 5, 2022

This pull request generated screenshots of many common pages in the running app. You should be able to download and view them here:
https://github.com/publiclab/plots2/suites/8142614414/artifacts/353110022

@codeclimate
Copy link

codeclimate bot commented Sep 8, 2022

Code Climate has analyzed commit 11cdb1c and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 2

View more on Code Climate.

@github-actions
Copy link

github-actions bot commented Sep 8, 2022

This pull request generated screenshots of many common pages in the running app. You should be able to download and view them here:
https://github.com/publiclab/plots2/suites/8197882740/artifacts/356918804

subtopic_tag:
tid: 38
uid: 2
nid: 41
Copy link
Member

Choose a reason for hiding this comment

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

This looks good, but it's applied to this page, which is a note, not a wiki:

https://github.com/KarishmaVanwari/plots2/blob/subtopics/test/fixtures/nodes.yml#L497

Will that affect the logic, and possibly cause it not to return things?

Copy link
Member

Choose a reason for hiding this comment

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

Well, it should get the slug for this note, and try to use it as a subtopic tagname, according to this logic:

https://github.com/publiclab/plots2/pull/11380/files#diff-5d60373322d4baf080e5f3957fc30d0e8058337c202f5641e1775402776428b1R533

Aha - yes, so, then it takes the slug from that page, which is "jeff-12-20-2020-ouija-board" - and tries to find a tag with that name. It doesn't find one, so it returns null.

Let's change this to instead point at this node, which is a page, with slug about. Then let's add a new tag with the name about so that there is actually a tag that can be returned.

We could give these more realistic tag names so it makes more sense... but, maybe it's not worth it for now. Let's just get it working first.

Suggested change
nid: 41
nid: 2

So now you'll also have to add a new tags.yml entry, but it doesn't need a node_tags.yml entry, since we only look if the tag exists, not if we used it anywhere. Let's see how that works!

subtopic_names = Tag.find_by(name: "parent:#{params[:topic]}")
&.nodes
&.collect(&:slug)
@subtopics = Tag.find_by(name: subtopic_names)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was trying this locally and this line returns nil,,, the subtopic_names variable above returns slugs of the nodes' title downcase & hyphenated -- from the comment seems we are expecting this to be tagname slugs that maybe the issue

@stale
Copy link

stale bot commented Sep 16, 2023

Hi 😄, this issue has been automatically marked as stale because it has not had recent activity. Don't worry you can continue to work on this and ask @publiclab/reviewers to add in-progress label 🎉 . Otherwise, it will be closed if no further activity occurs in 10 days -- but you can always re-open it if you like! 💯 Thank you for your contributions! 🙌 🎈.

@stale stale bot added the stale label Sep 16, 2023
@stale stale bot closed this Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the subtopics method
3 participants