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

WEB: Add templated while account creation and fixes minor ui changes #307

Merged
merged 1 commit into from
Oct 2, 2024
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
10 changes: 6 additions & 4 deletions src/apps/console/routes/_a+/new-team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import MultiStepProgress, {
import MultiStepProgressWrapper from '~/console/components/multi-step-progress-wrapper';
import { NameIdView } from '~/console/components/name-id-view';
import { useConsoleApi } from '~/console/server/gql/api-provider';
import { ensureAccountClientSide } from '~/console/server/utils/auth-utils';
import { useExternalRedirect } from '~/root/lib/client/helpers/use-redirect';
import { useDataFromMatches } from '~/root/lib/client/hooks/use-custom-matches';
import useCustomSwr from '~/root/lib/client/hooks/use-custom-swr';
Expand Down Expand Up @@ -74,10 +75,11 @@ const NewAccount = () => {
if (_errors) {
throw _errors[0];
}
// const { errors: e } = await api.setupDefaultEnvironment({});
// if (e) {
// throw e[0];
// }
ensureAccountClientSide({ account: v.name });
const { errors: e } = await api.setupDefaultEnvironment({});
if (e) {
throw e[0];
}
toast.success('account created');
// navigate(`/onboarding/${v.name}/attach-new-cluster`);
navigate(`/${v.name}/environments`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ResourceExtraAction, {
IResourceExtraItem,
} from '~/console/components/resource-extra-action';
import { SyncStatusV2 } from '~/console/components/sync-status';
import { findClusterStatus } from '~/console/hooks/use-cluster-status';
import { useClusterStatusV2 } from '~/console/hooks/use-cluster-status-v2';
import { useConsoleApi } from '~/console/server/gql/api-provider';
import { IApps } from '~/console/server/gql/queries/app-queries';
Expand Down Expand Up @@ -304,7 +305,9 @@ const ListView = ({ items = [], onAction }: IResource) => {
},
],
rows: items.map((i) => {
// const isClusterOnline = clusterOnlineStatus[parseName(cluster)];
const isClusterOnline = findClusterStatus(
clusters[environment.clusterName]
);

const { name, id, updateInfo } = parseItem(i);
return {
Expand Down Expand Up @@ -332,9 +335,13 @@ const ListView = ({ items = [], onAction }: IResource) => {
return null;
}

// if (!isClusterOnline) {
// return <Badge type="warning">Cluster Offline</Badge>;
// }
if (environment.clusterName === '') {
return <ListItemV2 className="px-4xl" data="-" />;
}

if (!isClusterOnline) {
return <Badge type="warning">Cluster Offline</Badge>;
}

return <SyncStatusV2 item={i} />;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useParams } from '@remix-run/react';
import { useOutletContext, useParams } from '@remix-run/react';
import { useState } from 'react';
import { Badge } from '~/components/atoms/badge';
import { toast } from '~/components/molecule/toast';
Expand All @@ -16,6 +16,7 @@ import { LockSimple, Trash } from '~/console/components/icons';
import ListGridView from '~/console/components/list-grid-view';
import ListV2 from '~/console/components/listV2';
import ResourceExtraAction from '~/console/components/resource-extra-action';
import { findClusterStatus } from '~/console/hooks/use-cluster-status';
import { useClusterStatusV2 } from '~/console/hooks/use-cluster-status-v2';
import { useConsoleApi } from '~/console/server/gql/api-provider';
import { IImportedManagedResources } from '~/console/server/gql/queries/imported-managed-resource-queries';
Expand All @@ -29,6 +30,7 @@ import { getManagedTemplateLogo } from '~/console/utils/commons';
import { useReload } from '~/lib/client/helpers/reloader';
import { useWatchReload } from '~/lib/client/helpers/socket/useWatch';
import { handleError } from '~/lib/utils/common';
import { IEnvironmentContext } from '../_layout';
import { ViewSecret } from './handle-managed-resource-v2';

const RESOURCE_NAME = 'managed resource';
Expand Down Expand Up @@ -131,7 +133,7 @@ const GridView = ({ items = [], onAction, templates }: IResource) => {
};

const ListView = ({ items = [], onAction, templates }: IResource) => {
// const { cluster } = useOutletContext<IEnvironmentContext>();
const { environment } = useOutletContext<IEnvironmentContext>();
const { clusters } = useClusterStatusV2();

// const [clusterOnlineStatus, setClusterOnlineStatus] = useState<
Expand Down Expand Up @@ -193,6 +195,9 @@ const ListView = ({ items = [], onAction, templates }: IResource) => {
rows: items.map((i) => {
const { name, id, logo, updateInfo } = parseItem(i, templates);
// const isClusterOnline = clusterOnlineStatus[parseName(cluster)];
const isClusterOnline = findClusterStatus(
clusters[environment.clusterName]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider extracting cluster status check into a reusable function

The findClusterStatus(clusters[environment.clusterName]) pattern is repeated in multiple files. Consider creating a custom hook or utility function to encapsulate this logic, which would improve code reusability and maintainability.

const useClusterStatus = () => {
  const environment = useEnvironment();
  const clusters = useClusters();
  return useCallback(() => 
    findClusterStatus(clusters[environment.clusterName]),
    [clusters, environment.clusterName]
  );
};

// In the component:
const getClusterStatus = useClusterStatus();
const isClusterOnline = getClusterStatus();

);

return {
columns: {
Expand Down Expand Up @@ -227,9 +232,13 @@ const ListView = ({ items = [], onAction, templates }: IResource) => {
},
status: {
render: () => {
// if (!isClusterOnline) {
// return <Badge type="warning">Cluster Offline</Badge>;
// }
if (environment.clusterName === '') {
return <ListItemV2 className="px-4xl" data="-" />;
}

if (!isClusterOnline) {
return <Badge type="warning">Cluster Offline</Badge>;
}

if (i.syncStatus?.state === 'UPDATED_AT_AGENT') {
return <Badge type="info">Ready</Badge>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const ListView = ({ items, onAction }: IResource) => {
avatar={
i.clusterName === '' ? (
// <TemplateAvatar />
<TemplateAvatar name="{.}" color="text-white" />
<TemplateAvatar name="{ }" color="white" />
) : (
<ConsoleAvatar name={id} />
)
Expand Down
2 changes: 1 addition & 1 deletion src/design-system/components/atoms/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const AvatarBase = ({
'outline-none transition-all',
'rounded-full',
isTemplate
? 'border border-border-tertiary'
? 'border border-dashed border-border-tertiary'
: 'border border-border-default',
{
'w-8xl h-8xl': size === 'lg',
Expand Down
Loading