Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More preparation for React Router v6 update #2453

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;