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 console and webinar related changes #300

Merged
merged 3 commits into from
Sep 27, 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
23 changes: 17 additions & 6 deletions gql-queries-generator/doc/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ query consoleListAllClusters($search: SearchCluster, $pagination: CursorPaginati
cursor
node {
accountName
ownedBy
clusterSvcCIDR
lastOnlineAt
createdBy {
Expand Down Expand Up @@ -2438,9 +2439,6 @@ query consoleGetPvc($clusterName: String!, $name: String!) {
namespace
}
resources {
claims {
name
}
limits
requests
}
Expand Down Expand Up @@ -2505,9 +2503,6 @@ query consoleListPvcs($clusterName: String!, $search: SearchPersistentVolumeClai
namespace
}
resources {
claims {
name
}
limits
requests
}
Expand Down Expand Up @@ -3386,6 +3381,7 @@ query consoleGetBYOKClusterInstructions($name: String!, $onlyHelmValues: Boolean
query consoleGetByokCluster($name: String!) {
infra_getBYOKCluster(name: $name) {
accountName
ownedBy
createdBy {
userEmail
userId
Expand Down Expand Up @@ -3430,6 +3426,7 @@ query consoleListByokClusters($search: SearchCluster, $pagination: CursorPaginat
cursor
node {
accountName
ownedBy
clusterSvcCIDR
lastOnlineAt
createdBy {
Expand Down Expand Up @@ -4489,6 +4486,20 @@ query consoleGetRegistryImageUrl {
}
}

query consoleSearchRegistryImages($query: String!) {
core_searchRegistryImages(query: $query) {
accountName
creationTime
id
imageName
imageTag
markedForDeletion
meta
recordVersion
updateTime
}
}

query consoleListRegistryImages($pq: CursorPaginationIn) {
core_listRegistryImages(pq: $pq) {
edges {
Expand Down
108 changes: 54 additions & 54 deletions src/apps/console/page-components/app/general.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { useParams } from '@remix-run/react';
import { useCallback, useEffect, useState } from 'react';
import { Checkbox } from '~/components/atoms/checkbox';
import { TextInput } from '~/components/atoms/input';
import Select from '~/components/atoms/select';
import { BottomNavigation } from '~/console/components/commons';
import { NameIdView } from '~/console/components/name-id-view';
import { useAppState } from '~/console/page-components/app-states';
import { FadeIn } from '~/console/page-components/util';
import { AppSelectItem } from '~/console/routes/_main+/$account+/env+/$environment+/new-app/app-detail';
import HandleBuild from '~/console/routes/_main+/$account+/repo+/$repo+/builds/handle-builds';
import { useConsoleApi } from '~/console/server/gql/api-provider';
import { parseName, parseNodes } from '~/console/server/r-utils/common';
import { parseName } from '~/console/server/r-utils/common';
import { keyconstants } from '~/console/server/r-utils/key-constants';
import { ensureAccountClientSide } from '~/console/server/utils/auth-utils';
import { constants } from '~/console/server/utils/constants';
import useDebounce from '~/root/lib/client/hooks/use-debounce';
import useForm, { dummyEvent } from '~/root/lib/client/hooks/use-form';
import { useUnsavedChanges } from '~/root/lib/client/hooks/use-unsaved-changes';
import Yup from '~/root/lib/server/helpers/yup';
Expand Down Expand Up @@ -63,28 +66,8 @@ import { handleError } from '~/root/lib/utils/common';
// return <ResourceExtraAction options={options} />;
// };

const AppSelectItem = ({
label,
value,
registry,
repository,
}: {
label: string;
value: string;
registry: string;
repository: string;
}) => {
return (
<div>
<div className="flex flex-col">
<div>{label}</div>
{registry !== '' && repository !== '' && (
<div className="bodySm text-text-soft">{`${registry}/${repository}`}</div>
)}
{/* <div className="bodySm text-text-soft">{value}</div> */}
</div>
</div>
);
const valueRenderer = ({ value }: { value: string }) => {
return <div>{value}</div>;
};

const AppGeneral = ({ mode = 'new' }: { mode: 'edit' | 'new' }) => {
Expand All @@ -109,38 +92,49 @@ const AppGeneral = ({ mode = 'new' }: { mode: 'edit' | 'new' }) => {

const [imageList, setImageList] = useState<any[]>([]);
const [imageLoaded, setImageLoaded] = useState(false);
const [imageSearchText, setImageSearchText] = useState('');

const getRegistryImages = useCallback(async () => {
ensureAccountClientSide(params);
setImageLoaded(true);
try {
const registrayImages = await api.listRegistryImages({});
const data = parseNodes(registrayImages.data).map((i) => ({
label: `${i.imageName}:${i.imageTag}`,
value: `${i.imageName}:${i.imageTag}`,
ready: true,
render: () => (
<AppSelectItem
label={`${i.imageName}:${i.imageTag}`}
value={`${i.imageName}:${i.imageTag}`}
registry={i.meta.registry || ''}
repository={i.meta.repository || ''}
/>
),
}));
setImageList(data);
} catch (err) {
handleError(err);
} finally {
setImageLoaded(false);
}
}, []);
const getRegistryImages = useCallback(
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider improving error handling in getRegistryImages function

The current error handling simply logs the error. Consider implementing more robust error handling, such as displaying an error message to the user or retrying the request.

  const getRegistryImages = useCallback(
    async ({ query }: { query: string }) => {
      try {
        ensureAccountClientSide(params);
        // ... rest of the function
      } catch (error) {
        console.error('Failed to fetch registry images:', error);
        // TODO: Implement user-facing error message
        // Consider adding a retry mechanism here
      }
    },
    [params]
  );

async ({ query }: { query: string }) => {
ensureAccountClientSide(params);
setImageLoaded(true);
try {
const registrayImages = await api.searchRegistryImages({ query });
const data = registrayImages.data.map((i) => ({
label: `${i.imageName}:${i.imageTag}/${i.meta.author}/${i.meta.registry}:${i.meta.repository}`,
value: `${i.imageName}:${i.imageTag}`,
ready: true,
render: () => (
<AppSelectItem
label={`${i.imageName}:${i.imageTag}`}
meta={i.meta}
imageSearchText={query}
/>
),
}));
setImageList(data);
} catch (err) {
handleError(err);
} finally {
setImageLoaded(false);
}
},
[]
);

useEffect(() => {
getRegistryImages();
getRegistryImages({ query: '' });
}, []);

// const api = useConsoleApi();
useDebounce(
() => {
if (imageSearchText) {
getRegistryImages({ query: imageSearchText });
}
},
300,
[imageSearchText]
);

const {
values,
Expand Down Expand Up @@ -317,25 +311,30 @@ const AppGeneral = ({ mode = 'new' }: { mode: 'edit' | 'new' }) => {
/>
)}
<div className="flex flex-col gap-xl">
<TextInput
{/* <TextInput
size="lg"
label="Image name"
placeholder="Enter Image name"
value={values.imageUrl}
onChange={handleChange('imageUrl')}
error={!!errors.imageUrl}
message={errors.imageUrl}
/>
{/* <Select
/> */}

<Select
label="Select Images"
size="lg"
value={values.imageUrl}
placeholder="Select a image"
creatable
searchable
options={async () => imageList}
onChange={({ value }) => {
handleChange('imageUrl')(dummyEvent(value));
}}
onSearch={(text) => {
setImageSearchText(text);
}}
showclear
noOptionMessage={
<div className="p-2xl bodyMd text-center">
Expand All @@ -346,7 +345,8 @@ const AppGeneral = ({ mode = 'new' }: { mode: 'edit' | 'new' }) => {
message={errors.imageUrl}
loading={imageLoaded}
createLabel="Select"
/> */}
valueRender={valueRenderer}
/>
</div>

<Checkbox
Expand Down
Loading
Loading