Repository navigation
MostViewedFooter as an island
#3942
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6fc379e
feat: `MostViewedFooter` as an island
oliverlloyd c1fe828
refactor: Move MostViewedFotter files into the components root
oliverlloyd 19ec8d1
refactor: Created `MostViewedFooterLayout`
oliverlloyd 68b839f
Merge branch 'main' into oliver/mostviewedfooter-island
oliverlloyd 7019d31
Merge branch 'main' into oliver/mostviewedfooter-island
oliverlloyd 8747f67
feat: Added WithABProvider to MostViewedFooter
oliverlloyd 6e1068c
fix: Imports
oliverlloyd 082ec45
refactor: `SecondTierItem` > `MostViewedFooterSecondTierItem`
oliverlloyd 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
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
dotcom-rendering/src/web/components/MostViewedFooter.importable.tsx
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { MostViewedFooterLayout } from './MostViewedFooterLayout'; | ||
| import { WithABProvider } from './WithABProvider'; | ||
|
|
||
| type Props = { | ||
| sectionName?: string; | ||
| format: ArticleFormat; | ||
| ajaxUrl: string; | ||
| switches: Switches; | ||
| pageIsSensitive: boolean; | ||
| isDev?: boolean; | ||
| }; | ||
|
|
||
| export const MostViewedFooter = ({ | ||
| sectionName, | ||
| format, | ||
| ajaxUrl, | ||
| switches, | ||
| pageIsSensitive, | ||
| isDev, | ||
| }: Props) => { | ||
| return ( | ||
| <WithABProvider | ||
| abTestSwitches={switches} | ||
| pageIsSensitive={pageIsSensitive} | ||
| isDev={!!isDev} | ||
| > | ||
| <MostViewedFooterLayout | ||
| sectionName={sectionName} | ||
| format={format} | ||
| ajaxUrl={ajaxUrl} | ||
| /> | ||
| </WithABProvider> | ||
| ); | ||
| }; | ||
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 |
|---|---|---|
|
|
@@ -3,14 +3,14 @@ import fetchMock from 'fetch-mock'; | |
| import { ArticleDisplay, ArticleDesign, ArticlePillar } from '@guardian/libs'; | ||
| import { ABProvider } from '@guardian/ab-react'; | ||
|
|
||
| import { ElementContainer } from '../../ElementContainer'; | ||
| import { ElementContainer } from './ElementContainer'; | ||
| import { | ||
| responseWithTwoTabs, | ||
| responseWithOneTab, | ||
| responseWithMissingImage, | ||
| } from '../MostViewed.mocks'; | ||
| } from './MostViewed.mocks'; | ||
|
|
||
| import { MostViewedFooter } from './MostViewedFooter'; | ||
| import { MostViewedFooter } from './MostViewedFooter.importable'; | ||
|
|
||
| export default { | ||
| component: MostViewedFooter, | ||
|
|
@@ -51,6 +51,9 @@ export const withTwoTabs = () => { | |
| }} | ||
| sectionName="politics" | ||
| ajaxUrl="https://api.nextgen.guardianapps.co.uk" | ||
| switches={{}} | ||
| pageIsSensitive={false} | ||
| isDev={false} | ||
|
Comment on lines
+54
to
+56
Contributor
Author
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. I''m passing these in to be used by |
||
| /> | ||
| </ElementContainer> | ||
| </AbProvider> | ||
|
|
@@ -74,6 +77,9 @@ export const withOneTabs = () => { | |
| theme: ArticlePillar.News, | ||
| }} | ||
| ajaxUrl="https://api.nextgen.guardianapps.co.uk" | ||
| switches={{}} | ||
| pageIsSensitive={false} | ||
| isDev={false} | ||
| /> | ||
| </ElementContainer> | ||
| </AbProvider> | ||
|
|
@@ -97,6 +103,9 @@ export const withNoMostSharedImage = () => { | |
| theme: ArticlePillar.News, | ||
| }} | ||
| ajaxUrl="https://api.nextgen.guardianapps.co.uk" | ||
| switches={{}} | ||
| pageIsSensitive={false} | ||
| isDev={false} | ||
| /> | ||
| </ElementContainer> | ||
| </AbProvider> | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -2,16 +2,16 @@ import { render, fireEvent } from '@testing-library/react'; | |
|
|
||
| import { ArticleDesign, ArticleDisplay, ArticlePillar } from '@guardian/libs'; | ||
|
|
||
| import { useApi as useApi_ } from '../../../lib/useApi'; | ||
| import { decidePalette } from '../../../lib/decidePalette'; | ||
| import { useApi as useApi_ } from '../lib/useApi'; | ||
|
Contributor
Author
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. There's a bunch of these import changes which are merge conflict hangovers |
||
| import { decidePalette } from '../lib/decidePalette'; | ||
|
|
||
| import { responseWithTwoTabs, responseWithOneTab } from '../MostViewed.mocks'; | ||
| import { responseWithTwoTabs, responseWithOneTab } from './MostViewed.mocks'; | ||
| import { MostViewedFooterData } from './MostViewedFooterData'; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const useApi: { [key: string]: any } = useApi_; | ||
|
|
||
| jest.mock('../../../lib/useApi', () => ({ | ||
| jest.mock('../lib/useApi', () => ({ | ||
| useApi: jest.fn(), | ||
| })); | ||
|
|
||
|
|
||
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
File renamed without changes.
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this reason we need
WithABProviderhere because this is being loaded in dynamically and so doesn't inherit theBootReactWithABProvider?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. We're no longer in the same context (the same stack) as
BootReactso we need to set our own AB providerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a pattern we will continue to see then and could we look at adding this to the islands code? e.g. All islands have the same as the Boot context?
(another PR / discussion maybe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered this approach (I'll update the PR description to include this) but it turned out to make the inclusion of this AB code dynamic (only when needed/wanted) I would have needed to change the code both in the
Islandserver side component and also thedoHydrationclient side code. It felt like adding more coupling to this for what is a secondary concern wasn't the right thing to do.The alternative to the dynamic coupling is to just always set it. Which is an option. I guess the discussion is around the trade off between optimisation and dev ex. I think this is a worthwhile discussion to have so I'll raise it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: #3955