Skip to content

Commit

Permalink
Merge pull request #7318 from google/enhancement/7061-fix-KM-navigati…
Browse files Browse the repository at this point in the history
…on-bugs

Fix incorrect navigation chip selection on page load.
  • Loading branch information
techanvil authored Jul 17, 2023
2 parents c3f56d5 + 2d6add0 commit 893aff7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets/js/components/DashboardNavigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export default function Navigation() {
const margin = 20;

const areas = [
...( showKeyMetrics ? [ ANCHOR_ID_TRAFFIC ] : [] ),
...( showKeyMetrics ? [ ANCHOR_ID_KEY_METRICS ] : [] ),
...( showTraffic ? [ ANCHOR_ID_TRAFFIC ] : [] ),
...( showContent ? [ ANCHOR_ID_CONTENT ] : [] ),
...( showSpeed ? [ ANCHOR_ID_SPEED ] : [] ),
Expand Down
11 changes: 10 additions & 1 deletion assets/js/components/DashboardNavigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Data from 'googlesitekit-data';
import { CORE_USER } from '../../googlesitekit/datastore/user/constants';
import useViewOnly from '../../hooks/useViewOnly';
import Navigation from './Navigation';
import { useFeature } from '../../hooks/useFeature';
const { useSelect } = Data;

export default function DashboardNavigation() {
Expand All @@ -36,7 +37,15 @@ export default function DashboardNavigation() {
return select( CORE_USER ).getViewableModules();
} );

if ( viewableModules === undefined ) {
const userInputEnabled = useFeature( 'userInput' );
const keyMetrics = useSelect(
( select ) => userInputEnabled && select( CORE_USER ).getKeyMetrics()
);

// The Navigation component relies on the resolution of the above selectors to check if individual
// widgetContexts are active. The results of these checks are used to determine the `defaultChipID`
// which 'highlights' the first chip and sets the corresponding hash on page load.
if ( viewableModules === undefined || keyMetrics === undefined ) {
return null;
}

Expand Down

0 comments on commit 893aff7

Please sign in to comment.