Skip to content

Commit

Permalink
fix: sonar maintain issues #4 (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefl authored Nov 28, 2024
1 parent 60ee010 commit eca0019
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import useAnalytics from "@/lib/analytics/useAnalytics";
import { useAtBottom } from "@/lib/hooks/use-at-bottom";
import { cn } from "@/lib/utils";

export function ButtonScrollToBottom({ className, ...props }: ButtonProps) {
export function ButtonScrollToBottom({
className,
...props
}: Readonly<ButtonProps>) {
const isAtBottom = useAtBottom();
const { trackEvent } = useAnalytics();
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface ButtonProps
readonly asChild?: boolean;
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
const Button = React.forwardRef<HTMLButtonElement, Readonly<ButtonProps>>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/components/AppComponents/GetInTouchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ const GetInTouchBox = () => {
</svg>
</div>
<p>
Can’t find what you need?{" "}
{"Can’t find what you need? "}
<a href={email} className="text-blue underline">
Get in touch
</a>
, we’d be happy to help.
{", we’d be happy to help."}
</p>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,37 @@ const Answers = ({
const [userIsEditing, setUserIsEditing] = useState(false);

return (
<>
<Box>
{!isLoading && (
<>
{questionRow.answers.map((answer, answerIdx) => {
return (
<Skeleton loaded={true} key={answer.value}>
<Flex direction="row" className="w-full">
<Box className="h-fit w-fit" mr="3" mt="2">
<Box className="flex scale-75 items-center justify-center rounded-full bg-pupilsHighlight p-6">
<Icon icon="tick" size="sm" />
</Box>
</Box>
<Box className="w-full max-w-[90%]">
<Answer
setUserIsEditing={setUserIsEditing}
questionIdx={questionIdx}
questionRow={questionRow}
state={state}
isLoading={isLoading}
userIsEditing={userIsEditing}
answerIdx={answerIdx}
dispatch={dispatch}
answer={answer}
/>
</Box>
</Flex>
</Skeleton>
);
})}
</>
)}
<Box>
{!isLoading &&
questionRow.answers.map((answer, answerIdx) => {
return (
<Skeleton loaded={true} key={answer.value}>
<Flex direction="row" className="w-full">
<Box className="h-fit w-fit" mr="3" mt="2">
<Box className="flex scale-75 items-center justify-center rounded-full bg-pupilsHighlight p-6">
<Icon icon="tick" size="sm" />
</Box>
</Box>
<Box className="w-full max-w-[90%]">
<Answer
setUserIsEditing={setUserIsEditing}
questionIdx={questionIdx}
questionRow={questionRow}
state={state}
isLoading={isLoading}
userIsEditing={userIsEditing}
answerIdx={answerIdx}
dispatch={dispatch}
answer={answer}
/>
</Box>
</Flex>
</Skeleton>
);
})}

{hasError && error && <GenerationErrorBox error={error} />}
</Box>
</>
{hasError && error && <GenerationErrorBox error={error} />}
</Box>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export const DownloadButton = ({
</Link>
<button
className="flex w-full items-center justify-start gap-15 hover:underline sm:hidden"
onClick={async () => {
onClick={() => {
const lessonTitle = lesson.title;
if (!lessonTitle) return;
mutateAsync({
void mutateAsync({
lessonTitle,
title,
link,
Expand All @@ -150,10 +150,14 @@ export const DownloadButton = ({
</div>
);
}

const downloadButtonClasses = downloadAvailable
? `border-opacity-100`
: ` border-opacity-40`;
return (
<>
<button
className={`flex items-center justify-between gap-9 rounded-md border-2 border-black px-14 py-10 ${downloadAvailable ? `border-opacity-100` : ` border-opacity-40`}`}
className={`flex items-center justify-between gap-9 rounded-md border-2 border-black px-14 py-10 ${downloadButtonClasses}`}
onClick={() => onClick()}
disabled={!downloadAvailable}
data-testid={dataTestId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ const CreatingChatDialog = ({
}
}, [isSubmitting, demo]);

const createAppSession = useCallback(async () => {
const createAppSession = useCallback(() => {
if (!submit) {
throw new Error("DemoInterstitialDialog requires a submit function");
}

setIsSubmitting(true);

try {
await submit();
submit();
} catch (error) {
log.error("Error creating demo lesson:", error);
setIsSubmitting(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const ReportContentDialog = ({
closeDialogWithPostHogDismiss();
}

async function onSubmit(e?: React.FormEvent<HTMLFormElement>) {
function onSubmit(
e?: React.FormEvent<HTMLFormElement> | React.MouseEvent<HTMLButtonElement>,
) {
log.info("submitting");
e?.preventDefault();
setUserHasSubmitted(true);
Expand All @@ -64,7 +66,7 @@ const ReportContentDialog = ({
<Flex className="h-full w-full" direction="column" justify="between">
<form
className="flex flex-col gap-14"
onSubmit={async (e) => {
onSubmit={(e) => {
e.preventDefault();
}}
>
Expand Down Expand Up @@ -95,7 +97,7 @@ const ReportContentDialog = ({

<ModalFooterButtons
actionButtonStates={() => (
<OakPrimaryButton onClick={() => onSubmit()}>
<OakPrimaryButton onClick={onSubmit}>
Submit feedback
</OakPrimaryButton>
)}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/router/lesson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const lessonRouter = router({
},
});

if (!res || !res.summaries[0]) {
if (!res?.summaries?.[0]) {
throw new TRPCError({
message: "Lesson not found",
code: "NOT_FOUND",
Expand Down Expand Up @@ -218,7 +218,7 @@ export const lessonRouter = router({
where: { lessonId: lesson.id, variant: "ORIGINAL" },
cacheStrategy: { ttl: 60 * 5, swr: 60 * 2 },
});
if (!transcript || !transcript.content) {
if (!transcript?.content) {
throw new TRPCError({
message: "Transcript not found",
code: "NOT_FOUND",
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/models/generations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import type {
Generation,
ModerationType,
Prisma,
PrismaClientWithAccelerate} from "@oakai/db";
import {
GenerationStatus
PrismaClientWithAccelerate,
} from "@oakai/db";
import { GenerationStatus } from "@oakai/db";
import type { StructuredLogger } from "@oakai/logger";
import { structuredLogger } from "@oakai/logger";
import type { Logger as InngestLogger } from "inngest/middleware/logger";
import { omit } from "remeda";
import { Md5 } from "ts-md5";

export type PromptInputs = {
[key: string]: unknown | undefined;
[key: string]: unknown;
fact?: string;
knowledge?: string;
transcript?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { StructuredLogger } from "@oakai/logger";
import { structuredLogger } from "@oakai/logger";
import type { Logger as InngestLogger } from "inngest/middleware/logger";
import { PromptTemplate } from "langchain/prompts";
import type { BaseMessage} from "langchain/schema";
import type { BaseMessage } from "langchain/schema";
import { SystemMessage } from "langchain/schema";
import untruncateJson from "untruncate-json";

Expand Down Expand Up @@ -196,7 +196,7 @@ export class LLMRefusalError extends Error {

constructor(message: string, meta: Partial<CompletionMeta>) {
super(message);
this.name = "LLMCompletionError";
this.name = "LLMRefusalError";
this.completionMeta = meta;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/rag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const log = aiLogger("rag");

export class RAG {
prisma: PrismaClientWithAccelerate;
private _chatMeta: OpenAICompletionWithLoggingOptions;
private readonly _chatMeta: OpenAICompletionWithLoggingOptions;
constructor(
prisma: PrismaClientWithAccelerate,
chatMeta: OpenAICompletionWithLoggingOptions,
Expand Down Expand Up @@ -776,7 +776,7 @@ Thank you and happy classifying!`;
topN: k,
});
const mostRelevantHydrated = rerank.results
.sort((a, b) => b.relevanceScore - a.relevanceScore)
.toSorted((a, b) => b.relevanceScore - a.relevanceScore)
.map((r) => {
const lessonPlan = lessonPlans[r.index];
if (!lessonPlan) {
Expand Down
3 changes: 1 addition & 2 deletions packages/db/scripts/import-export/validate_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ const validateCSV = (
}
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const [fk, refTable] of Object.entries(foreignKeys)) {
for (const fk of Object.keys(foreignKeys)) {
if (!foreignKeyCheck[fk]) {
foreignKeyCheck[fk] = new Set();
}
Expand Down

0 comments on commit eca0019

Please sign in to comment.