Skip to content

Commit

Permalink
More preparation for React Router v6 update
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanGreene authored and tekton-robot committed Sep 9, 2022
1 parent e9f7ce4 commit 9737cc4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
44 changes: 29 additions & 15 deletions src/containers/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ import {
import {
NamespaceContext,
useExtensions,
useIsReadOnly,
useLogoutURL,
useNamespaces,
useProperties,
Expand Down Expand Up @@ -157,7 +156,6 @@ export function App({ lang }) {
isFetching: isFetchingProperties,
isPlaceholderData: isPropertiesPlaceholder
} = useProperties();
const isReadOnly = useIsReadOnly();
const logoutURL = useLogoutURL();
const tenantNamespace = useTenantNamespace();

Expand Down Expand Up @@ -240,18 +238,25 @@ export function App({ lang }) {
>
<PageErrorBoundary>
<Switch>
<Redirect exact from="/" to={urls.about()} />
<Route
path="/"
exact
render={() => <Redirect to={urls.about()} />}
/>
<Route path={paths.pipelines.all()} exact>
<Pipelines />
</Route>
<Route path={paths.pipelines.byNamespace()} exact>
<Pipelines />
</Route>
<ReadWriteRoute
isReadOnly={isReadOnly}
<Route
path={paths.pipelineRuns.create()}
exact
component={CreatePipelineRun}
render={() => (
<ReadWriteRoute>
<CreatePipelineRun />
</ReadWriteRoute>
)}
/>
<Route path={paths.pipelineRuns.all()}>
<PipelineRuns />
Expand All @@ -274,11 +279,14 @@ export function App({ lang }) {
<Route path={paths.pipelineResources.byName()} exact>
<PipelineResource />
</Route>
<ReadWriteRoute
isReadOnly={isReadOnly}
<Route
path={paths.pipelineResources.create()}
exact
component={CreatePipelineResource}
render={() => (
<ReadWriteRoute>
<CreatePipelineResource />
</ReadWriteRoute>
)}
/>

<Route path={paths.tasks.all()} exact>
Expand All @@ -287,11 +295,14 @@ export function App({ lang }) {
<Route path={paths.tasks.byNamespace()} exact>
<Tasks />
</Route>
<ReadWriteRoute
isReadOnly={isReadOnly}
<Route
path={paths.taskRuns.create()}
exact
component={CreateTaskRun}
render={() => (
<ReadWriteRoute>
<CreateTaskRun />
</ReadWriteRoute>
)}
/>
<Route path={paths.taskRuns.all()}>
<TaskRuns />
Expand Down Expand Up @@ -327,10 +338,13 @@ export function App({ lang }) {
<Settings />
</Route>

<ReadWriteRoute
isReadOnly={isReadOnly}
<Route
path={paths.importResources()}
component={ImportResources}
render={() => (
<ReadWriteRoute>
<ImportResources />
</ReadWriteRoute>
)}
/>

<Route path={paths.eventListeners.all()} exact>
Expand Down
19 changes: 6 additions & 13 deletions src/containers/ReadWriteRoute/ReadWriteRoute.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020-2021 The Tekton Authors
Copyright 2020-2022 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -12,20 +12,13 @@ limitations under the License.
*/
/* istanbul ignore file */
import React from 'react';
import { Route } from 'react-router-dom';

import { useIsReadOnly } from '../../api';
import { NotFound } from '..';

const ReadWriteRoute = ({
component: Component,
exact,
isReadOnly,
path,
...rest
}) => (
<Route {...rest} exact={exact} path={path}>
{isReadOnly ? <NotFound /> : <Component />}
</Route>
);
const ReadWriteRoute = ({ children }) => {
const isReadOnly = useIsReadOnly();
return isReadOnly ? <NotFound /> : children;
};

export default ReadWriteRoute;

0 comments on commit 9737cc4

Please sign in to comment.