-
Notifications
You must be signed in to change notification settings - Fork 0
Render fulfillment container only when applicable #402
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8654cb1
Render fulfillment container only when applicable
jazairi 97e04c5
Address security issue identified by CodeQL
jazairi 0fb3f13
Remove semicolons
jazairi c8f65a3
Safely remove container
jazairi 57a4d80
Disable annotations in development and simplify cleanup logic
jazairi 0c2f369
Add helper method to handle cases where stimulus controller JS doesn'…
jazairi 67f1232
rubocop
jazairi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,16 +11,26 @@ export default class extends Controller { | |
| fetch(this.urlValue) | ||
| .then(response => response.text()) | ||
| .then(html => { | ||
| const parentElement = this.element.parentElement; | ||
| // Replace the entire element with the fetched HTML | ||
| this.element.outerHTML = html; | ||
| // Hide primo links if libkey link is present | ||
| if (parentElement.querySelector('.libkey-link')) { | ||
| const resultGet = parentElement.closest('.result-get'); | ||
| if (resultGet) { | ||
| const primoLinks = resultGet.querySelectorAll('.primo-link'); | ||
| // removing instead of hiding to avoid layout issues when selecting which link to highlight | ||
| primoLinks.forEach(link => link.remove()); | ||
| const parentElement = this.element.parentElement | ||
| // Replace the entire element with the fetched HTML, or remove if empty | ||
| if (html.trim()) { | ||
| this.element.outerHTML = html | ||
| // Hide primo links if libkey link is present | ||
| if (parentElement.querySelector('.libkey-link')) { | ||
| const resultGet = parentElement.closest('.result-get') | ||
| if (resultGet) { | ||
| const primoLinks = resultGet.querySelectorAll('.primo-link') | ||
| // removing instead of hiding to avoid layout issues when selecting which link to highlight | ||
| primoLinks.forEach(link => link.remove()) | ||
| } | ||
| } | ||
| } else { | ||
| // Remove empty loader | ||
| this.element.remove() | ||
|
|
||
| // Remove parent empty container, confirming first that it's empty | ||
| if (!parentElement.textContent.trim()) { | ||
| parentElement.remove() | ||
| } | ||
| } | ||
|
jazairi marked this conversation as resolved.
|
||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,4 +111,84 @@ class ResultsHelperTest < ActionView::TestCase | |
| assert_not article?(nil) | ||
| assert_not article?('') | ||
| end | ||
|
|
||
| test 'result_get? returns true when result has links' do | ||
| assert result_get?({ links: [{ 'kind' => 'PDF', 'url' => 'https://example.com' }] }) | ||
| end | ||
|
|
||
| test 'result_get? returns true when result has availability' do | ||
| assert result_get?({ availability: 'Available' }) | ||
| end | ||
|
|
||
| test 'result_get? returns true when ThirdIron enabled and result has doi' do | ||
| ClimateControl.modify(THIRDIRON_ID: '123', THIRDIRON_KEY: 'abc') do | ||
| assert result_get?({ doi: '10.1234/test' }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns true when ThirdIron enabled and result has pmid' do | ||
| ClimateControl.modify(THIRDIRON_ID: '123', THIRDIRON_KEY: 'abc') do | ||
| assert result_get?({ pmid: '12345678' }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns true when ThirdIron enabled and result is a journal with issn' do | ||
| ClimateControl.modify(THIRDIRON_ID: '123', THIRDIRON_KEY: 'abc') do | ||
| assert result_get?({ format: 'Journal', issn: '1234-5678' }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns true when oa_always enabled and result is an article' do | ||
| ClimateControl.modify(FEATURE_OA_ALWAYS: 'true') do | ||
| assert result_get?({ format: 'Article' }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns false when result has no fulfillment content' do | ||
| ClimateControl.modify(THIRDIRON_ID: nil, THIRDIRON_KEY: nil, FEATURE_OA_ALWAYS: nil) do | ||
| assert_not result_get?({}) | ||
| assert_not result_get?({ format: 'Book' }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns false when ThirdIron disabled even with doi' do | ||
| ClimateControl.modify(THIRDIRON_ID: nil, THIRDIRON_KEY: nil) do | ||
| assert_not result_get?({ doi: '10.1234/test' }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns false when oa_always disabled and result has no links' do | ||
| ClimateControl.modify(FEATURE_OA_ALWAYS: nil, THIRDIRON_ID: nil, THIRDIRON_KEY: nil) do | ||
| assert_not result_get?({ format: 'Article' }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns false when result has only full record link and feature is disabled' do | ||
| ClimateControl.modify(FEATURE_RECORD_LINK: nil, THIRDIRON_ID: nil, THIRDIRON_KEY: nil, FEATURE_OA_ALWAYS: nil) do | ||
| assert_not result_get?({ links: [{ 'kind' => 'Full Record', 'url' => 'https://example.com' }] }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns true when result has only full record link and feature is enabled' do | ||
| ClimateControl.modify(FEATURE_RECORD_LINK: 'true', THIRDIRON_ID: nil, THIRDIRON_KEY: nil, FEATURE_OA_ALWAYS: nil) do | ||
| assert result_get?({ links: [{ 'kind' => 'Full Record', 'url' => 'https://example.com' }] }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns true when result has PDF link even if record_link feature is disabled' do | ||
| ClimateControl.modify(FEATURE_RECORD_LINK: nil, THIRDIRON_ID: nil, THIRDIRON_KEY: nil, FEATURE_OA_ALWAYS: nil) do | ||
| assert result_get?({ links: [{ 'kind' => 'PDF', 'url' => 'https://example.com' }] }) | ||
| end | ||
| end | ||
|
|
||
| test 'result_get? returns true when result has both full record and PDF links even if record_link feature is disabled' do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ClimateControl.modify(FEATURE_RECORD_LINK: nil, THIRDIRON_ID: nil, THIRDIRON_KEY: nil, FEATURE_OA_ALWAYS: nil) do | ||
| assert result_get?({ | ||
| links: [ | ||
| { 'kind' => 'Full Record', 'url' => 'https://example.com' }, | ||
| { 'kind' => 'PDF', 'url' => 'https://pdf.example.com' } | ||
| ] | ||
| }) | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.