Skip to content

Commit

Permalink
feat(routerContext): sw-1089 enhance page titles (#1091)
Browse files Browse the repository at this point in the history
* routerContext, exposed bundleTitle through useChrome
  • Loading branch information
cdcabrera committed Apr 6, 2023
1 parent a3a7d9b commit 1d05b6d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/jest.setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ global.window.insights = {
})
)
},
getBundleData: Function.prototype,
getUserPermissions: () => [],
hideGlobalFilter: Function.prototype,
identifyApp: Function.prototype,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exports[`RouterContext should apply a hook for useRouteDetail: document title 1`
[
[
"t(curiosity-view.title, {"appName":"Subscriptions","context":"RHEL"}) - Subscriptions",
true,
],
]
`;
Expand Down
10 changes: 6 additions & 4 deletions src/components/router/routerContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const useRouteDetail = ({
useChrome: useAliasChrome = useChrome,
useSelector: useAliasSelector = storeHooks.reactRedux.useSelectors
} = {}) => {
const { updateDocumentTitle = helpers.noop } = useAliasChrome();
const { getBundleData = helpers.noop, updateDocumentTitle = helpers.noop } = useAliasChrome();
const bundleData = getBundleData();
const [productPath] = useAliasSelector([({ view }) => view?.product?.config]);
const [detail, setDetail] = useState({});

Expand All @@ -112,12 +113,13 @@ const useRouteDetail = ({
pathName: productPath
});

// Set document title
// Set document title, remove pre-baked suffix
updateDocumentTitle(
`${t(`curiosity-view.title`, {
appName: helpers.UI_DISPLAY_NAME,
context: firstMatch?.productGroup
})} - ${helpers.UI_DISPLAY_NAME}`
})} - ${helpers.UI_DISPLAY_NAME}${(bundleData?.bundleTitle && ` | ${bundleData?.bundleTitle}`) || ''}`,
true
);

// Set route detail
Expand All @@ -132,7 +134,7 @@ const useRouteDetail = ({
productPath
});
}
}, [detail?._passed, productPath, t, updateDocumentTitle]);
}, [bundleData?.bundleTitle, detail?._passed, productPath, t, updateDocumentTitle]);

return detail;
};
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ window.insights = {
});
})
},
getBundleData: () => ({ bundleId: 'insights', bundleTitle: 'Red Hat Insights' }),
getUserPermissions: () => [],
hideGlobalFilter: Function.prototype,
identifyApp: Function.prototype,
Expand Down

0 comments on commit 1d05b6d

Please sign in to comment.