diff --git a/.changeset/rare-pandas-hope.md b/.changeset/rare-pandas-hope.md new file mode 100644 index 0000000000..6e8e81fcfb --- /dev/null +++ b/.changeset/rare-pandas-hope.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-playlist': patch +--- + +Internal update to work with newer versions of react-router diff --git a/plugins/playlist/src/components/PlaylistPage/AddEntitiesDrawer.tsx b/plugins/playlist/src/components/PlaylistPage/AddEntitiesDrawer.tsx index 05dd4da231..fe08870bcd 100644 --- a/plugins/playlist/src/components/PlaylistPage/AddEntitiesDrawer.tsx +++ b/plugins/playlist/src/components/PlaylistPage/AddEntitiesDrawer.tsx @@ -102,12 +102,16 @@ export const AddEntitiesDrawer = ({ const entityRoute = useRouteRef(entityRouteRef); const entityLocationRegex = useMemo(() => { const forwardSlashRegex = new RegExp('/', 'g'); + // We need to do this in two steps, since entityRoute will ruin some special chars, like question marks const locationRegex = entityRoute({ - namespace: '(?.+?)', - kind: '(?.+?)', - name: '(?.+?)', - }).replace(forwardSlashRegex, '\\/'); - + namespace: '__REPLACE_WITH_NAMESPACE__', + kind: '__REPLACE_WITH_KIND__', + name: '__REPLACE_WITH_NAME__', + }) + .replace('__REPLACE_WITH_NAMESPACE__', '(?.+?)') + .replace('__REPLACE_WITH_KIND__', '(?.+?)') + .replace('__REPLACE_WITH_NAME__', '(?.+?)') + .replace(forwardSlashRegex, '\\/'); return new RegExp(`${locationRegex}$`); }, [entityRoute]); @@ -127,12 +131,12 @@ export const AddEntitiesDrawer = ({ const addEntity = useCallback( entityResult => { - // TODO (kuangp): this parsing of the location is not great. Ideally `CatalogEntityDocument` + // TODO(kuangp): this parsing of the location is not great. Ideally `CatalogEntityDocument` // contains the `metadata.name` field so we can derive the full ref and we only fall back to // parsing location if it's missing (ie. for older versions) - const { groups } = entityResult.location.match(entityLocationRegex); - if (groups) { - onAdd(stringifyEntityRef(groups)); + const match = entityResult.location.match(entityLocationRegex); + if (match?.groups) { + onAdd(stringifyEntityRef(match?.groups)); } else { // eslint-disable-next-line no-console console.error(