Skip to content

Commit

Permalink
ci: add UI typechecks
Browse files Browse the repository at this point in the history
Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com>
  • Loading branch information
Marvin9 committed Nov 18, 2024
1 parent c09fec4 commit 357f006
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 25 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}

lint-ui:
lint-and-typecheck-ui:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -65,6 +65,8 @@ jobs:
node-version: "22.8.0"
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- name: Run typecheck
run: make typecheck-ui
- name: Run linter
run: make lint-ui

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ lint-ui:
pnpm --dir=ui install --dev
pnpm --dir=ui run lint

.PHONY: typecheck-ui
typecheck-ui:
pnpm --dir=ui install
pnpm --dir=ui run typecheck

.PHONY: format-ui
format-ui:
pnpm --dir=ui install --dev
Expand Down
1 change: 1 addition & 0 deletions ui/src/features/common/code-editor/yaml-editor-lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const YamlEditor: FC<YamlEditorProps> = (props) => {
validate: true,
isKubernetes: true,
format: true,
// @ts-expect-error correct schema
schemas: schema && [
{
uri: `https://raw.githubusercontent.com/akuity/kargo/${__UI_VERSION__ && __UI_VERSION__ !== 'development' ? __UI_VERSION__ : 'main'}/ui/src/gen/schema/${resourceType || 'stages'}.kargo.akuity.io_v1alpha1.json`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { FieldContainer } from '@ui/features/common/form/field-container';
import { ModalComponentProps } from '@ui/features/common/modal/modal-context';
import { SegmentLabel } from '@ui/features/common/segment-label';
import { dnsRegex } from '@ui/features/common/utils';
import { Secret } from '@ui/gen/k8s.io/api/core/v1/generated_pb';
import {
createCredentials,
updateCredentials
} from '@ui/gen/service/v1alpha1/service-KargoService_connectquery';
import { Secret } from '@ui/gen/v1alpha1/types_pb';
import { zodValidators } from '@ui/utils/validators';

import { constructDefaults, labelForKey, typeLabel } from './utils';
Expand Down Expand Up @@ -151,6 +151,7 @@ export const CreateCredentialsModal = ({ project, onSuccess, editing, init, ...p
control={control}
>
{({ field }) => (
// @ts-expect-error repoUrlInRegex won't be here so no boolean only strings
<Input
{...field}
type={key === 'password' ? 'password' : 'text'}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/features/project/credentials/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { faAnchor, faQuestionCircle } from '@fortawesome/free-solid-svg-icons';

import { SegmentLabel } from '@ui/features/common/segment-label';
import { DESCRIPTION_ANNOTATION_KEY } from '@ui/features/common/utils';
import { Secret } from '@ui/gen/v1alpha1/types_pb';
import { Secret } from '@ui/gen/k8s.io/api/core/v1/generated_pb';

import { CredentialTypeLabelKey, CredentialsDataKey, CredentialsType } from './types';

Expand Down
6 changes: 4 additions & 2 deletions ui/src/features/project/list/project-list-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ export const ProjectListFilter = ({
const navigate = useNavigate();

const filteredProjects = data?.projects.filter((p) =>
p.metadata?.name.toLowerCase().includes(filter.toLowerCase())
p.metadata?.name?.toLowerCase().includes(filter.toLowerCase())
);

const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter' && filteredProjects?.length === 1) {
const selectedProject = filteredProjects[0].metadata?.name;
navigate(paths.project.replace(':name', selectedProject));
if (selectedProject) {
navigate(paths.project.replace(':name', selectedProject));
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const FreightIndicators = ({
style={{
width: '10px',
height: '10px',
backgroundColor: warehouseColorMap[freight?.warehouse || '']
backgroundColor: warehouseColorMap[freight?.origin?.name || '']
}}
onClick={(e) => {
e.stopPropagation();
Expand Down
38 changes: 20 additions & 18 deletions ui/src/features/project/pipelines/utils/useImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ export const useImages = (stages: Stage[]) => {
return useMemo(() => {
const images = new Map<string, Map<string, StageStyleMap>>();
stages.forEach((stage) => {
const len = stage.status?.history?.length || 0;
stage.status?.history?.forEach((freight, i) => {
freight.images?.forEach((image) => {
let repo = image.repoURL ? images.get(image.repoURL) : undefined;
if (!repo) {
repo = new Map<string, StageStyleMap>();
images.set(image.repoURL!, repo);
}
let curStages = image.tag ? repo.get(image.tag) : undefined;
if (!curStages) {
curStages = {} as StageStyleMap;
}
curStages[stage.metadata?.name as string] = {
opacity: 1 - i / len,
backgroundColor: stageColorMap[stage.metadata?.name as string]
};
repo.set(image.tag!, curStages);
});
const len = stage.status?.freightHistory?.length || 0;
stage.status?.freightHistory?.forEach((freight, i) => {
for (const warehouseValue of Object.values(freight?.items)) {
warehouseValue.images?.forEach((image) => {
let repo = image.repoURL ? images.get(image.repoURL) : undefined;
if (!repo) {
repo = new Map<string, StageStyleMap>();
images.set(image.repoURL!, repo);
}
let curStages = image.tag ? repo.get(image.tag) : undefined;
if (!curStages) {
curStages = {} as StageStyleMap;
}
curStages[stage.metadata?.name as string] = {
opacity: 1 - i / len,
backgroundColor: stageColorMap[stage.metadata?.name as string]
};
repo.set(image.tag!, curStages);
});
}
});

const existingImages = getCurrentFreight(stage).flatMap((freight) => freight.images || []);
Expand Down
3 changes: 2 additions & 1 deletion ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"@kargo-public/*": ["./public/*"]
}
},
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.tsx"]
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.tsx"],
"exclude": ["src/**/*.test.ts"]
}

0 comments on commit 357f006

Please sign in to comment.