Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
- change all || to ?? operator
- remove commenting redundant "no-console"
- remove dangling promises returns
- no ternal expressions on button clicks
-  include PORT to env validation
- remove unnecessary const assignments
- update tsconfig settings
  • Loading branch information
matyson committed Dec 6, 2024
1 parent 29facde commit 37b96b6
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ yarn-error.log*
# typescript
*.tsbuildinfo
dist/
.cache
5 changes: 2 additions & 3 deletions apps/spu-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.2.3",
"@sophys-web/eslint-config": "workspace:*",
"@sophys-web/tailwind-config": "workspace:*",
"@sophys-web/typescript-config": "workspace:*",
Expand All @@ -46,11 +45,11 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.18",
"eslint": "catalog:",
"jiti": "^2.4.0",
"postcss": "^8.4.35",
"tailwindcss": "catalog:",
"typescript": "catalog:",
"eslint": "catalog:"
"typescript": "catalog:"
},
"prettier": "@sophys-web/prettier-config"
}
2 changes: 1 addition & 1 deletion apps/spu-ui/src/app/_components/console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function ConsoleMessage({ message }: { message: ParsedLogMessage }) {
const formattedServiceName = (service: string) => {
if (service.includes("bluesky_queueserver.manager")) {
const splitNames = service.split(".");
return splitNames[splitNames.length - 1].toUpperCase();
return splitNames[splitNames.length - 1]?.toUpperCase() ?? "";
}
return service.toUpperCase();
};
Expand Down
2 changes: 1 addition & 1 deletion apps/spu-ui/src/app/_components/env-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function EnvMenu() {
if (status.isError) {
return "Error";
}
return status.data?.reState || "Unknown";
return status.data?.reState ?? "Unknown";
};

return (
Expand Down
6 changes: 5 additions & 1 deletion apps/spu-ui/src/app/_components/queue/queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ export function QueueControls() {
<Button
disabled={!status.data?.reState || status.data.itemsInQueue === 0}
onClick={() => {
status.data?.reState === "running" ? stopQueue() : startQueue();
if (status.data?.reState === "running") {
stopQueue();
} else {
startQueue();
}
}}
size="sm"
variant="default"
Expand Down
6 changes: 3 additions & 3 deletions apps/spu-ui/src/app/_components/run-engine-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type EngineAction = "pause" | "resume" | "stop" | "halt" | "abort";
export const getEngineStatus = (
reStateStr: string | null | undefined,
): EngineStatus => {
if (["idle", "running", "paused"].includes(reStateStr || "")) {
if (["idle", "running", "paused"].includes(reStateStr ?? "")) {
return reStateStr as EngineStatus;
}
return "unknown";
Expand Down Expand Up @@ -129,9 +129,9 @@ export function RunEngineControls() {
async (action: EngineAction) => {
const actionDetails = actionMap[action];
actionDetails.mutation.mutate(undefined, {
onSuccess: async () => {
onSuccess: () => {
toast.info(actionDetails.successMessage);
await utils.status.get.invalidate();
void utils.status.get.invalidate();
},
onError: (error) => {
toast.error(`Failed to ${action}: ${error.message}`);
Expand Down
4 changes: 4 additions & 0 deletions apps/spu-ui/src/app/_components/upload-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export function UploadButton(props: ButtonProps) {
const files = e.target.files;
if (!files) return;
const file = files[0];
if (!file) {
toast.error("No file selected");
return;
}
parse(file, {
header: true,
skipEmptyLines: true,
Expand Down
1 change: 0 additions & 1 deletion apps/spu-ui/src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const handler = auth(async (req) => {
headers: req.headers,
}),
onError({ error, path }) {
// eslint-disable-next-line no-console -- we want to log errors
console.error(`>>> tRPC Error on '${path}'`, error);
},
});
Expand Down
2 changes: 1 addition & 1 deletion apps/spu-ui/src/app/auth/signin/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function SignInForm() {

const onSubmit = async (data: z.infer<typeof FormSchema>) => {
toast.info("Signing in...");
const callbackUrl = params.get("callbackUrl") || "/";
const callbackUrl = params.get("callbackUrl") ?? "/";
const res = await signIn({
username: data.username,
password: data.password,
Expand Down
2 changes: 2 additions & 0 deletions apps/spu-ui/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const env = createEnv({
NODE_ENV: z
.enum(["development", "production", "test"])
.default("development"),
PORT: z.string().optional(),
COOLIFY_URL: z.string().url().optional(),
},
/**
Expand All @@ -28,6 +29,7 @@ export const env = createEnv({
*/
experimental__runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
PORT: process.env.PORT,
COOLIFY_URL: process.env.COOLIFY_URL,
NEXT_PUBLIC_BASE_PATH: process.env.NEXT_PUBLIC_BASE_PATH,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
Expand Down
5 changes: 2 additions & 3 deletions apps/spu-ui/src/lib/schemas/queue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { z } from "zod";
import { schemas } from "@sophys-web/api";
import type { schemas } from "@sophys-web/api";

const responseSchema = schemas.queue.getResponseSchema;
type QueueResponse = z.infer<typeof responseSchema>;
type QueueResponse = z.infer<typeof schemas.queue.getResponseSchema>;
export type QueueItem =
| QueueResponse["items"][number]
| QueueResponse["runningItem"];
8 changes: 3 additions & 5 deletions apps/spu-ui/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { z } from "zod";
import { schemas } from "@sophys-web/api";
import type { schemas } from "@sophys-web/api";

const itemSubmitSchema = schemas.item.addSubmit;
export type ItemSubmit = z.infer<typeof itemSubmitSchema>;
export type ItemSubmit = z.infer<typeof schemas.item.addSubmit>;

const queueResponseSchema = schemas.queue.getResponseSchema;
type QueueResponse = z.infer<typeof queueResponseSchema>;
type QueueResponse = z.infer<typeof schemas.queue.getResponseSchema>;
export type QueueItemProps =
| QueueResponse["items"][number]
| QueueResponse["runningItem"];
Expand Down
2 changes: 1 addition & 1 deletion apps/spu-ui/src/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ const getBaseUrl = () => {
if (typeof window !== "undefined")
return `${window.location.origin}${env.NEXT_PUBLIC_BASE_PATH}`;

return `http://localhost${env.NEXT_PUBLIC_BASE_PATH}:${process.env.PORT ?? 3000}`;
return `http://localhost${env.NEXT_PUBLIC_BASE_PATH}:${env.PORT ?? 3000}`;
};
21 changes: 15 additions & 6 deletions packages/api/src/router/console-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const consoleOutputRouter = {
if (chunk) {
const decoded = new TextDecoder().decode(chunk);
const messages = parseMessagesFromText(decoded);
for await (const message of messages) {
for (const message of messages) {
const innerMessage = parseInnerMessage(message.msg);
if (innerMessage) {
const id = nanoid();
Expand All @@ -49,11 +49,11 @@ type Message = z.infer<typeof MessageSchema>;
function parseMessagesFromText(input: string): Message[] {
const messageRegex = /(\{.*?\})(?=\{|\s*$)/g;

const matches = input.match(messageRegex) || [];
const matches = input.match(messageRegex) ?? [];

const parsedMessages = matches
.map((jsonStr) => {
const parsed = JSON.parse(jsonStr);
const parsed = JSON.parse(jsonStr) as unknown;
const result = MessageSchema.safeParse(parsed);
return result.success ? result.data : null;
})
Expand All @@ -62,27 +62,36 @@ function parseMessagesFromText(input: string): Message[] {
return parsedMessages;
}

type ParsedLogMessage = {
interface ParsedLogMessage {
logLevel: string;
date: string;
timestamp: string;
service: string;
textMessage: string;
};
}

function parseInnerMessage(message: string): ParsedLogMessage | null {
const innerMessageRegex = /^\[(.*?)\]\s*(.*)$/s;
const match = message.match(innerMessageRegex);
const match = innerMessageRegex.exec(message);

if (!match) {
console.error("Failed to parse inner message:", message);
return null;
}

const [, bracketContent, textMessage] = match;
if (!bracketContent) {
console.error("Failed to parse bracket content:", message);
return null;
}

const [logLevel, date, timestamp, service] = bracketContent.split(/\s+/);

if (!logLevel || !date || !timestamp || !service || !textMessage) {
console.error("Failed to parse bracket content:", message);
return null;
}

return {
logLevel,
date,
Expand Down
34 changes: 18 additions & 16 deletions packages/config-typescript/base.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"allowImportingTsExtensions": true,
"noEmit": true,
"inlineSources": false,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"target": "ES2022",
"lib": ["ES2022"],
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,

"incremental": true,
"disableSourceOfProjectReferenceRedirect": true,
"tsBuildInfoFile": "${configDir}/.cache/tsbuildinfo.json",

"strict": true,
"strictNullChecks": true
"noUncheckedIndexedAccess": true,
"checkJs": true,

"module": "Preserve",
"moduleResolution": "Bundler",
"noEmit": true
},
"exclude": ["node_modules"]
"exclude": ["node_modules", "build", "dist", ".next", ".expo"]
}
2 changes: 1 addition & 1 deletion packages/config-typescript/nextjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"declarationMap": false,
"incremental": true,
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": ["dom", "dom.iterable", "ES2022"],
"module": "esnext",
"resolveJsonModule": true,
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/config-typescript/react-library.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"display": "React Library",
"extends": "./base.json",
"compilerOptions": {
"lib": ["ES2015", "DOM"],
"lib": ["ES2022", "DOM"],
"module": "ESNext",
"target": "ES6",
"jsx": "react-jsx",
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 37b96b6

Please sign in to comment.