chore: more deprecations and reworking more routeRefs to subRouteRefs

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2021-10-27 11:52:28 +02:00
parent 8b21788e96
commit bd98d4f457
10 changed files with 66 additions and 58 deletions
@@ -17,7 +17,7 @@ import React from 'react';
import { Entity } from '@backstage/catalog-model';
import { useEntity } from '@backstage/plugin-catalog-react';
import { Routes, Route } from 'react-router';
import { rootRouteRef, buildRouteRef } from '../routes';
import { buildRouteRef } from '../routes';
import { WorkflowRunDetails } from './WorkflowRunDetails';
import { WorkflowRunsTable } from './WorkflowRunsTable';
import { GITHUB_ACTIONS_ANNOTATION } from './useProjectName';
@@ -41,12 +41,9 @@ export const Router = (_props: Props) => {
}
return (
<Routes>
<Route path="/" element={<WorkflowRunsTable entity={entity} />} />
<Route
path={`/${rootRouteRef.path}`}
element={<WorkflowRunsTable entity={entity} />}
/>
<Route
path={`/${buildRouteRef.path}`}
path={`${buildRouteRef.path}`}
element={<WorkflowRunDetails entity={entity} />}
/>
)
@@ -24,7 +24,7 @@ import {
} from '@material-ui/core';
import RetryIcon from '@material-ui/icons/Replay';
import GitHubIcon from '@material-ui/icons/GitHub';
import { Link as RouterLink, generatePath } from 'react-router-dom';
import { Link as RouterLink } from 'react-router-dom';
import { useWorkflowRuns, WorkflowRun } from '../useWorkflowRuns';
import { WorkflowRunStatus } from '../WorkflowRunStatus';
import SyncIcon from '@material-ui/icons/Sync';
@@ -34,7 +34,7 @@ import { Entity } from '@backstage/catalog-model';
import { readGitHubIntegrationConfigs } from '@backstage/integration';
import { EmptyState, Table, TableColumn } from '@backstage/core-components';
import { configApiRef, useApi } from '@backstage/core-plugin-api';
import { configApiRef, useApi, useRouteRef } from '@backstage/core-plugin-api';
const generatedColumns: TableColumn[] = [
{
@@ -47,14 +47,15 @@ const generatedColumns: TableColumn[] = [
title: 'Message',
field: 'message',
highlight: true,
render: (row: Partial<WorkflowRun>) => (
<Link
component={RouterLink}
to={generatePath(buildRouteRef.path, { id: row.id! })}
>
{row.message}
</Link>
),
render: (row: Partial<WorkflowRun>) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const routeLink = useRouteRef(buildRouteRef);
return (
<Link component={RouterLink} to={routeLink({ id: row.id! })}>
{row.message}
</Link>
);
},
},
{
title: 'Source',
+4 -3
View File
@@ -14,13 +14,14 @@
* limitations under the License.
*/
import { createRouteRef } from '@backstage/core-plugin-api';
import { createRouteRef, createSubRouteRef } from '@backstage/core-plugin-api';
export const rootRouteRef = createRouteRef({
id: 'github-actions',
});
export const buildRouteRef = createRouteRef({
export const buildRouteRef = createSubRouteRef({
id: 'github-actions/build',
params: ['id'],
path: '/:id',
parent: rootRouteRef,
});