Scaffold DashboardMainApp and DashboardEntityApp
Feature Description
The GoogleSiteKitDashboard component is the entry-point to the dashboard and can be set to render differently based on the unifiedDashboard feature flag. When the feature flag for unifiedDashboard is disabled, the existing DashboardApp component should render. When the feature flag for unifiedDashboard is enabled, we should instead render either DashboardMainApp (or DashboardEntityApp, if on an Entity Dashboard page).
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Two new components should be scaffolded in the
assets/js/componentsfolder:DashboardMainAppandDashboardEntityApp. They should only render the Site Kit Header (assets/js/components/Header.js) component for now. - The
GoogleSiteKitDashboardcomponent should, whenunifiedDashboardfeature flag is enabled: renderDashboardMainApp. TheDashboardDetailsAppshould, whenunifiedDashboardfeature flag is enabled, renderDashboardEntityApp. - If the
unifiedDashboardfeature flag is not enabled:GoogleSiteKitDashboardandDashboardDetailsAppshould behave as they currently do today.
Implementation Brief
Inside assets/js/components, create the following files:
dashboard-main/DashboardMainApp.jsdashboard-entity/DashboardEntityApp.js
Inside DashboardMainApp and DashboardEntityApp:
- Import
Headerfromassets/js/components/Header - Create a simple functional component that renders the
Headeronly, and export it as thedefault.
Inside assets/js/googlesitekit-dashboard.js:
- Check if the
unifiedDashboardfeature flag is enabled using theuseFeaturehook. - If the flag is NOT enabled, the existing logic should run.
- If the flag IS enabled, render the new
DashboardEntityAppcomponent
Inside assets/js/googlesitekit-dashboard-details.js:
- Create a new functional component,
GoogleSitekitDashboardDetails, in the same way as has been done ingooglesitekit-dashboard - Inside the new
GoogleSitekitDashboardDetailsfunction, check if theunifiedDashboardfeature flag is enabled using theuseFeaturehook.- If the flag is NOT enabled, the function should return
<DashboardDetailsApp />. - If the flag IS enabled, return
<DashboardEntityApp/>
- If the flag is NOT enabled, the function should return
- Refactor the
rendercall insidedomReadyto render<GoogleSitekitDashboardDetails />inside of<Root>instead of<DashboardDetailsApp />. See the gist below:
const GoogleSitekitDashboardDetails = () => {
const unifiedDashboardEnabled = useFeature( 'unifiedDashboard' );
if ( unifiedDashboardEnabled ) {
return <DashboardEntityApp />;
}
return <DashboardDetailsApp />;
};
domReady( () => {
// ...
render(
<Root viewContext={ VIEW_CONTEXT_PAGE_DASHBOARD }>
<GoogleSitekitDashboardDetails />
</Root>,
renderTarget
);
}
Test Coverage
- No new tests required.
Visual Regression Changes
- Unlikely to require VRT updates.
QA Brief
- Enable the
unifiedDashboardfeature flag in the tester plugin. - Go to the main dashboard:
wp-admin/admin.php?page=googlesitekit-dashboard.- You should see an empty page with a plain header (no help menu or date select).
- If you search the source code, near the bottom you should find a
<div>with an ID ofjs-googlesitekit-dashboard.
- Append a
permaLinkquery string to the URL (e.g.wp-admin/admin.php?page=googlesitekit-dashboard&permaLink=test) to load the entity dashboard.- Again, you should see an empty page with a plain header (no help menu or date select).
- However, if you search the source code, you should find a
<div>with an ID ofjs-googlesitekit-dashboard-details.
Changelog entry
- N/A
IB ✅
The GoogleSiteKitDashboard component should, when unifiedDashboard feature flag is enabled: render DashboardMainApp when there is no permaLink query param and render DashboardEntityApp when the permaLink query param exists.
@aaemnnosttv I think we might have missed a step, looking at this more closely.
It seems if the permaLink query var is present, the PHP layer loads an entirely separate div: googlesitekit-dashboard-details, into which the DashboardDetailsApp is loaded - so it never even hits googlesitekit-dashboard.
What's the best way to proceed here? It feels a bit funny to test for the feature flag in the PHP layer, so I guess we need to add an override inside assets/js/googlesitekit-dashboard-details.js (or possibly assets/js/components/dashboard-details/DashboardDetailsApp.js) that returns the DashboardEntityApp if the feature flag is on?
Let me know what you think and I'll update the IB 👍
@johnPhillips the DashboardEntityApp is essentially the unified dashboard version of the DashboardDetailsApp so we would conditionally render that one based on the feature flag, just as we would do with the current dashboard and unified "main" version of that. So no changes needed on the PHP side for now I don't think 🙂
Thanks @aaemnnosttv. IB updated, let me know what you think?
Inside
assets/js/googlesitekit-dashboard.js
- If the
permalinkquery argument is present, render the newDashboardEntityAppcomponent
@johnPhillips this entrypoint would remain specific to the main dashboard. I see now that this is how it is defined in the ACs which I think may be a mistake. As far as I understand it, GoogleSitekitDashboard only decides to render DashboardApp or the new DashboardMainApp based on the feature flag. Similarly, the assets/js/googlesitekit-dashboard-details.js entry would conditionally render DashboardDetailsApp or the new DashboardEntityApp as you have defined – no query param checks should be needed in either case because that is still done on page load and controls which entry and render target are loaded.
@tofumatt can you confirm and if so, would you please update the ACs?
@aaemnnosttv @tofumatt Yes I see that now too. While we eventually want to combine these things into one app, let's keep things separate as is for now, in their own JS assets - this is related to the conversations we've had before about full page reloads between the two.
We can change this in the future, as 1-2 issues outside of this epic.
Indeed, this was an oversight in the ACs and design doc, because I actually just assumed the rendering logic was located clientside.
I've updated the ACs and have sent it back to you for IB @johnPhillips. Sorry about that! 😓
No problem @tofumatt. This all makes sense to me now and I've updated the IB to remove references to the query param check.
IB :heavy_check_mark:
QA: ✅
- Enabled the
unifiedDashboardfeature flag via the tester plugin - Visited the main dashboard and it's an empty page with a plain header.
divwithjs-googlesitekit-dashboardas ID present.
- Added the
permaLinkURL param - Empty page with plain header displayed as expected.
divwithjs-googlesitekit-dashboard-detailsas ID present.