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 { DotsThreeVertical } from "@phosphor-icons/react";
import moment from "moment";
import { useRef, useState, useEffect } from "react"; import { useRef, useState, useEffect } from "react";
import PromptHistory from "@/models/promptHistory"; import PromptHistory from "@/models/promptHistory";
import truncate from "truncate";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import moment from "moment";
import truncate from "truncate";
const MAX_PROMPT_LENGTH = 200; // chars const MAX_PROMPT_LENGTH = 200; // chars
export default function PromptHistoryItem({ export default function PromptHistoryItem({

View File

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

View File

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

View File

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