Skip to content

Commit

Permalink
Merge pull request #422 from Aeolun/feature/allow-linking-directly-to…
Browse files Browse the repository at this point in the history
…-build-id

feat: allow linking directly to a project/build-id combination
  • Loading branch information
agoldis committed Sep 8, 2021
2 parents 7a31951 + a4a2714 commit b4cb690
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/dashboard/src/root.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ApolloProvider } from '@apollo/client';
import { RunRedirect } from '@src/run/runsRedirect';
import { ThemeProvider } from 'bold-ui';
import React from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { Content, Footer, Header, Layout } from './components';
import { InstanceDetailsView } from './instance/instanceDetailsView';
import { client } from './lib/apolloClient';
Expand Down Expand Up @@ -61,7 +62,13 @@ export const Root = () => {
<Content>
<Route path="/" exact component={ProjectsView} />

<Route path="/:projectId+/runs" component={RunsView} />
<Switch>
<Route
path="/:projectId+/runs/:buildId"
component={RunRedirect}
/>
<Route path="/:projectId+/runs" component={RunsView} />
</Switch>
<Route path="/:projectId+/edit" component={ProjectEditView} />
<Route path="/run/:id" component={RunDetailsView} />
<Route
Expand Down
33 changes: 33 additions & 0 deletions packages/dashboard/src/run/runsRedirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useGetRunsFeed } from '@src/run/runsFeed/useGetRunFeed';
import React from 'react';
import { Redirect } from 'react-router';

type RunRedirectProps = {
match: {
params: {
projectId: string;
buildId: string;
};
};
};

export function RunRedirect({
match: {
params: { projectId, buildId },
},
}: RunRedirectProps) {
const [runsFeed, loadMore, loading, error] = useGetRunsFeed({
projectId,
search: buildId,
});

return !loading && runsFeed && runsFeed.runs.length > 0 ? (
<Redirect to={`/run/${runsFeed.runs[0].runId}`} />
) : loading ? (
<div>
Redirecting to run with build id {buildId} in {projectId}
</div>
) : (
<div>Associated run not found</div>
);
}

0 comments on commit b4cb690

Please sign in to comment.