broadinstitute / single_cell_portal_core

Rails/Docker application for the Broad Institute's single cell RNA-seq data portal
https://singlecell.broadinstitute.org
BSD 3-Clause "New" or "Revised" License
62 stars 26 forks source link

Adding reusing component for placing link on home page (SCP-5803) #2140

Closed bistline closed 4 weeks ago

bistline commented 4 weeks ago

BACKGROUND & CHANGES

This update adds the HomePageLink model for placing a single link on the home page. There is no UI for adding these links - instead they can be added directly from the Rails console to reduce the overhead of CRUDing the link. The model includes convenience methods for publishing/unpublishing links, and validations to ensure that only one link can be published at any time. Additionally, admins can embed an image inside the button by providing a filename of an existing image (sadly, we cannot link to remote images due to our CSP img_src rule). The button CSS classes & background color are configurable, though the CSS needs to be a previously defined class. Also, the button can have a tooltip to display a contextual message.

Here's a screenshot of what the button can look like with an image (using the Cellarium logo, as this is primarily what this feature was designed to link to):

Screenshot 2024-09-24 at 4 07 39 PM

Additionally, this moves the link for the "Portal whitepaper" to the footer, next to the Terms of Service link.

MANUAL TESTING

  1. Boot as normal and confirm there is no link displayed on the home page under the Feature announcements button
  2. In a separate Rails console session, create a new HomePageLink for the CAS survey, but don't publish it yet:
    
    link = HomePageLink.create(name: 'CAS Survey', href: 'https://docs.google.com/forms/d/e/1FAIpQLSd8WJvrRrCXi-KyYPTrOQ4u7kWNZo4Wt1uKorJXH05TmPJ_oQ/viewform', image: 'cellarium.png', tooltip: 'Fill out the survey!')
    => #<HomePageLink _id: 66f328c094ec8f52319c33f4, ...

link.published? => false

3. Reload the homepage and confirm that you still do not see the link
4. Publish the link, then reload the home page to confirm that you see it with the image & tooltip:

link.publish! => true

![Screenshot 2024-09-24 at 5 13 21 PM](https://github.com/user-attachments/assets/708aff9c-9290-42a4-bbe3-7cca04615694)

5. Use the convenience methods to publish/unpublish links without directly loading them, and that they show/hide on the home page accordingly:

HomePageLink.unpublish! ... Unpublishing 'CAS Survey' => true

HomePageLink.unpublish! ... No published links => false

HomePageLink.publish_last! ... Publishing 'CAS Survey' => true

HomePageLink.publish_last! 'CAS Survey' is already published => false

6. Try changing the `bg_color` to `red` and `css_class` to `btn-lg` and confirm that the UI updates (note you can also use hex color codes prefixed with `#`):

link.update(bg_color: 'red', css_class: 'btn btn-lg') => true

![Screenshot 2024-09-24 at 5 16 03 PM](https://github.com/user-attachments/assets/8118cb4d-46f1-49f4-973a-63bbe9c3bece)
7. Use the convenience method to reset the colors/classes and confirm it reverts to normal:

link.reset_bg_color! ... Resetting bg_color to '#4999F9' => true

link.reset_css! ... Resetting css_class to 'btn btn-home-link' => true

![Screenshot 2024-09-24 at 5 13 21 PM](https://github.com/user-attachments/assets/d82fbb6d-3119-489d-a35d-1a95225db74e)
8. Try to create a new published link and confirm it does not save:

new_link = HomePageLink.create(name: 'foo', href: 'bar', published: true) ... Published link exists: 'CAS Survey', please unpublish first with HomePageLink.unpublish! => #<HomePageLink _id: 66f32d5794ec8f52319c33f7, created_at: nil, updated_at: nil, name: "foo", href: "bar", tooltip: nil, bg_color: "#...

new_link.persisted? => false

codecov[bot] commented 4 weeks ago

Codecov Report

Attention: Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 69.61%. Comparing base (b4cf943) to head (0235243). Report is 42 commits behind head on development.

Files with missing lines Patch % Lines
app/models/home_page_link.rb 93.61% 3 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/broadinstitute/single_cell_portal_core/pull/2140/graphs/tree.svg?width=650&height=150&src=pr&token=HMWE5BO2a4&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=broadinstitute)](https://app.codecov.io/gh/broadinstitute/single_cell_portal_core/pull/2140?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=broadinstitute) ```diff @@ Coverage Diff @@ ## development #2140 +/- ## =============================================== - Coverage 69.86% 69.61% -0.26% =============================================== Files 328 331 +3 Lines 27670 27936 +266 Branches 2402 2438 +36 =============================================== + Hits 19333 19449 +116 - Misses 8203 8334 +131 - Partials 134 153 +19 ``` | [Files with missing lines](https://app.codecov.io/gh/broadinstitute/single_cell_portal_core/pull/2140?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=broadinstitute) | Coverage Δ | | |---|---|---| | [app/controllers/site\_controller.rb](https://app.codecov.io/gh/broadinstitute/single_cell_portal_core/pull/2140?src=pr&el=tree&filepath=app%2Fcontrollers%2Fsite_controller.rb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=broadinstitute#diff-YXBwL2NvbnRyb2xsZXJzL3NpdGVfY29udHJvbGxlci5yYg==) | `40.09% <100.00%> (+0.14%)` | :arrow_up: | | [app/models/home\_page\_link.rb](https://app.codecov.io/gh/broadinstitute/single_cell_portal_core/pull/2140?src=pr&el=tree&filepath=app%2Fmodels%2Fhome_page_link.rb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=broadinstitute#diff-YXBwL21vZGVscy9ob21lX3BhZ2VfbGluay5yYg==) | `93.61% <93.61%> (ø)` | | ... and [11 files with indirect coverage changes](https://app.codecov.io/gh/broadinstitute/single_cell_portal_core/pull/2140/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=broadinstitute)
bistline commented 4 weeks ago

Build failure addressed in #2141

eweitz commented 4 weeks ago

The AnnData test failures are false positives, insofar as user-facing impact is concerned.

bistline commented 4 weeks ago

The AnnData test failures are false positives, insofar as user-facing impact is concerned.

Right - thanks for the clarification. I meant only the NeMO tests.