Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added web/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"sql-formatter": "^15.6.6",
"tailwind-merge": "^2.5.5",
"tailwindcss-animate": "^1.0.7",
"uuid": "^13.0.0",
"vaul": "^1.1.2",
"vega-embed": "^7.0.2",
"vega-lite": "^6.2.0",
Expand Down
18 changes: 17 additions & 1 deletion web/src/components/dataset/unified-uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Dashboard from "@uppy/dashboard";
import GoogleDrive from "@uppy/google-drive";
import Url from "@uppy/url";
import AwsS3Multipart from "@uppy/aws-s3";
import { sanitizeAndUniquifyFilename } from "@/lib/utils/sanitize-filename";

// Import Uppy styles and our custom theme
import "@uppy/core/dist/style.min.css";
Expand Down Expand Up @@ -210,6 +211,22 @@ export const UnifiedUploader = forwardRef<
],
},
debug: process.env.NODE_ENV === "development",
onBeforeFileAdded: (currentFile) => {
setOriginalFileNameRef.current(currentFile.name || "");
const originalName = currentFile?.name || '';
const modifiedName = sanitizeAndUniquifyFilename(originalName);

const modifiedFile = {
...currentFile,
name: modifiedName, // Update the primary name
meta: {
...currentFile.meta,
name: modifiedName, // Also update meta name if needed by plugins
originalName: originalName, // Store original name in meta if needed later
},
};
return modifiedFile;
}
});

// Add Dashboard plugin with proper theme
Expand Down Expand Up @@ -260,7 +277,6 @@ export const UnifiedUploader = forwardRef<
try {
setSelectedFile(file);
setUploadError(null);
setOriginalFileNameRef.current(file.name || "");

// Detect file format
const format = detectFileFormat(
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/project/inline-project-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,21 @@ export function InlineProjectEditor({ project }: InlineProjectEditorProps) {
<CalendarIcon className="size-4" />
<span>Created:</span>
<span className="font-medium text-foreground">
{formatDate(project.createdAt)}
{formatDate(project.created_at)}
</span>
</div>
<div className="flex items-center gap-2 text-muted-foreground">
<CalendarIcon className="size-4" />
<span>Updated:</span>
<span className="font-medium text-foreground">
{formatDate(project.updatedAt)}
{formatDate(project.updated_at)}
</span>
</div>
<div className="flex items-center gap-2 text-muted-foreground">
<UserIcon className="size-4" />
<span>Created by:</span>
<span className="font-medium text-foreground">
{project.createdBy}
{project.created_by}
</span>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/project/project-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ export function ProjectCard({ project, onUpdate, onDelete }: ProjectCardProps) {
</span>
</div>

{project.createdAt && (
{project.created_at && (
<div className="flex items-center gap-1.5 text-sm text-muted-foreground">
<Calendar className="h-3.5 w-3.5" />
<span>
{format(new Date(project.createdAt), "MMM d, yyyy")}
{format(new Date(project.created_at), "MMM d, yyyy")}
</span>
</div>
)}
Expand Down
30 changes: 28 additions & 2 deletions web/src/hooks/use-chat-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useDatasetSql } from "@/lib/mutations/dataset/sql";
import { parseSqlError } from "@/lib/sql-error-utils";
import { useResultsPanelStore } from "@/lib/stores/results-panel-store";
import type { GoPieUIMessage } from "@/types/chat-message";
import { useAuthStore } from "@/lib/stores/auth-store";

// Constants
const QUERY_INVALIDATION_DELAY_MS = 100; // Delay before invalidating queries to ensure smooth transition
Expand All @@ -31,6 +32,8 @@ export function useChatSession({
isNewChat = false,
}: UseChatSessionProps) {
const queryClient = useQueryClient();
const { organizationId } = useAuthStore();
const isAuthDisabled = String(process.env.NEXT_PUBLIC_ENABLE_AUTH).trim() !== "true";
const { selectChatForDataset } = useChatStore();
const { setIsOpen: setSqlPanelOpen, setResults: setSqlResults, setIsLoading: setSqlLoading, resetExecutedQueries } = useSqlStore();
const { clearPaths, setPaths: setVisualizationPaths } = useVisualizationStore();
Expand Down Expand Up @@ -64,7 +67,14 @@ export function useChatSession({

// Create a new chat when needed (for new chats)
useEffect(() => {
if (isNewChat && !selectedChatId && !chatId && !isPreparingChat && selectedContexts.length > 0) {
if (
isNewChat &&
(isAuthDisabled || organizationId) &&
!selectedChatId &&
!chatId &&
!isPreparingChat &&
selectedContexts.length > 0
) {
setIsPreparingChat(true);

// Clear any previous SQL results and visualizations when starting a new chat
Expand Down Expand Up @@ -115,7 +125,23 @@ export function useChatSession({
}
);
}
}, [isNewChat, selectedChatId, chatId, isPreparingChat, selectedContexts, createInitialChatMutation, selectChatForDataset, updateUrlWithChatId, resetExecutedQueries, clearPaths, setSqlResults, setSqlPanelOpen, setActiveTab]);
}, [
isNewChat,
organizationId,
selectedChatId,
chatId,
isPreparingChat,
selectedContexts,
createInitialChatMutation,
selectChatForDataset,
updateUrlWithChatId,
resetExecutedQueries,
clearPaths,
setSqlResults,
setSqlPanelOpen,
setActiveTab,
isAuthDisabled
]);

// Update chat ID when selectedChatId changes
useEffect(() => {
Expand Down
8 changes: 4 additions & 4 deletions web/src/lib/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export interface ProjectInput {

export interface Project extends ProjectInput {
id: string;
createdAt: string;
updatedAt: string;
created_at: string;
updated_at: string;
dataset_count: number;
createdBy: string;
updatedBy: string;
created_by: string;
updated_by: string;
custom_prompt?: string;
}

Expand Down
17 changes: 17 additions & 0 deletions web/src/lib/utils/sanitize-filename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { v4 as uuidv4 } from 'uuid';
/**
* Generates a unique filename using UUID while preserving the original extension.
* This prevents filename collisions and ensures safe storage.
*
* @param originalName - The original filename
* @returns A UUID-based filename in format: "uuid.extension"
* @example
* sanitizeAndUniquifyFilename("my-file.csv")
* // Returns: "550e8400-e29b-41d4-a716-446655440000.csv"
*/
export function sanitizeAndUniquifyFilename(originalName: string): string {
const uniqueId = uuidv4();
const extensionMatch = originalName.match(/\.[^.]+$/);
const extension = extensionMatch ? extensionMatch[0] : '';
return `${uniqueId}${extension}`;
}
Loading