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/repo name #136

Merged
merged 5 commits into from
Mar 12, 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
2 changes: 1 addition & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tasks:
interactive: true
cmds:
- |
BASE_URL=dev.kloudlite.io
BASE_URL=gcp-production.kloudlite.io
COOKIE_DOMAIN=".kloudlite.io"
GATEWAY_URL="http://gateway.kloudlite.svc.cluster.local"
case {{.app}} in
Expand Down
2 changes: 1 addition & 1 deletion lib/client/helpers/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const logger = {
}

if (err) {
console.trace(err);
console.log(err);
if (!isDev) {
PostToHook(`\`\`\`${err}\`\`\``);
}
Expand Down
9 changes: 5 additions & 4 deletions src/apps/console/components/git.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ const githubInstallUrl = `https://github.com/apps/${githubAppName}/installations

const popupWindow = ({
url = '',
onClose = () => { },
onClose = () => {},
width = 800,
height = 500,
title = 'kloudlite',
}) => {
const frame = window.open(
url,
title,
`toolbar=no,scrollbars=yes,resizable=no,top=${window.screen.height / 2 - height / 2
`toolbar=no,scrollbars=yes,resizable=no,top=${
window.screen.height / 2 - height / 2
},left=${window.screen.width / 2 - width / 2},width=800,height=600`
);
const interval = setInterval(() => {
Expand All @@ -90,8 +91,8 @@ interface IBranch {

interface IListRenderer {
data:
| { name: string; updatedAt: any; private: true; url: string }[]
| undefined;
| { name: string; updatedAt: any; private: true; url: string }[]
| undefined;
onChange: (value: string) => void;
value: string;
isLoading?: boolean;
Expand Down
53 changes: 32 additions & 21 deletions src/apps/console/routes/_main+/$account+/repo+/$repo+/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ import {
import Breadcrum from '~/console/components/breadcrum';
import { CommonTabs } from '~/console/components/common-navbar-tabs';

import { IRemixCtx } from '~/root/lib/types/common';
import { IRemixCtx, LoaderResult } from '~/root/lib/types/common';
import { GQLServerHandler } from '~/console/server/gql/saved-queries';
import logger from '~/root/lib/client/helpers/log';
import { ILoginUrls, ILogins } from '~/console/server/gql/queries/git-queries';
import { IPackageContext } from '~/console/routes/_main+/$account+/packages+/_layout';

export interface IRepoContext extends IPackageContext {
logins: ILogins;
loginUrls: ILoginUrls;
}
const LocalBreadcrum = () => {
const { repo, account } = useParams();
const repoName = atob(repo || '');
const { account, repo } = useParams();
return (
<div className="flex flex-row items-center">
<Breadcrum.Button
Expand All @@ -44,16 +38,18 @@ const LocalBreadcrum = () => {
}
/>
<Breadcrum.Button
to={`/${account}/repo/${repoName}`}
to={`/${account}/repo/${repo}`}
LinkComponent={Link}
content={<span>{repoName}</span>}
content={<span>{atob(repo || '')}</span>}
/>
</div>
);
};

const Tabs = () => {
const { repo, account } = useParams();
const { account } = useParams();

const { repo } = useParams();
Comment on lines +50 to +52
Copy link

Choose a reason for hiding this comment

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

suggestion (code_refinement): It seems like useParams() is called twice consecutively to extract account and repo. Consider combining these into a single destructuring assignment for cleaner code and potentially better performance.

Suggested change
const { account } = useParams();
const { repo } = useParams();
const { account, repo } = useParams();

const iconSize = 16;
return (
<CommonTabs
Expand Down Expand Up @@ -103,14 +99,12 @@ const Tabs = () => {
/>
);
};
export const handle = () => {
return {
navbar: <Tabs />,
breadcrum: () => <LocalBreadcrum />,
};
};

export const loader = async (ctx: IRemixCtx) => {
const { repo } = ctx.params;

const repoName = atob(repo || '');

try {
const { data, errors } = await GQLServerHandler(ctx.request).getLogins({});

Expand All @@ -129,21 +123,38 @@ export const loader = async (ctx: IRemixCtx) => {
return {
loginUrls: e,
logins: data,
repoName,
};
} catch (err) {
logger.error(err);
}

const k: any = {};

return {
logins: k,
loginUrls: k,
repoName,
};
};

export const handle = () => {
return {
logins: {},
loginUrls: {},
navbar: <Tabs />,
breadcrum: () => <LocalBreadcrum />,
};
};

export interface IRepoContext extends IPackageContext {
logins: LoaderResult<typeof loader>['logins'];
loginUrls: LoaderResult<typeof loader>['loginUrls'];
repoName: LoaderResult<typeof loader>['repoName'];
}

const Repo = () => {
const rootContext = useOutletContext<IPackageContext>();
const { logins, loginUrls } = useLoaderData<typeof loader>();
return <Outlet context={{ ...rootContext, logins, loginUrls }} />;
const ctx = useLoaderData<typeof loader>();
return <Outlet context={{ ...rootContext, ...ctx }} />;
};

export default Repo;
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
XCircleFill,
} from '@jengaicons/react';
import dayjs from 'dayjs';
import { IAccountContext } from '../../../_layout';
import LogComp from '~/root/lib/client/components/logger';
import { IAccountContext } from '../../../_layout';

const RESOURCE_NAME = 'build run';
type BaseType = ExtractNodeType<IBuildRuns>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const loader = async (ctx: IRemixCtx) => {

const promise = pWrapper(async () => {
const { data, errors } = await GQLServerHandler(ctx.request).listBuildRuns({
repoName: repo,
repoName: atob(repo),
Copy link

Choose a reason for hiding this comment

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

suggestion (code_refinement): The use of atob for decoding repo parameter is consistent across multiple loaders. This is a good practice as it centralizes the decoding logic, making it easier to manage and understand. However, ensure that there's corresponding encoding logic wherever repo parameters are generated or redirected to maintain consistency.

Suggested change
repoName: atob(repo),
repoName: atob(repo),

pq: getPagination(ctx),
search: getSearch(ctx),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import logger from '~/root/lib/client/helpers/log';
import { IRemixCtx } from '~/root/lib/types/common';
import { Plus } from '@jengaicons/react';
import { Button } from '~/components/atoms/button';
import fake from '~/root/fake-data-generator/fake';
import BuildResources from './build-resources';
import HandleBuild from './handle-builds';
import Tools from './tools';
import fake from "~/root/fake-data-generator/fake";

export const loader = async (ctx: IRemixCtx) => {
const { repo } = ctx.params;
const promise = pWrapper(async () => {
ensureAccountSet(ctx);
const { data, errors } = await GQLServerHandler(ctx.request).listBuilds({
repoName: repo,
repoName: atob(repo),
pagination: getPagination(ctx),
search: getSearch(ctx),
});
Expand All @@ -44,10 +44,10 @@ const Builds = () => {
return (
<>
<LoadingComp
data={promise}
skeletonData={{
buildData: fake.ConsoleListBuildsQuery.cr_listBuilds as any,
}}
data={promise}
skeletonData={{
buildData: fake.ConsoleListBuildsQuery.cr_listBuilds as any,
}}
>
{({ buildData }) => {
const builds = buildData.edges?.map(({ node }) => node);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/destructuring-assignment */
import { IDialogBase } from '~/console/components/types.d';
import { useOutletContext, useParams } from '@remix-run/react';
import { useOutletContext } from '@remix-run/react';
import { Checkbox } from '~/components/atoms/checkbox';
import Select from '~/components/atoms/select';
import { toast } from '~/components/molecule/toast';
Expand Down Expand Up @@ -119,8 +119,6 @@ const Root = (props: IDialog) => {
totalSteps: 2,
});

const { repo } = useParams();

const isAdvanceOptions = (data: any) => {
if (!data) {
return false;
Expand Down Expand Up @@ -306,6 +304,7 @@ const Root = (props: IDialog) => {
}}
error={!!errors.buildClusterName || !!errorCluster}
message={
// eslint-disable-next-line no-nested-ternary
errors.buildClusterName
? errors.buildClusterName
: errorCluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ import { ensureAccountSet } from '~/console/server/utils/auth-utils';
import { getPagination, getSearch } from '~/console/server/utils/common';
import logger from '~/root/lib/client/helpers/log';
import { IRemixCtx } from '~/root/lib/types/common';
import SecondarySubHeader from '~/console/components/secondary-sub-header';
import fake from '~/root/fake-data-generator/fake';
import TagsResources from './tags-resources';
import Tools from './tools';
import fake from "~/root/fake-data-generator/fake";

export const loader = async (ctx: IRemixCtx) => {
const { repo } = ctx.params;

const promise = pWrapper(async () => {
ensureAccountSet(ctx);
const { data, errors } = await GQLServerHandler(ctx.request).listDigest({
repoName: atob(repo),
pagination: getPagination(ctx),
search: getSearch(ctx),
});

if (errors) {
logger.error(errors[0]);
throw errors[0];
Expand All @@ -38,10 +39,10 @@ const Images = () => {
const { promise } = useLoaderData<typeof loader>();
return (
<LoadingComp
data={promise}
skeletonData={{
tagsData: fake.ConsoleListDigestQuery.cr_listDigests as any,
}}
data={promise}
skeletonData={{
tagsData: fake.ConsoleListDigestQuery.cr_listDigests as any,
}}
>
{({ tagsData }) => {
const tags = tagsData.edges?.map(({ node }) => node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import Popup from '~/components/molecule/popup';
import CodeView from '~/console/components/code-view';
import { IDialog } from '~/console/components/types.d';
import { registryHost } from '~/root/lib/configs/base-url.cjs';
import { useOutletContext } from 'react-router-dom';
import { ISHADialogData } from './tags-resources';
import { IRepoContext } from '../_layout';

const SHADialog = ({ show, setShow }: IDialog<ISHADialogData>) => {
const { account, repo } = useParams();
const url = `${registryHost}/${account}/${repo}:${
const { account } = useParams();

const { repoName } = useOutletContext<IRepoContext>();

return null;
Comment on lines +14 to +16
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): The addition of return null; immediately after fetching repoName from the context effectively disables the SHADialog component. If this is intentional for temporary disabling, consider adding a comment to clarify. Otherwise, review the logic to ensure the component functions as expected.

Suggested change
const { repoName } = useOutletContext<IRepoContext>();
return null;
const { repoName } = useOutletContext<IRepoContext>();
// TODO: Temporarily returning null. Need to implement or fix the logic to utilize `repoName`.
// return null;


const url = `${registryHost}/${account}/${repoName}:${
show?.data?.tag ? show?.data?.tag : `@${show?.data?.sha}`
}`;
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const TagsResources = ({ items = [] }: { items: BaseType[] }) => {
}
}}
/>
<SHADialog show={showSHADialog} setShow={setShowSHADialog} />
{/* <SHADialog show={showSHADialog} setShow={setShowSHADialog} /> */}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import ExtendedFilledTab from '~/console/components/extended-filled-tab';
import { AnimatePresence, motion } from 'framer-motion';
import { FadeIn } from '~/console/page-components/util';



const ConfigureRepo = () => {
const [setting, setSetting] = useState('general');
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { useConsoleApi } from '~/console/server/gql/api-provider';
import Git from '~/console/components/git';
import { IGIT_PROVIDERS } from '~/console/hooks/use-git';
import { BottomNavigation } from '~/console/components/commons';
import { toast } from '~/components/molecule/toast';
import ReviewBuild from './review-build';
import BuildDetails from './build-details';
import { IRepoContext } from '../_layout';

const NewBuild = () => {
const { loginUrls, logins } = useOutletContext<IRepoContext>();
const { loginUrls, logins, repoName } = useOutletContext<IRepoContext>();

const navigate = useNavigate();

Expand All @@ -27,7 +28,6 @@ const NewBuild = () => {
});

const api = useConsoleApi();
const { repo } = useParams();

const { values, errors, handleSubmit, handleChange, isLoading } = useForm({
initialValues: {
Expand All @@ -40,7 +40,7 @@ const NewBuild = () => {
tags: [],
buildClusterName: '',
advanceOptions: false,
repository: repo || '',
repository: repoName || '',
buildArgs: {},
buildContexts: {},
contextDir: '',
Expand Down Expand Up @@ -69,8 +69,9 @@ const NewBuild = () => {
}),
}),
onSubmit: async (val) => {
if (!repo) {
throw new Error('Repository is required!.');
if (!repoName) {
toast.error('Repository is required!.');
return;
Comment on lines +72 to +74
Copy link

Choose a reason for hiding this comment

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

issue (code_refinement): Replacing the throw new Error with toast.error and a return statement changes the error handling flow. Ensure that this change aligns with the application's error handling strategy, especially in asynchronous operations where a thrown error might be caught by a higher-level error handler.

Suggested change
if (!repoName) {
toast.error('Repository is required!.');
return;
if (!repoName) {
toast.error('Repository is required!.');
return Promise.reject(new Error('Repository is required!.'));
}

}
const submit = async () => {
try {
Expand Down Expand Up @@ -115,21 +116,26 @@ const NewBuild = () => {
if (e) {
throw e[0];
}
navigate(`/${account}/repo/${repo}/builds`);
navigate(`/${account}/repo/${repoName}/builds`);
} catch (err) {
handleError(err);
}
};
switch (currentStep) {
case 1:
nextStep();
break;
case 2:
nextStep();
break;
default:
await submit();
break;

try {
switch (currentStep) {
case 1:
nextStep();
break;
case 2:
nextStep();
break;
default:
await submit();
break;
}
} catch (err) {
handleError(err);
}
},
});
Expand Down
Loading
Loading