Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: soft delete #383

Merged
merged 30 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ded82a9
chore: test build
tomwisecodes Nov 21, 2024
b936de9
chore: types and storeis
tomwisecodes Nov 21, 2024
e46dd14
chore: add top files
tomwisecodes Nov 21, 2024
bb51c12
chore: add top files
tomwisecodes Nov 21, 2024
9a6315a
chore: add top files
tomwisecodes Nov 21, 2024
7eaaaf0
chore: add top files
tomwisecodes Nov 21, 2024
9a17719
chore: add top files
tomwisecodes Nov 21, 2024
45301fc
chore: add top files
tomwisecodes Nov 21, 2024
e570351
chore: add top files
tomwisecodes Nov 21, 2024
be9c517
chore: update the date
tomwisecodes Nov 21, 2024
af1e19e
chore: update test
tomwisecodes Nov 21, 2024
e1a9d6c
Merge branch 'main' into chore/tst-build
tomwisecodes Nov 21, 2024
a74693b
chore: fix story
tomwisecodes Nov 21, 2024
1718dd2
chore: playwright fix
tomwisecodes Nov 21, 2024
7af730f
feat: oak modal on the right hand side
tomwisecodes Nov 21, 2024
68b611f
chore: comments
tomwisecodes Nov 21, 2024
09c4ba9
chore: hide gleap
tomwisecodes Nov 25, 2024
6e246a9
chore: remove sentence case
tomwisecodes Nov 25, 2024
759700b
chore: focus on open
tomwisecodes Nov 25, 2024
73aca9f
chore: clear single chat
tomwisecodes Nov 25, 2024
29e3130
chore: clear chat history
tomwisecodes Nov 25, 2024
06d14fe
Merge branch 'main' into chore/tst-build
tomwisecodes Nov 25, 2024
359f99a
chore: change text
tomwisecodes Nov 26, 2024
2f29679
Merge branch 'chore/tst-build' into feat/soft-delete
tomwisecodes Nov 26, 2024
2e83b24
feat: add deleted at
tomwisecodes Nov 26, 2024
c94a356
Merge branch 'main' into feat/soft-delete
tomwisecodes Nov 26, 2024
aaae68e
feat: stop get chat from finding deleted chats
tomwisecodes Nov 26, 2024
2edb4c0
chore: center align text on clear chat dialogs on mobile
tomwisecodes Nov 26, 2024
d115b22
chore: migration
tomwisecodes Nov 26, 2024
0c32da6
Merge branch 'main' into feat/soft-delete
tomwisecodes Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function getChatById(
id: string,
): Promise<AilaPersistedChat | null> {
const session = await prisma?.appSession.findUnique({
where: { id },
where: { id, deletedAt: null },
});

if (!session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ const ClearChatHistory = ({
$justifyContent="center"
$gap="space-between-m"
>
<OakP>This will permanently delete all of your lesson history.</OakP>
<OakP $textAlign="center">
This will permanently delete all of your lesson history.
</OakP>
<ModalFooterButtons
closeDialog={handleCloseDialog}
actionButtonStates={handleDeleteChat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const ClearSingleChatFromChatHistory = ({
$gap="space-between-m"
$justifyContent="center"
>
<OakP>This will permanently delete this lesson.</OakP>
<OakP $textAlign="center">This will permanently delete this lesson.</OakP>
{isLoading ? (
<OakFlex $justifyContent="center" $alignItems="center">
<LoadingWheel />
Expand Down
4 changes: 4 additions & 0 deletions apps/nextjs/src/components/DialogControl/DialogContents.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useState } from "react";

import type { LooseLessonPlan } from "@oakai/aila/src/protocol/schema";
import {
OakModal,
OakModalCenter,
OakModalCenterBody,
type OakIconName,
Expand All @@ -8,6 +11,7 @@ import type { Message } from "ai";
import styled from "styled-components";

import type { DialogTypes } from "../AppComponents/Chat/Chat/types";
import { ChatHistory } from "../AppComponents/Chat/chat-history";
import { useDialog } from "../AppComponents/DialogContext";
import ClearChatHistory from "./ContentOptions/ClearChatHistory";
import ClearSingleChatFromChatHistory from "./ContentOptions/ClearSingleChatFromChatHistory";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class AilaPrismaPersistence extends AilaPersistence {
const appSession = await this._prisma.appSession.findFirst({
where: {
id,
deletedAt: null,
},
});

Expand Down
14 changes: 11 additions & 3 deletions packages/api/src/router/appSessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function getChat(id: string, prisma: PrismaClientWithAccelerate) {
const chatRecord = await prisma.appSession.findUnique({
where: {
id: id,
deletedAt: null,
},
});
if (!chatRecord) {
Expand Down Expand Up @@ -206,6 +207,7 @@ export const appSessionsRouter = router({
"app_sessions"
WHERE
"user_id" = ${userId} AND "app_id" = 'lesson-planner'
AND "deleted_at" IS NULL
ORDER BY
"updated_at" DESC
`;
Expand Down Expand Up @@ -246,22 +248,27 @@ export const appSessionsRouter = router({
const { userId } = ctx.auth;
const { id } = input;

await ctx.prisma.appSession.deleteMany({
await ctx.prisma.appSession.update({
where: {
id,
appId: "lesson-planner",
userId,
},
data: {
deletedAt: new Date(),
},
});
}),
deleteAllChats: protectedProcedure.mutation(async ({ ctx }) => {
const { userId } = ctx.auth;

await ctx.prisma.appSession.deleteMany({
await ctx.prisma.appSession.updateMany({
where: {
userId,
appId: "lesson-planner",
},
data: {
deletedAt: new Date(),
},
});
}),
shareChat: protectedProcedure
Expand All @@ -279,6 +286,7 @@ export const appSessionsRouter = router({
id,
userId,
appId: "lesson-planner",
deletedAt: null,
},
});

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/router/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const chatsRouter = router({
const { id } = input;

const session = await prisma?.appSession.findUnique({
where: { id },
where: { id, deletedAt: null },
});

if (!session) {
Expand All @@ -72,6 +72,7 @@ export const chatsRouter = router({
where: {
userId,
appId: "lesson-planner",
deletedAt: null,
},
});

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/models/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class Apps {
where: {
id: sessionId,
userId: userId,
deletedAt: null,
output: {
not: Prisma.AnyNull,
},
Expand All @@ -59,6 +60,7 @@ export class Apps {
return this.prisma.appSession.findMany({
where: {
userId: userId,
deletedAt: null,
output: {
not: Prisma.AnyNull,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

-- AlterTable
ALTER TABLE "public"."app_sessions" ADD COLUMN "deleted_at" TIMESTAMP(3);
5 changes: 3 additions & 2 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,15 @@ model AppSession {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

deletedAt DateTime? @map("deleted_at")

app App @relation(fields: [appId], references: [id], onDelete: Cascade)
appId String @map("app_id")

userId String @map("user_id") // The user that requested this generation

output Json? // The final output of the session

userTweaks UserTweak[]
reGenerations ReGeneration[]
generationUserFlags GenerationUserFlag[]
Expand Down
Loading