Skip to content

Commit

Permalink
fix enums & other smaller issues
Browse files Browse the repository at this point in the history
  • Loading branch information
QcFe committed Nov 21, 2024
1 parent 9a6cf4e commit 0706b91
Show file tree
Hide file tree
Showing 16 changed files with 6,110 additions and 2,863 deletions.
27 changes: 27 additions & 0 deletions frontend/codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CodegenConfig } from '@graphql-codegen/cli';

const schemaUrl =
(process.env.GRAPHQL_URL || 'https://graphql.preprod.crownlabs.polito.it') +
'/schema';

const config: CodegenConfig = {
schema: {
[schemaUrl]: { handleAsSDL: true },
},
documents: ['./src/**/*.{graphql,ts}'],
generates: {
'./src/generated-types.tsx': {
config: {
preResolveTypes: true,
},
plugins: [
'typescript',
'typescript-operations',
'typescript-react-apollo',
],
},
},
config: {},
};

export default config;
12 changes: 0 additions & 12 deletions frontend/codegen.yml

This file was deleted.

14 changes: 6 additions & 8 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dependencies": {
"@ant-design/icons": "^4.6.2",
"@apollo/client": "^3.3.20",
"@apollo/react-hooks": "^4.0.0",
"@craco/craco": "^6.1.1",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
Expand All @@ -28,7 +27,7 @@
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"typescript": "^4.1.2",
"typescript": "^5.6.3",
"web-vitals": "^1.0.1",
"ws": "^8.2.2"
},
Expand All @@ -39,7 +38,7 @@
"prepare": "cd .. && husky install frontend/.husky",
"check-format-lint": "prettier --check **/*.{ts,tsx,js,jsx,json,css,graphql} && eslint . --ext .ts --ext .tsx --ext .js --ext .jsx --max-warnings=0",
"pre-commit": "lint-staged",
"generate": "curl https://graphql.preprod.crownlabs.polito.it/schema -o schema.graphql && graphql-codegen --config codegen.yml ; rm -f schema.graphql"
"generate": "graphql-codegen"
},
"eslintConfig": {
"extends": [
Expand Down Expand Up @@ -96,11 +95,10 @@
]
},
"devDependencies": {
"@graphql-codegen/cli": "1.21.6",
"@graphql-codegen/introspection": "1.18.2",
"@graphql-codegen/typescript": "1.22.4",
"@graphql-codegen/typescript-operations": "1.18.3",
"@graphql-codegen/typescript-react-apollo": "2.2.8",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/typescript": "^4.1.1",
"@graphql-codegen/typescript-operations": "^4.3.1",
"@graphql-codegen/typescript-react-apollo": "^4.3.2",
"@tailwindcss/postcss7-compat": "npm:@tailwindcss/postcss7-compat",
"autoprefixer": "^9",
"eslint-config-prettier": "^8.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ const RowInstanceActionsDropdown: FC<IRowInstanceActionsDropdownProps> = ({
};

const statusComponents = {
Ready: {
[Phase.Ready]: {
menuKey: 'stop',
menuIcon: <PoweroffOutlined style={font20px} />,
menuText: 'Stop',
},
Off: {
[Phase.Off]: {
menuKey: 'start',
menuIcon: <CaretRightOutlined style={font20px} />,
menuText: 'Start',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,36 @@ const RowInstanceStatus: FC<IRowInstanceStatusProps> = ({ ...props }) => {

const font20px = { fontSize: '20px' };
const statusIcon = {
Unknown: <WarningOutlined className="warning-color-fg" style={font20px} />,
CreationLoopBackoff: (
[Phase.Empty]: (
<WarningOutlined className="warning-color-fg" style={font20px} />
),
Running: <LoadingOutlined className="warning-color-fg" style={font20px} />,
Importing: (
[Phase.CreationLoopBackoff]: (
<WarningOutlined className="warning-color-fg" style={font20px} />
),
[Phase.Running]: (
<LoadingOutlined className="warning-color-fg" style={font20px} />
),
ResourceQuotaExceeded: (
[Phase.Importing]: (
<LoadingOutlined className="warning-color-fg" style={font20px} />
),
[Phase.ResourceQuotaExceeded]: (
<CloseCircleOutlined className="danger-color-fg" style={font20px} />
),
Ready: (
[Phase.Ready]: (
<CheckCircleOutlined className="success-color-fg" style={font20px} />
),
Failed: (
[Phase.Failed]: (
<CloseCircleOutlined className="danger-color-fg" style={font20px} />
),
Off: <PauseCircleOutlined className="warning-color-fg" style={font20px} />,
Starting: <LoadingOutlined className="warning-color-fg" style={font20px} />,
Stopping: <LoadingOutlined className="warning-color-fg" style={font20px} />,
[Phase.Off]: (
<PauseCircleOutlined className="warning-color-fg" style={font20px} />
),
[Phase.Starting]: (
<LoadingOutlined className="warning-color-fg" style={font20px} />
),
[Phase.Stopping]: (
<LoadingOutlined className="warning-color-fg" style={font20px} />
),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import Button from 'antd-button-color';
import {
CreateTemplateMutation,
EnvironmentType,
useWorkspaceTemplatesQuery,
} from '../../../generated-types';
import { FetchResult } from '@apollo/client';
Expand All @@ -24,7 +25,7 @@ export type Image = {
registry: string;
};

type Vmorcontainer = 'Container' | 'VM';
type Vmorcontainer = EnvironmentType.VirtualMachine | EnvironmentType.Container;

type Template = {
name?: string;
Expand Down Expand Up @@ -316,14 +317,16 @@ const ModalCreateTemplate: FC<IModalCreateTemplateProps> = ({ ...props }) => {
image: String(value),
registry: imageFound?.registry,
vmorcontainer:
imageFound?.vmorcontainer[0] ?? 'Container',
imageFound?.vmorcontainer[0] ??
EnvironmentType.Container,
persistent: false,
gui: true,
};
});
form.setFieldsValue({
image: value,
vmorcontainer: imageFound?.vmorcontainer[0] ?? 'Container',
vmorcontainer:
imageFound?.vmorcontainer[0] ?? EnvironmentType.Container,
});
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useCreateTemplateMutation,
useImagesQuery,
} from '../../../generated-types';
import { Workspace } from '../../../utils';
import { JSONDeepCopy, Workspace, WorkspaceRole } from '../../../utils';
import UserListLogic from '../../accountPage/UserListLogic/UserListLogic';
import Box from '../../common/Box';
import ModalCreateTemplate from '../ModalCreateTemplate';
Expand All @@ -24,7 +24,7 @@ export interface IWorkspaceContainerProps {

const getImages = (dataImages: ImagesQuery) => {
let images: Image[] = [];
dataImages?.imageList?.images?.forEach(i => {
JSONDeepCopy(dataImages?.imageList?.images)?.forEach(i => {
const registry = i?.spec?.registryName!;
const imagesRaw = i?.spec?.images;
imagesRaw?.forEach(ir => {
Expand All @@ -36,15 +36,15 @@ const getImages = (dataImages: ImagesQuery) => {
versionsInImageName = [
{
name: latestVersion,
vmorcontainer: ['VM'],
vmorcontainer: [EnvironmentType.VirtualMachine],
registry: registry!,
},
];
} else {
versionsInImageName = ir?.versions?.map(v => {
return {
name: `${ir?.name!}:${v}`,
vmorcontainer: ['Container'],
vmorcontainer: [EnvironmentType.Container],
registry: registry!,
};
})!;
Expand Down Expand Up @@ -122,7 +122,7 @@ const WorkspaceContainer: FC<IWorkspaceContainerProps> = ({ ...props }) => {
</p>
</div>
),
left: workspace.role === 'manager' && (
left: workspace.role === WorkspaceRole.manager && (
<div className="h-full flex justify-center items-center pl-10">
<Tooltip title="Manage users">
<Button
Expand All @@ -144,7 +144,7 @@ const WorkspaceContainer: FC<IWorkspaceContainerProps> = ({ ...props }) => {
</Tooltip>
</div>
),
right: workspace.role === 'manager' && (
right: workspace.role === WorkspaceRole.manager && (
<div className="h-full flex justify-center items-center pr-10">
<Tooltip title="Create template">
<Button
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/contexts/TenantContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ const TenantContextProvider: FC<PropsWithChildren<{}>> = props => {

const { loading, error, subscribeToMore } = useTenantQuery({
variables: { tenantId: userId ?? '' },
onCompleted: d => {
d!.tenant!.spec?.workspaces!.sort((a, b) =>
workspaceGetName(a!).localeCompare(workspaceGetName(b!))
skip: !userId,
onCompleted: data => {
const d = JSONDeepCopy(data);
d?.tenant?.spec?.workspaces?.sort((a, b) =>
workspaceGetName(a).localeCompare(workspaceGetName(b))
);
setData(JSONDeepCopy(d));
setData(d);
},
fetchPolicy: 'network-only',
onError: apolloErrorCatcher,
Expand All @@ -66,7 +68,7 @@ const TenantContextProvider: FC<PropsWithChildren<{}>> = props => {
});

useEffect(() => {
if (!loading && !error && !errorsQueue.length) {
if (userId && !loading && !error && !errorsQueue.length) {
const unsubscribe = subscribeToMore({
onError: makeErrorCatcher(ErrorTypes.GenericError),
variables: { tenantId: userId ?? '' },
Expand Down
Loading

0 comments on commit 0706b91

Please sign in to comment.