fix null entry on new workspace

This commit is contained in:
timothycarambat 2025-05-08 08:34:37 -07:00
parent 10e65fc021
commit f40559b180
4 changed files with 11 additions and 13 deletions

View File

@ -1,9 +1,10 @@
import { DotsThreeVertical } from "@phosphor-icons/react";
import moment from "moment";
import { useRef, useState, useEffect } from "react";
import PromptHistory from "@/models/promptHistory";
import truncate from "truncate";
import { useTranslation } from "react-i18next";
import moment from "moment";
import truncate from "truncate";
const MAX_PROMPT_LENGTH = 200; // chars
export default function PromptHistoryItem({

View File

@ -1,10 +1,10 @@
import { useEffect, useState, forwardRef } from "react";
import PromptHistory from "@/models/promptHistory";
import { useTranslation } from "react-i18next";
import { X } from "@phosphor-icons/react";
import PromptHistory from "@/models/promptHistory";
import PromptHistoryItem from "./PromptHistoryItem";
import * as Skeleton from "react-loading-skeleton";
import "react-loading-skeleton/dist/skeleton.css";
import { useTranslation } from "react-i18next";
export default forwardRef(function ChatPromptHistory(
{ show, workspaceSlug, onRestore, onClose },

View File

@ -5,9 +5,9 @@ const PromptHistory = {
try {
const history = await prisma.prompt_history.create({
data: {
workspaceId,
prompt,
modifiedBy,
workspaceId: Number(workspaceId),
prompt: String(prompt),
modifiedBy: !!modifiedBy ? Number(modifiedBy) : null,
},
});
return { history, message: null };
@ -32,9 +32,7 @@ const PromptHistory = {
if (!workspaceId) return [];
try {
const history = await prisma.prompt_history.findMany({
where: {
workspaceId,
},
where: { workspaceId: Number(workspaceId) },
...(limit !== null ? { take: limit } : {}),
...(orderBy !== null
? { orderBy }
@ -79,9 +77,7 @@ const PromptHistory = {
delete: async function (clause = {}) {
try {
await prisma.prompt_history.deleteMany({
where: clause,
});
await prisma.prompt_history.deleteMany({ where: clause });
return true;
} catch (error) {
console.error(error.message);

View File

@ -449,6 +449,7 @@ const Workspace = {
_trackWorkspacePromptChange: async function (prevData, newData, user = null) {
if (
!!newData?.openAiPrompt && // new prompt is set
!!prevData?.openAiPrompt && // previous prompt was not null (default)
prevData?.openAiPrompt !== this.defaultPrompt && // previous prompt was not default
newData?.openAiPrompt !== prevData?.openAiPrompt // previous and new prompt are not the same
)