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

fix: Codemie loading, available clusters list #538

Merged
merged 1 commit into from
Jan 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export const DynamicDataContextProvider: React.FC = ({ children }) => {
namespace: getDefaultNamespace(),
});

const codemieSecret = codemieSecrets?.[0];

const DataContextValue = React.useMemo(
() => ({
codemieQuickLink: {
Expand All @@ -46,12 +44,12 @@ export const DynamicDataContextProvider: React.FC = ({ children }) => {
error: codemieQuickLinkError,
},
codemie: {
data: codemie,
data: codemie?.[0]?.jsonData,
isLoading: codemie === null,
error: codemieError,
},
codemieProject: {
data: codemieProject,
data: codemieProject?.[0]?.jsonData,
isLoading: codemieProject === null,
error: codemieProjectError,
},
Expand All @@ -66,7 +64,7 @@ export const DynamicDataContextProvider: React.FC = ({ children }) => {
error: codemieApplicationsError,
},
codemieSecret: {
data: codemieSecret,
data: codemieSecrets?.[0]?.jsonData,
isLoading: codemieSecrets === null,
error: codemieSecretsError,
},
Expand All @@ -82,7 +80,6 @@ export const DynamicDataContextProvider: React.FC = ({ children }) => {
codemieProjectSettingsError,
codemieQuickLink,
codemieQuickLinkError,
codemieSecret,
codemieSecrets,
codemieSecretsError,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { QuickLinkKubeObjectInterface } from '../../../../../../k8s/groups/EDP/Q
import { DataProviderValue } from '../../../../../../types/pages';

export interface DynamicDataContextProviderValue {
codemie: DataProviderValue<CodemieKubeObjectInterface[]>;
codemieProject: DataProviderValue<CodemieProjectKubeObjectInterface[]>;
codemie: DataProviderValue<CodemieKubeObjectInterface>;
codemieProject: DataProviderValue<CodemieProjectKubeObjectInterface>;
codemieProjectSettings: DataProviderValue<CodemieProjectSettingsKubeObjectInterface[]>;
codemieApplications: DataProviderValue<CodemieApplicationKubeObjectInterface[]>;
codemieSecret: DataProviderValue<SecretKubeObjectInterface>;
Expand Down
228 changes: 122 additions & 106 deletions src/pages/configuration/pages/codemie/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const PageView = () => {
return <ErrorContent error={forbiddenError} outlined />;
}

if (!codemie && !isLoading) {
if (!codemie.isLoading && !codemie.data && !codemieSecret.isLoading && !codemieSecret.data) {
return (
<>
<EmptyList
Expand All @@ -90,8 +90,8 @@ export const PageView = () => {

const ownerReference = codemieSecret.data?.metadata?.ownerReferences?.[0]?.kind;

const status = codemieProject.data?.[0]?.status?.value;
const statusError = codemieProject.data?.[0]?.status?.error;
const status = codemieProject.data?.status?.value;
const statusError = codemieProject.data?.status?.error;

const [icon, color] = CodemieKubeObject.getStatusIcon(status);

Expand Down Expand Up @@ -119,7 +119,7 @@ export const PageView = () => {
}
/>
</Grid>
<Grid item>{codemieProject.data?.[0]?.metadata.name}</Grid>
<Grid item>{codemieProject.data?.metadata.name}</Grid>
{!!ownerReference && (
<Grid item>
<Tooltip title={`Managed by ${ownerReference}`}>
Expand All @@ -139,7 +139,7 @@ export const PageView = () => {
<AccordionDetails>
<ManageCodeMie
quickLink={codemieQuickLink.data}
codemie={codemie.data?.[0]}
codemie={codemie.data}
codemieSecret={codemieSecret.data}
permissions={permissions}
handleClosePanel={handleCloseCreateDialog}
Expand All @@ -151,9 +151,9 @@ export const PageView = () => {
}, [
error,
codemie,
isLoading,
codemieSecret.data,
codemieSecret,
codemieProject.data,
isLoading,
codemieQuickLink.data,
permissions,
]);
Expand Down Expand Up @@ -238,7 +238,7 @@ export const PageView = () => {
component: (
<ManageCodeMie
quickLink={codemieQuickLink.data}
codemie={codemie.data?.[0]}
codemie={codemie.data}
codemieSecret={codemieSecret.data}
permissions={permissions}
handleClosePanel={handleCloseCreateDialog}
Expand Down Expand Up @@ -268,59 +268,67 @@ export const PageView = () => {
Project Settings
</Typography>
<LoadingWrapper isLoading={codemieProjectSettings.isLoading}>
<Grid container spacing={2}>
{codemieProjectSettings.data?.map((setting) => {
const status = setting?.status?.value;
const statusError = setting?.status?.error;
{codemieProjectSettings.data?.length ? (
<Grid container spacing={2}>
{codemieProjectSettings.data?.map((_setting) => {
const setting = _setting.jsonData;
const status = setting?.status?.value;
const statusError = setting?.status?.error;

const [icon, color] = CodemieProjectSettingsKubeObject.getStatusIcon(status);
const [icon, color] = CodemieProjectSettingsKubeObject.getStatusIcon(status);

return (
<Grid item xs={12} key={setting.metadata.name}>
<Paper
sx={{ p: (t) => `${t.typography.pxToRem(10)} ${t.typography.pxToRem(20)}` }}
>
<Stack
direction="row"
spacing={2}
alignItems="center"
justifyContent="space-between"
return (
<Grid item xs={12} key={setting.metadata.name}>
<Paper
sx={{ p: (t) => `${t.typography.pxToRem(10)} ${t.typography.pxToRem(20)}` }}
>
<Stack direction="row" spacing={2} alignItems="center">
<StatusIcon
icon={icon}
color={color}
Title={
<>
<Typography variant={'subtitle2'} style={{ fontWeight: 600 }}>
{`Status: ${status || 'Unknown'}`}
</Typography>
{!!statusError && (
<Typography variant={'subtitle2'} style={{ marginTop: rem(10) }}>
{statusError}
<Stack
direction="row"
spacing={2}
alignItems="center"
justifyContent="space-between"
>
<Stack direction="row" spacing={2} alignItems="center">
<StatusIcon
icon={icon}
color={color}
Title={
<>
<Typography variant={'subtitle2'} style={{ fontWeight: 600 }}>
{`Status: ${status || 'Unknown'}`}
</Typography>
)}
</>
}
/>
<Typography variant={'h6'}>{setting.metadata.name}</Typography>
{!!statusError && (
<Typography
variant={'subtitle2'}
style={{ marginTop: rem(10) }}
>
{statusError}
</Typography>
)}
</>
}
/>
<Typography variant={'h6'}>{setting.metadata.name}</Typography>
</Stack>
<Button
startIcon={<Icon icon={ICONS.PENCIL} />}
size="small"
component={'button'}
style={{ flexShrink: 0 }}
color="inherit"
onClick={() => handleOpenEditor(setting)}
>
Edit YAML
</Button>
</Stack>
<Button
startIcon={<Icon icon={ICONS.PENCIL} />}
size="small"
component={'button'}
style={{ flexShrink: 0 }}
color="inherit"
onClick={() => handleOpenEditor(setting)}
>
Edit YAML
</Button>
</Stack>
</Paper>
</Grid>
);
})}
</Grid>
</Paper>
</Grid>
);
})}
</Grid>
) : (
<EmptyList customText={'No CodeMie Project Settings Found.'} />
)}
</LoadingWrapper>
</Grid>
<Grid item xs={12} sx={{ pb: (t) => t.typography.pxToRem(40) }}>
Expand All @@ -332,66 +340,74 @@ export const PageView = () => {
Applications
</Typography>
<LoadingWrapper isLoading={codemieApplications.isLoading}>
<Grid container spacing={2}>
{codemieApplications.data?.map((application) => {
const status = application?.status?.value;
const statusError = application?.status?.error;
{codemieApplications.data?.length ? (
<Grid container spacing={2}>
{codemieApplications.data?.map((_application) => {
const application = _application.jsonData;
const status = application?.status?.value;
const statusError = application?.status?.error;

const [icon, color] = CodemieApplicationKubeObject.getStatusIcon(status);
const [icon, color] = CodemieApplicationKubeObject.getStatusIcon(status);

return (
<Grid item xs={12} key={application.metadata.name}>
<Paper
sx={{ p: (t) => `${t.typography.pxToRem(10)} ${t.typography.pxToRem(20)}` }}
>
<Stack
direction="row"
spacing={2}
alignItems="center"
justifyContent="space-between"
return (
<Grid item xs={12} key={application.metadata.name}>
<Paper
sx={{ p: (t) => `${t.typography.pxToRem(10)} ${t.typography.pxToRem(20)}` }}
>
<Stack direction="row" spacing={2} alignItems="center">
<StatusIcon
icon={icon}
color={color}
Title={
<>
<Typography variant={'subtitle2'} style={{ fontWeight: 600 }}>
{`Status: ${status || 'Unknown'}`}
</Typography>
{!!statusError && (
<Typography variant={'subtitle2'} style={{ marginTop: rem(10) }}>
{statusError}
<Stack
direction="row"
spacing={2}
alignItems="center"
justifyContent="space-between"
>
<Stack direction="row" spacing={2} alignItems="center">
<StatusIcon
icon={icon}
color={color}
Title={
<>
<Typography variant={'subtitle2'} style={{ fontWeight: 600 }}>
{`Status: ${status || 'Unknown'}`}
</Typography>
)}
</>
}
/>
<Typography variant={'h6'}>{application.metadata.name}</Typography>
{!!statusError && (
<Typography
variant={'subtitle2'}
style={{ marginTop: rem(10) }}
>
{statusError}
</Typography>
)}
</>
}
/>
<Typography variant={'h6'}>{application.metadata.name}</Typography>
</Stack>
<Button
startIcon={<Icon icon={ICONS.PENCIL} />}
size="small"
component={'button'}
style={{ flexShrink: 0 }}
color="inherit"
onClick={() => handleOpenEditor(application)}
>
Edit YAML
</Button>
</Stack>
<Button
startIcon={<Icon icon={ICONS.PENCIL} />}
size="small"
component={'button'}
style={{ flexShrink: 0 }}
color="inherit"
onClick={() => handleOpenEditor(application)}
>
Edit YAML
</Button>
</Stack>
</Paper>
</Grid>
);
})}
</Grid>
</Paper>
</Grid>
);
})}
</Grid>
) : (
<EmptyList customText={'No CodeMie Applications Found.'} />
)}
</LoadingWrapper>
</Grid>
</Grid>
{editor.open && editor.data?.jsonData && (
{editor.open && editor.data && (
<EditorDialog
open={editor.open}
item={editor.data?.jsonData}
item={editor.data}
onClose={handleCloseEditor}
onSave={handleEditorSave}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import React from 'react';
import { useHistory } from 'react-router-dom';
import { DEFAULT_CLUSTER } from '../../../../../../constants/clusters';
import { EDP_USER_GUIDE } from '../../../../../../constants/urls';
import { useClusterSecretListQuery } from '../../../../../../k8s/groups/default/Secret/hooks/useClusterSecretListQuery';
import { EDP_CONFIG_CONFIG_MAP_NAME } from '../../../../../../k8s/groups/default/ConfigMap/constants';
import { useEDPConfigMapQuery } from '../../../../../../k8s/groups/default/ConfigMap/hooks/useEDPConfigMap';
import { routeClusters } from '../../../../../../pages/configuration/pages/clusters/route';
import { FormSelect } from '../../../../../../providers/Form/components/FormSelect';
import { useTypedFormContext } from '../../../hooks/useFormContext';
Expand All @@ -22,13 +23,20 @@ export const Cluster = () => {
formState: { errors },
} = useTypedFormContext();

const { data, isLoading } = useClusterSecretListQuery({});
const { data, isLoading } = useEDPConfigMapQuery({
props: {
name: EDP_CONFIG_CONFIG_MAP_NAME,
},
});

const clusterOptions = React.useMemo(() => {
if (isLoading || !data) {
return [defaultClusterOption];
}
const clusters = data?.items.map(({ metadata: { name } }) => ({

const availableClusters = data?.data?.available_clusters?.split(', ');

const clusters = availableClusters.map((name) => ({
label: name,
value: name,
}));
Expand Down
Loading