@backstage/plugin-app 0.4.6-next.1 → 0.4.6-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @backstage/plugin-app
|
|
2
2
|
|
|
3
|
+
## 0.4.6-next.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a345820: The `app/routes` redirect config now supports path parameter substitution in the `to` target. Named params (`:userId`) and splat params (`*`) captured by the `from` path are replaced in the `to` string before navigating, making it possible to express redirects like:
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
app:
|
|
11
|
+
extensions:
|
|
12
|
+
- app/routes:
|
|
13
|
+
config:
|
|
14
|
+
redirects:
|
|
15
|
+
- from: /users/:userId
|
|
16
|
+
to: /profile/:userId
|
|
17
|
+
- from: /old-docs
|
|
18
|
+
to: /docs/*
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- @backstage/ui@0.15.0-next.3
|
|
23
|
+
|
|
3
24
|
## 0.4.6-next.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
import { createExtension, coreExtensionData, createExtensionInput, NotFoundErrorPage } from '@backstage/frontend-plugin-api';
|
|
4
|
-
import { useRoutes, Navigate } from 'react-router-dom';
|
|
4
|
+
import { useRoutes, useParams, Navigate } from 'react-router-dom';
|
|
5
5
|
|
|
6
|
+
function RedirectWithParams({ to }) {
|
|
7
|
+
const params = useParams();
|
|
8
|
+
let target = to;
|
|
9
|
+
for (const [name, value] of Object.entries(params)) {
|
|
10
|
+
target = target.replace(
|
|
11
|
+
name === "*" ? /\*/g : new RegExp(`:${name}\\b`, "g"),
|
|
12
|
+
value ?? ""
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return /* @__PURE__ */ jsx(Navigate, { to: target, replace: true });
|
|
16
|
+
}
|
|
6
17
|
const AppRoutes = createExtension({
|
|
7
18
|
name: "routes",
|
|
8
19
|
attachTo: { id: "app/layout", input: "content" },
|
|
@@ -28,7 +39,7 @@ const AppRoutes = createExtension({
|
|
|
28
39
|
const element = useRoutes([
|
|
29
40
|
...redirects.map((redirect) => ({
|
|
30
41
|
path: redirect.from === "/" ? redirect.from : `${redirect.from.replace(/\/$/, "")}/*`,
|
|
31
|
-
element: /* @__PURE__ */ jsx(
|
|
42
|
+
element: /* @__PURE__ */ jsx(RedirectWithParams, { to: redirect.to })
|
|
32
43
|
})),
|
|
33
44
|
...inputs.routes.map((route) => {
|
|
34
45
|
const routePath = route.get(coreExtensionData.routePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppRoutes.esm.js","sources":["../../src/extensions/AppRoutes.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { z } from 'zod/v4';\nimport {\n createExtension,\n coreExtensionData,\n createExtensionInput,\n NotFoundErrorPage,\n} from '@backstage/frontend-plugin-api';\nimport { Navigate, useRoutes } from 'react-router-dom';\n\nexport const AppRoutes = createExtension({\n name: 'routes',\n attachTo: { id: 'app/layout', input: 'content' },\n inputs: {\n routes: createExtensionInput([\n coreExtensionData.routePath,\n coreExtensionData.routeRef.optional(),\n coreExtensionData.reactElement,\n ]),\n },\n configSchema: {\n redirects: z\n .array(\n z.object({\n from: z.string(),\n to: z.string(),\n }),\n )\n .optional(),\n },\n output: [coreExtensionData.reactElement],\n factory({ inputs, config }) {\n const redirects = config.redirects ?? [];\n\n const Routes = () => {\n const element = useRoutes([\n ...redirects.map(redirect => ({\n path:\n redirect.from === '/'\n ? redirect.from\n : `${redirect.from.replace(/\\/$/, '')}/*`,\n element: <
|
|
1
|
+
{"version":3,"file":"AppRoutes.esm.js","sources":["../../src/extensions/AppRoutes.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { z } from 'zod/v4';\nimport {\n createExtension,\n coreExtensionData,\n createExtensionInput,\n NotFoundErrorPage,\n} from '@backstage/frontend-plugin-api';\nimport { Navigate, useParams, useRoutes } from 'react-router-dom';\n\nfunction RedirectWithParams({ to }: { to: string }) {\n const params = useParams() as Record<string, string>;\n let target = to;\n for (const [name, value] of Object.entries(params)) {\n // Use \\b (word boundary) for named params so that `:a` doesn't\n // accidentally match inside `:ab` when both are present.\n target = target.replace(\n name === '*' ? /\\*/g : new RegExp(`:${name}\\\\b`, 'g'),\n value ?? '',\n );\n }\n return <Navigate to={target} replace />;\n}\n\nexport const AppRoutes = createExtension({\n name: 'routes',\n attachTo: { id: 'app/layout', input: 'content' },\n inputs: {\n routes: createExtensionInput([\n coreExtensionData.routePath,\n coreExtensionData.routeRef.optional(),\n coreExtensionData.reactElement,\n ]),\n },\n configSchema: {\n redirects: z\n .array(\n z.object({\n from: z.string(),\n to: z.string(),\n }),\n )\n .optional(),\n },\n output: [coreExtensionData.reactElement],\n factory({ inputs, config }) {\n const redirects = config.redirects ?? [];\n\n const Routes = () => {\n const element = useRoutes([\n ...redirects.map(redirect => ({\n path:\n redirect.from === '/'\n ? redirect.from\n : `${redirect.from.replace(/\\/$/, '')}/*`,\n element: <RedirectWithParams to={redirect.to} />,\n })),\n ...inputs.routes.map(route => {\n const routePath = route.get(coreExtensionData.routePath);\n\n return {\n path:\n routePath === '/'\n ? routePath\n : `${routePath.replace(/\\/$/, '')}/*`,\n\n element: route.get(coreExtensionData.reactElement),\n };\n }),\n {\n path: '*',\n element: <NotFoundErrorPage />,\n },\n ]);\n\n return element;\n };\n\n return [coreExtensionData.reactElement(<Routes />)];\n },\n});\n"],"names":[],"mappings":";;;;;AAyBA,SAAS,kBAAA,CAAmB,EAAE,EAAA,EAAG,EAAmB;AAClD,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AAGlD,IAAA,MAAA,GAAS,MAAA,CAAO,OAAA;AAAA,MACd,IAAA,KAAS,MAAM,KAAA,GAAQ,IAAI,OAAO,CAAA,CAAA,EAAI,IAAI,OAAO,GAAG,CAAA;AAAA,MACpD,KAAA,IAAS;AAAA,KACX;AAAA,EACF;AACA,EAAA,uBAAO,GAAA,CAAC,QAAA,EAAA,EAAS,EAAA,EAAI,MAAA,EAAQ,SAAO,IAAA,EAAC,CAAA;AACvC;AAEO,MAAM,YAAY,eAAA,CAAgB;AAAA,EACvC,IAAA,EAAM,QAAA;AAAA,EACN,QAAA,EAAU,EAAE,EAAA,EAAI,YAAA,EAAc,OAAO,SAAA,EAAU;AAAA,EAC/C,MAAA,EAAQ;AAAA,IACN,QAAQ,oBAAA,CAAqB;AAAA,MAC3B,iBAAA,CAAkB,SAAA;AAAA,MAClB,iBAAA,CAAkB,SAAS,QAAA,EAAS;AAAA,MACpC,iBAAA,CAAkB;AAAA,KACnB;AAAA,GACH;AAAA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A,UACN,OAAA,sBAAU,iBAAA,EAAA,EAAkB;AAAA;AAC9B,OACD,CAAA;AAED,MAAA,OAAO,OAAA;AAAA,IACT,CAAA;AAEA,IAAA,OAAO,CAAC,iBAAA,CAAkB,YAAA,iBAAa,GAAA,CAAC,MAAA,EAAA,EAAO,CAAE,CAAC,CAAA;AAAA,EACpD;AACF,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-app",
|
|
3
|
-
"version": "0.4.6-next.
|
|
3
|
+
"version": "0.4.6-next.2",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "frontend-plugin",
|
|
6
6
|
"pluginId": "app",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"test": "backstage-cli package test"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@backstage/core-components": "0.18.10-next.
|
|
66
|
+
"@backstage/core-components": "0.18.10-next.1",
|
|
67
67
|
"@backstage/core-plugin-api": "1.12.6-next.1",
|
|
68
68
|
"@backstage/filter-predicates": "0.1.3-next.0",
|
|
69
69
|
"@backstage/frontend-plugin-api": "0.17.0-next.1",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@backstage/plugin-permission-react": "0.5.1-next.0",
|
|
73
73
|
"@backstage/theme": "0.7.3",
|
|
74
74
|
"@backstage/types": "1.2.2",
|
|
75
|
-
"@backstage/ui": "0.15.0-next.
|
|
75
|
+
"@backstage/ui": "0.15.0-next.3",
|
|
76
76
|
"@backstage/version-bridge": "1.0.12",
|
|
77
77
|
"@material-ui/core": "^4.9.13",
|
|
78
78
|
"@material-ui/icons": "^4.9.1",
|