Skip to content

[UI] Edit Cluster #1400

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

Merged
merged 30 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d79f5b4
Add edit cluster to Cluster Table - 1
AlinaGoaga Aug 30, 2022
13b5357
Merge branch 'main' of github.com:weaveworks/weave-gitops-enterprise …
AlinaGoaga Aug 31, 2022
243f375
Merge branch 'main' into edit-cluster
AlinaGoaga Aug 31, 2022
d6289a7
Merge branch 'edit-cluster' of github.com:weaveworks/weave-gitops-ent…
AlinaGoaga Aug 31, 2022
361e419
Clear active cluster and its data on nav away
AlinaGoaga Aug 31, 2022
4f91ced
Retrieve apps form cluster data
AlinaGoaga Aug 31, 2022
3cee944
Retrieve profiles from cluster data - WIP
AlinaGoaga Aug 31, 2022
18fc941
Merge branch 'main' into edit-cluster
AlinaGoaga Aug 31, 2022
74da68c
Allow only certain clusters to be editable
AlinaGoaga Aug 31, 2022
a024edc
Merge branch 'edit-cluster' of github.com:weaveworks/weave-gitops-ent…
AlinaGoaga Aug 31, 2022
40005b6
Merge branch 'main' into edit-cluster
AlinaGoaga Aug 31, 2022
087a1e3
Merge branch 'main' of github.com:weaveworks/weave-gitops-enterprise …
AlinaGoaga Aug 31, 2022
46636e1
Fix bug in profiles
AlinaGoaga Sep 1, 2022
f8b5ce1
Merge branch 'edit-cluster' of github.com:weaveworks/weave-gitops-ent…
AlinaGoaga Sep 1, 2022
822ad27
Update initialFormData for edit cluster
AlinaGoaga Sep 1, 2022
d84737b
Cleanup logs
AlinaGoaga Sep 1, 2022
e526d74
Merge branch 'main' into edit-cluster
AlinaGoaga Sep 1, 2022
ae14732
Get apps to show again
AlinaGoaga Sep 1, 2022
8ab2c8a
Merge branch 'edit-cluster' of github.com:weaveworks/weave-gitops-ent…
AlinaGoaga Sep 1, 2022
ba77c6c
Check base64 encode
AlinaGoaga Sep 1, 2022
bc10218
Merge branch 'main' into edit-cluster
AlinaGoaga Sep 1, 2022
4c0774a
Get profiles to update when we have an activeCluster
AlinaGoaga Sep 2, 2022
262f6cf
Merge branch 'main' into edit-cluster
foot Sep 5, 2022
0a815a4
Merge branch 'main' into edit-cluster
foot Sep 5, 2022
343b1eb
Merge branch 'main' into edit-cluster
foot Sep 5, 2022
5ef3a93
Merge branch 'main' into edit-cluster
foot Sep 5, 2022
23503cd
Adds Edit Cluster page
foot Sep 2, 2022
3033b86
Fix PR Preview
AlinaGoaga Sep 6, 2022
0d3724a
Hide filters and use cls name for Gitops again
AlinaGoaga Sep 6, 2022
c5adec0
Merge branch 'main' into edit-cluster
AlinaGoaga Sep 6, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const AppFields: FC<{
const handleSelectSource = (event: React.ChangeEvent<any>) => {
const { value } = event.target;
const { obj } = JSON.parse(value);
console.log(obj);

let currentAutomation = [...formData.clusterAutomations];

Expand All @@ -110,7 +109,7 @@ const AppFields: FC<{
clusterAutomations: currentAutomation,
});

if (JSON.parse(value).kind === 'HelmRepository') {
if (obj?.kind === 'HelmRepository') {
setHelmRepo({
name: obj?.metadata?.name,
namespace: obj?.metadata?.namespace,
Expand Down
75 changes: 36 additions & 39 deletions ui-cra/src/components/Applications/Add/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,46 @@ import { localEEMuiTheme } from '../../../muiTheme';
import { PageTemplate } from '../../Layout/PageTemplate';
import { SectionHeader } from '../../Layout/SectionHeader';
import { AddApplicationRequest, useApplicationsCount } from '../utils';
import GitOps from '../../Clusters/Create/Form/Partials/GitOps';
import GitOps from '../../Clusters/Form/Partials/GitOps';
import { Grid } from '@material-ui/core';
import { ContentWrapper } from '../../Layout/ContentWrapper';
import {
CallbackStateContextProvider,
clearCallbackState,
getCallbackState,
getProviderToken,
} from '@weaveworks/weave-gitops';
import { useHistory } from 'react-router-dom';
import { theme as weaveTheme } from '@weaveworks/weave-gitops';
import { isUnauthenticated, removeToken } from '../../../utils/request';
import useNotifications from '../../../contexts/Notifications';
import useProfiles from '../../../contexts/Profiles';
import { GitProvider } from '@weaveworks/weave-gitops/ui/lib/api/applications/applications.pb';
import { useListConfig } from '../../../hooks/versions';
import { PageRoute } from '@weaveworks/weave-gitops/ui/lib/types';
import AppFields from './form/Partials/AppFields';
import Profiles from '../../Clusters/Create/Form/Partials/Profiles';
import { UpdatedProfile } from '../../../types/custom';
import Profiles from '../../Clusters/Form/Partials/Profiles';
import ProfilesProvider from '../../../contexts/Profiles/Provider';
import { ClusterAutomation } from '../../../cluster-services/cluster_services.pb';
import useClusters from '../../../contexts/Clusters';
import { Loader } from '../../Loader';
import _ from 'lodash';
import useProfiles from '../../../contexts/Profiles';
import { useCallbackState } from '../../../utils/callback-state';
import { ProfilesIndex } from '../../../types/custom';

const AddApplication = () => {
const applicationsCount = useApplicationsCount();
const [loading, setLoading] = useState<boolean>(false);
const [showAuthDialog, setShowAuthDialog] = useState(false);
const history = useHistory();
const { setNotifications } = useNotifications();
const { profiles } = useProfiles();
const { data } = useListConfig();
const repositoryURL = data?.repositoryURL || '';
const authRedirectPage = `/applications/create`;
const { clusters, isLoading } = useClusters();

const random = useMemo(() => Math.random().toString(36).substring(7), []);

const callbackState = useCallbackState();

let initialFormData = {
url: '',
provider: '',
Expand All @@ -65,37 +66,28 @@ const AddApplication = () => {
source_type: '',
},
],
...callbackState?.state?.formData,
};

let initialProfiles = [] as UpdatedProfile[];
const [formData, setFormData] = useState<any>(initialFormData);

const callbackState = getCallbackState();
const { profiles, isLoading: profilesIsLoading } = useProfiles();
const [updatedProfiles, setUpdatedProfiles] = useState<ProfilesIndex>({});

if (callbackState) {
initialFormData = {
...initialFormData,
...callbackState.state.formData,
};
initialProfiles = [
...initialProfiles,
...callbackState.state.selectedProfiles,
];
}
const [formData, setFormData] = useState<any>(initialFormData);
const [selectedProfiles, setSelectedProfiles] =
useState<UpdatedProfile[]>(initialProfiles);
useEffect(() => {
setUpdatedProfiles({
..._.keyBy(profiles, 'name'),
...callbackState?.state?.updatedProfiles,
});
}, [callbackState?.state?.updatedProfiles, profiles]);

useEffect(() => {
if (repositoryURL != null) {
setFormData((prevState: any) => ({
...prevState,
url: repositoryURL,
}));
}
setFormData((prevState: any) => ({
...prevState,
url: repositoryURL,
}));
}, [repositoryURL]);

useEffect(() => clearCallbackState(), []);

useEffect(() => {
setFormData((prevState: any) => ({
...prevState,
Expand All @@ -107,9 +99,13 @@ const AddApplication = () => {

const handleAddApplication = useCallback(() => {
let clusterAutomations: ClusterAutomation[] = [];
const selectedProfilesList = _.sortBy(
Object.values(updatedProfiles),
'name',
).filter(p => p.selected);
if (formData.source_type === 'HelmRepository') {
for (let kustomization of formData.clusterAutomations) {
for (let profile of selectedProfiles) {
for (let profile of selectedProfilesList) {
let values: string = '';
let version: string = '';
for (let value of profile.values) {
Expand Down Expand Up @@ -213,7 +209,7 @@ const AddApplication = () => {
}
})
.finally(() => setLoading(false));
}, [formData, history, setNotifications, selectedProfiles]);
}, [formData, history, setNotifications, updatedProfiles]);

return useMemo(() => {
return (
Expand All @@ -224,7 +220,7 @@ const AddApplication = () => {
page: authRedirectPage as PageRoute,
state: {
formData,
selectedProfiles,
updatedProfiles,
},
}}
>
Expand Down Expand Up @@ -258,13 +254,13 @@ const AddApplication = () => {
)}
{isLoading && <Loader></Loader>}
</Grid>
{profiles.length > 0 &&
formData.source_type === 'HelmRepository' ? (
{formData.source_type === 'HelmRepository' ? (
<Profiles
// Temp fix to hide layers when using profiles in Add App until we update the BE
context="app"
selectedProfiles={selectedProfiles}
setSelectedProfiles={setSelectedProfiles}
isLoading={profilesIsLoading}
updatedProfiles={updatedProfiles}
setUpdatedProfiles={setUpdatedProfiles}
/>
) : null}
<Grid item xs={12} sm={10} md={10} lg={8}>
Expand All @@ -289,8 +285,9 @@ const AddApplication = () => {
formData,
handleAddApplication,
loading,
profiles.length,
selectedProfiles,
profilesIsLoading,
updatedProfiles,
setUpdatedProfiles,
showAuthDialog,
clusters,
isLoading,
Expand Down
Loading