Skip to content

Commit

Permalink
Merge pull request #165 from kloudlite/design
Browse files Browse the repository at this point in the history
Design
  • Loading branch information
tulsiojha authored Mar 21, 2024
2 parents 9f8be93 + eace51e commit 54de939
Show file tree
Hide file tree
Showing 13 changed files with 542 additions and 125 deletions.
68 changes: 46 additions & 22 deletions src/apps/console/components/commons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,41 +299,65 @@ export const ReviewComponent = ({
);
};

export const GitDetail = ({
export const GitDetailRaw = ({
provider,
repository,
branch,
onEdit,
}: {
provider: IGIT_PROVIDERS;
repository: string;
branch: string;
onEdit?: (step?: number) => void;
}) => {
const gitIconSize = 16;
return (
<ReviewComponent title="Source details" onEdit={() => onEdit?.(1)}>
<div className="flex flex-col p-xl gap-lg rounded border border-border-default flex-1 overflow-hidden">
<div className="flex flex-col gap-md">
<div className="bodyMd-medium text-text-default">Source</div>
<div className="flex flex-row items-center gap-3xl bodySm">
<div className="flex flex-row items-center gap-xl">
{provider === 'github' ? (
<GithubLogoFill size={gitIconSize} />
) : (
<GitlabLogoFill size={gitIconSize} />
)}
<span>
{repository.replace('https://', '').replace('.git', '')}
</span>
</div>
<div className="flex flex-row items-center gap-xl">
<GitBranchFill size={gitIconSize} />
<span>{branch}</span>
</div>
<div className="flex flex-col p-xl gap-lg rounded border border-border-default flex-1 overflow-hidden">
<div className="flex flex-col gap-md">
<div className="bodyMd-medium text-text-default">Source</div>
<div className="flex flex-row items-center gap-3xl bodySm">
<div className="flex flex-row items-center gap-xl">
{provider === 'github' ? (
<GithubLogoFill size={gitIconSize} />
) : (
<GitlabLogoFill size={gitIconSize} />
)}
<span>
{repository.replace('https://', '').replace('.git', '')}
</span>
</div>
<div className="flex flex-row items-center gap-xl">
<GitBranchFill size={gitIconSize} />
<span>{branch}</span>
</div>
</div>
</div>
</div>
);
};

export const GitDetail = ({
provider,
repository,
branch,
onEdit,
canEdit,
}: {
provider: IGIT_PROVIDERS;
repository: string;
branch: string;
onEdit?: (step?: number) => void;
canEdit?: boolean;
}) => {
return (
<ReviewComponent
title="Source details"
onEdit={() => onEdit?.(1)}
canEdit={canEdit}
>
<GitDetailRaw
branch={branch}
repository={repository}
provider={provider}
/>
</ReviewComponent>
);
};
32 changes: 32 additions & 0 deletions src/apps/console/components/extended-filled-tab-with-container.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ReactNode } from 'react';
import ExtendedFilledTab, { IExtendedFilledTab } from './extended-filled-tab';

interface IExtendedFilledTabWithContainer extends IExtendedFilledTab {
children?: ReactNode;
}
const ExtendedFilledTabWithContainer = ({
children,
items,
value,
size,
onChange,
}: IExtendedFilledTabWithContainer) => {
return (
<div className="flex flex-col rounded border border-border-default bg-surface-basic-default shadow-button overflow-hidden">
<div
className="py-xl px-3xl flex flex-row
items-center bg-surface-basic-subdued"
>
<ExtendedFilledTab
items={items}
value={value}
size={size}
onChange={onChange}
/>
</div>
<div className="p-3xl">{children}</div>
</div>
);
};

export default ExtendedFilledTabWithContainer;
13 changes: 5 additions & 8 deletions src/apps/console/components/extended-filled-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Tabs, { ITab } from '~/components/atoms/tabs';
import { cn } from '~/components/utils';
import { NonNullableString } from '~/root/lib/types/common';

interface IExtendedFilledTab<T = string> {
export interface IExtendedFilledTab<T = string> {
value: string;
onChange?: (item: T) => void;
items: ITab<T>[];
Expand All @@ -17,13 +17,10 @@ const ExtendedFilledTab = <T,>({
}: IExtendedFilledTab<T>) => {
return (
<div
className={cn(
'bg-surface-basic-active rounded border border-border-default inline-block w-fit',
{
'p-lg shadow-button': size === 'md',
'p-md': size === 'sm',
}
)}
className={cn('bg-surface-basic-active rounded inline-block w-fit', {
'p-lg shadow-button border border-border-default': size === 'md',
'p-md': size === 'sm',
})}
>
<Tabs.Root size="sm" variant="filled" value={value} onChange={onChange}>
{items.map((item) => (
Expand Down
6 changes: 4 additions & 2 deletions src/apps/console/components/git.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const Git = ({
loginUrls,
}: IGitRepoSelector) => {
const [showProviderOverlay, setShowProviderOverlay] = useState(
!logins?.providerGithub || !logins?.providerGitlab || false
!logins?.providerGithub && !logins?.providerGitlab
);

const {
Expand Down Expand Up @@ -299,7 +299,9 @@ const Git = ({
}
}
});
setLoading(false);
setTimeout(() => {
setLoading(false);
}, 200);
}, []);

useEffect(() => {
Expand Down
39 changes: 37 additions & 2 deletions src/apps/console/page-components/app-states.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { NonNullableString } from '~/root/lib/types/common';
import {
AppIn,
Github__Com___Kloudlite___Operator___Apis___Crds___V1__AppContainerIn as AppSpecContainersIn,
BuildIn,
} from '~/root/src/generated/gql/server';
import { mapper } from '~/components/utils';
import { parseNodes } from '~/console/server/r-utils/common';
// import logger from '~/root/lib/client/helpers/log';

const defaultApp: AppIn = {
metadata: {
Expand All @@ -27,6 +27,28 @@ const defaultApp: AppIn = {
displayName: '',
};

const defaultBuild: BuildIn = {
name: '',
source: {
branch: '',
provider: 'github',
repository: '',
},
buildClusterName: '',
spec: {
registry: {
repo: {
name: '',
tags: [],
},
},
resource: {
cpu: 500,
memoryInMb: 1000,
},
},
};

export type ISetState<T = any> = (fn: ((val: T) => T) | T) => void;
type ISetContainer<T = any> = (fn: ((val: T) => T) | T, index?: number) => void;

Expand All @@ -45,12 +67,14 @@ interface IappState {
envPage: createAppEnvPage;
page: number;
app: AppIn;
buildData?: BuildIn;
}

export const useAppState = () => {
const [state, setState] = useContext<ImmerHook<IappState>>(CreateAppContext);

const { app, page, envPage, activeContIndex, completePages } = state;
const { app, page, envPage, activeContIndex, completePages, buildData } =
state;

const getContainer = (index: number = activeContIndex) => {
if (!index) {
Expand Down Expand Up @@ -102,6 +126,14 @@ export const useAppState = () => {
});
};

const setBuildData: ISetState<BuildIn> = (fn) => {
if (typeof fn === 'function') {
setState((s) => ({ ...s, buildData: fn(s.buildData || defaultBuild) }));
} else {
setState((s) => ({ ...s, buildData: fn }));
}
};

const setPage: ISetState<number> = (fn) => {
if (typeof fn === 'function') {
setState((s) => ({ ...s, page: fn(s.page) }));
Expand Down Expand Up @@ -193,6 +225,7 @@ export const useAppState = () => {
completePages: {},
envPage: 'environment_variables',
activeContIndex: 0,
buildData: defaultBuild,
});
};

Expand Down Expand Up @@ -245,6 +278,8 @@ export const useAppState = () => {
getRepoMapper,
getRepoName,
getImageTag,
setBuildData,
buildData,
};
};

Expand Down
109 changes: 109 additions & 0 deletions src/apps/console/page-components/app/app-build-integration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { useOutletContext } from '@remix-run/react';
import { Checkbox } from '~/components/atoms/checkbox';
import { TextArea, TextInput } from '~/components/atoms/input';
import Git from '~/console/components/git';
import KeyValuePair from '~/console/components/key-value-pair';
import { IGIT_PROVIDERS } from '~/console/hooks/use-git';
import { IAppContext } from '~/console/routes/_main+/$account+/$project+/env+/$environment+/app+/$app+/_layout';
import { dummyEvent } from '~/root/lib/client/hooks/use-form';

const AppBuildIntegration = ({
values,
errors,
handleChange,
}: {
values: Record<string, any>;
errors: Record<string, any>;
handleChange: (key: string) => (e: { target: { value: any } }) => void;
}) => {
const { logins, loginUrls } = useOutletContext<IAppContext>();

return (
<div className="flex flex-col gap-3xl">
<Git
logins={logins}
loginUrls={loginUrls}
error={errors?.source}
onChange={(git) => {
handleChange('source')(
dummyEvent({
branch: git.branch,
repository: git.repo,
provider: git.provider,
})
);
}}
value={{
branch: values.source.branch,
repo: values.source.repository,
provider: (values.source.provider as IGIT_PROVIDERS) || 'github',
}}
/>

<Checkbox
label="Advance options"
checked={values.advanceOptions}
onChange={(check) => {
handleChange('advanceOptions')(dummyEvent(!!check));
}}
/>
{values.advanceOptions && (
<div className="flex flex-col gap-3xl">
<KeyValuePair
size="lg"
label="Build args"
value={Object.entries(values.buildArgs || {}).map(
([key, value]) => ({ key, value })
)}
onChange={(_, items) => {
handleChange('buildArgs')(dummyEvent(items));
}}
error={!!errors.buildArgs}
message={errors.buildArgs}
/>
<KeyValuePair
size="lg"
label="Build contexts"
value={Object.entries(values.buildContexts || {}).map(
([key, value]) => ({ key, value })
)}
onChange={(_, items) => {
handleChange('buildContexts')(dummyEvent(items));
}}
error={!!errors.buildContexts}
message={errors.buildContexts}
/>
<TextInput
size="lg"
placeholder="Enter context dir"
label="Context dir"
value={values.contextDir}
onChange={handleChange('contextDir')}
/>
<TextInput
size="lg"
placeholder="Enter docker file path"
label="Docker file path"
value={values.dockerfilePath}
onChange={handleChange('dockerfilePath')}
/>
<TextArea
placeholder="Enter docker file content"
label="Docker file content"
value={values.dockerfileContent}
onChange={handleChange('dockerfileContent')}
resize={false}
rows="6"
/>
{/* <BuildPlatforms */}
{/* onChange={(data) => { */}
{/* console.log(data); */}
{/* }} */}
{/* /> */}
</div>
)}
</div>
);
};

export default AppBuildIntegration;
Loading

0 comments on commit 54de939

Please sign in to comment.