Skip to content

Commit b2cecc5

Browse files
footahussein3
andauthored
Don't show clusters and templates permission errors if viewing apps/sources (#1509)
* Don't show clusters and templates permission erros if viewing apps/sources - Refactors away the Clusters and Templates contexts * Clusters is always a list * Review feedback, choose better prop name Co-authored-by: Ahmed Magdy <[email protected]>
1 parent 3695c79 commit b2cecc5

File tree

17 files changed

+104
-193
lines changed

17 files changed

+104
-193
lines changed

ui-cra/src/components/Applications/__tests__/index.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import { CoreClientContextProvider, theme } from '@weaveworks/weave-gitops';
66
import { QueryClient, QueryClientProvider } from 'react-query';
77
import { MemoryRouter } from 'react-router-dom';
88
import { ThemeProvider } from 'styled-components';
9-
import ClustersProvider from '../../../contexts/Clusters/Provider';
109
import EnterpriseClientProvider from '../../../contexts/EnterpriseClient/Provider';
1110
import NotificationsProvider from '../../../contexts/Notifications/Provider';
1211
import RequestContextProvider from '../../../contexts/Request';
13-
import TemplatesProvider from '../../../contexts/Templates/Provider';
1412
import { muiTheme } from '../../../muiTheme';
1513
import {
1614
CoreClientMock,
@@ -41,8 +39,6 @@ describe('Applications index test', () => {
4139
[CoreClientContextProvider, { api }],
4240
[MemoryRouter],
4341
[NotificationsProvider],
44-
[TemplatesProvider],
45-
[ClustersProvider],
4642
]);
4743
});
4844
it('renders table rows', async () => {

ui-cra/src/components/Clusters/ClusterDashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState } from 'react';
22
import styled from 'styled-components';
33
import { ThemeProvider } from '@material-ui/core/styles';
4-
import useClusters from '../../contexts/Clusters';
4+
import useClusters from '../../hooks/clusters';
55
import { PageTemplate } from '../Layout/PageTemplate';
66
import { SectionHeader } from '../Layout/SectionHeader';
77
import { useHistory, useRouteMatch } from 'react-router-dom';

ui-cra/src/components/Clusters/Create/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Grid from '@material-ui/core/Grid';
22
import { useParams } from 'react-router-dom';
3-
import useClusters from '../../../contexts/Clusters';
4-
import useTemplates from '../../../contexts/Templates';
3+
import useClusters from '../../../hooks/clusters';
4+
import useTemplates from '../../../hooks/templates';
55
import { ContentWrapper, Title } from '../../Layout/ContentWrapper';
66
import { PageTemplate } from '../../Layout/PageTemplate';
77
import { SectionHeader } from '../../Layout/SectionHeader';

ui-cra/src/components/Clusters/DashboardsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { FC } from 'react';
22
import styled from 'styled-components';
3-
import useClusters from './../../contexts/Clusters';
3+
import useClusters from '../../hooks/clusters';
44
import { List, ListItem } from '@material-ui/core';
55
import { GitopsClusterEnriched } from '../../types/custom';
66
import { isAllowedLink } from '@weaveworks/weave-gitops';

ui-cra/src/components/Clusters/Delete.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@material-ui/core';
99
import styled from 'styled-components';
1010
import { CloseIconButton } from '../../assets/img/close-icon-button';
11-
import useClusters from '../../contexts/Clusters';
11+
import useClusters from '../../hooks/clusters';
1212
import useNotifications from '../../contexts/Notifications';
1313
import { Input } from '../../utils/form';
1414
import { Loader } from '../Loader';
@@ -43,21 +43,21 @@ interface Props {
4343
formData: any;
4444
setFormData: Dispatch<React.SetStateAction<any>>;
4545
selectedCapiClusters: ClusterNamespacedName[];
46-
setOpenDeletePR: Dispatch<React.SetStateAction<boolean>>;
46+
onClose: () => void;
4747
prDefaults: PRDefaults;
4848
}
4949

5050
export const DeleteClusterDialog: FC<Props> = ({
5151
formData,
5252
setFormData,
5353
selectedCapiClusters,
54-
setOpenDeletePR,
54+
onClose,
5555
prDefaults,
5656
}) => {
5757
const [showAuthDialog, setShowAuthDialog] = useState(false);
5858
const [enableCreatePR, setEnableCreatePR] = useState<boolean>(false);
5959

60-
const { deleteCreatedClusters, loading, setSelectedClusters } = useClusters();
60+
const { deleteCreatedClusters, loading } = useClusters();
6161
const { setNotifications } = useNotifications();
6262

6363
const handleChangeBranchName = useCallback(
@@ -140,10 +140,9 @@ export const DeleteClusterDialog: FC<Props> = ({
140140
const cleanUp = useCallback(() => {
141141
clearCallbackState();
142142
setShowAuthDialog(false);
143-
setSelectedClusters([]);
144143
setFormData(prDefaults);
145-
setOpenDeletePR(false);
146-
}, [setSelectedClusters, setFormData, setOpenDeletePR, prDefaults]);
144+
onClose();
145+
}, [onClose, setFormData, prDefaults]);
147146

148147
return (
149148
<ThemeProvider theme={localEEMuiTheme}>

ui-cra/src/components/Clusters/Edit/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Grid from '@material-ui/core/Grid';
22
import { FC } from 'react';
33
import { Redirect, useParams } from 'react-router-dom';
4-
import useClusters from '../../../contexts/Clusters';
5-
import useTemplates from '../../../contexts/Templates';
4+
import useClusters from '../../../hooks/clusters';
5+
import useTemplates from '../../../hooks/templates';
66
import { GitopsClusterEnriched } from '../../../types/custom';
77
import { ContentWrapper, Title } from '../../Layout/ContentWrapper';
88
import { PageTemplate } from '../../Layout/PageTemplate';

ui-cra/src/components/Clusters/Form/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import useNotifications from '../../../contexts/Notifications';
2727
import useProfiles from '../../../contexts/Profiles';
2828
import ProfilesProvider from '../../../contexts/Profiles/Provider';
29-
import useTemplates from '../../../contexts/Templates';
29+
import useTemplates from '../../../hooks/templates';
3030
import { useListConfig } from '../../../hooks/versions';
3131
import { localEEMuiTheme } from '../../../muiTheme';
3232
import {

ui-cra/src/components/Clusters/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
2525
import { Link, useHistory } from 'react-router-dom';
2626
import styled from 'styled-components';
2727
import { ClusterNamespacedName } from '../../cluster-services/cluster_services.pb';
28-
import useClusters from '../../contexts/Clusters';
28+
import useClusters from '../../hooks/clusters';
2929
import useNotifications from '../../contexts/Notifications';
3030
import { useListConfig } from '../../hooks/versions';
3131
import { GitopsClusterEnriched, PRDefaults } from '../../types/custom';
@@ -197,11 +197,17 @@ interface FormData {
197197
}
198198

199199
const MCCP: FC = () => {
200-
const { clusters, isLoading, count, selectedClusters, setSelectedClusters } =
201-
useClusters();
200+
const { clusters, isLoading, count } = useClusters();
201+
const [selectedClusters, setSelectedClusters] = useState<
202+
ClusterNamespacedName[]
203+
>([]);
202204
const { setNotifications } = useNotifications();
203205
const [openConnectInfo, setOpenConnectInfo] = useState<boolean>(false);
204206
const [openDeletePR, setOpenDeletePR] = useState<boolean>(false);
207+
const handleClose = useCallback(() => {
208+
setOpenDeletePR(false);
209+
setSelectedClusters([]);
210+
}, [setOpenDeletePR, setSelectedClusters]);
205211
const { data, repoLink } = useListConfig();
206212
const repositoryURL = data?.repositoryURL || '';
207213
const capiClusters = useMemo(
@@ -399,7 +405,7 @@ const MCCP: FC = () => {
399405
formData={formData}
400406
setFormData={setFormData}
401407
selectedCapiClusters={selectedCapiClusters}
402-
setOpenDeletePR={setOpenDeletePR}
408+
onClose={handleClose}
403409
prDefaults={PRdefaults}
404410
/>
405411
)}

ui-cra/src/components/PolicyViolations/ViolationDetails/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ContentWrapper } from '../../Layout/ContentWrapper';
66
import { Alert } from '@material-ui/lab';
77
import { LoadingPage } from '@weaveworks/weave-gitops';
88
import ViolationDetails from './ViolationDetails';
9-
import useClusters from '../../../contexts/Clusters';
9+
import useClusters from '../../../hooks/clusters';
1010
import {
1111
useCountPolicyValidations,
1212
useGetPolicyValidationDetails,

ui-cra/src/components/PolicyViolations/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PageTemplate } from '../Layout/PageTemplate';
22
import { SectionHeader } from '../Layout/SectionHeader';
33
import { ContentWrapper } from '../Layout/ContentWrapper';
44
import { FieldsType, PolicyViolationsTable } from './Table';
5-
import useClusters from './../../contexts/Clusters';
5+
import useClusters from '../../hooks/clusters';
66
import { useListPolicyValidations } from '../../contexts/PolicyViolations';
77
import { Alert } from '@material-ui/lab';
88
import { LoadingPage } from '@weaveworks/weave-gitops';

0 commit comments

Comments
 (0)