fix(plugins/home): Get name for catalog entities fallback to title
Signed-off-by: Renan Mendes Carvalho <aitherios@gmail.com>
This commit is contained in:
committed by
Camila Belo
parent
5514040b44
commit
f4cb351de2
@@ -57,7 +57,16 @@ const getToEntityRef =
|
||||
* for receiving a pathname and returning a string (name). The default
|
||||
* implementation ignores the pathname and uses the document.title .
|
||||
*/
|
||||
export const getVisitName = (document: Document) => () => document.title;
|
||||
export const getVisitName =
|
||||
({ rootPath = 'catalog', document = global.document } = {}) =>
|
||||
({ pathname }: { pathname: string }) => {
|
||||
const regex = new RegExp(
|
||||
`^\/${rootPath}\/(?<namespace>[^\/]+)\/(?<kind>[^\/]+)\/(?<name>[^\/]+)`,
|
||||
);
|
||||
const result = regex.exec(pathname);
|
||||
if (result && result?.groups) return result.groups.name;
|
||||
return document.title;
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -76,7 +85,7 @@ export const VisitListener = ({
|
||||
const visitsApi = useApi(visitsApiRef);
|
||||
const { pathname } = useLocation();
|
||||
const toEntityRefImpl = toEntityRef ?? getToEntityRef();
|
||||
const visitNameImpl = visitName ?? getVisitName(document);
|
||||
const visitNameImpl = visitName ?? getVisitName();
|
||||
useEffect(() => {
|
||||
// Wait for the browser to finish with paint with the assumption react
|
||||
// has finished with dom reconciliation.
|
||||
|
||||
Reference in New Issue
Block a user