Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ClockIcon,
DotsThreeOutlineVerticalIcon,
DownloadIcon,
ImageSquareIcon,
MagnifyingGlassIcon,
TrashIcon,
} from '@phosphor-icons/react';
Expand All @@ -32,7 +31,6 @@ import {
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Input } from '@/components/ui/input';
import { ScrollArea } from '@/components/ui/scroll-area';
import {
Sheet,
SheetContent,
Expand Down Expand Up @@ -66,10 +64,18 @@ function formatRelativeTime(timestamp: number): string {
const hours = Math.floor(diff / (1000 * 60 * 60));
const days = Math.floor(diff / (1000 * 60 * 60 * 24));

if (minutes < 1) return 'Just now';
if (minutes < 60) return `${minutes}m ago`;
if (hours < 24) return `${hours}h ago`;
if (days < 7) return `${days}d ago`;
if (minutes < 1) {
return 'Just now';
}
if (minutes < 60) {
return `${minutes}m ago`;
}
if (hours < 24) {
return `${hours}h ago`;
}
if (days < 7) {
return `${days}d ago`;
}
return new Date(timestamp).toLocaleDateString();
}

Expand All @@ -90,11 +96,11 @@ export function ChatHistorySheet({ isOpen, onClose }: ChatHistorySheetProps) {
const chats = await chatDB.getAllChats();

const chatsWithPreview = await Promise.all(
chats.map(async (chat: any) => {
chats.map(async (chat) => {
try {
const messages = await chatDB.getMessages(chat.websiteId);
const lastUserMessage = messages
.filter((m: any) => m.type === 'user')
.filter((m) => m.type === 'user')
.pop();

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client';

import { Robot } from '@phosphor-icons/react';
import React from 'react';

export function LoadingMessage() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export function useChat() {
const [model] = useAtom(modelAtom);
const [websiteId] = useAtom(websiteIdAtom);
const [websiteData] = useAtom(websiteDataAtom);
const [dateRange] = useAtom(dateRangeAtom);
const [messages, setMessages] = useAtom(messagesAtom);
const [inputValue, setInputValue] = useAtom(inputValueAtom);
const [isLoading, setIsLoading] = useAtom(isLoadingAtom);
Expand Down Expand Up @@ -124,9 +123,6 @@ export function useChat() {
}, 50);
}, [scrollAreaRef]);

const lastMessage = messages[messages.length - 1];
const lastMessageThinkingSteps = lastMessage?.thinkingSteps?.length || 0;

useEffect(() => {
scrollToBottom();
}, [scrollToBottom]);
Expand All @@ -143,7 +139,9 @@ export function useChat() {
const sendMessage = useCallback(
async (content?: string) => {
const messageContent = content || inputValue.trim();
if (!messageContent || isLoading || isRateLimited) return;
if (!messageContent || isLoading || isRateLimited) {
return;
}

const userMessage: Message = {
id: Date.now().toString(),
Expand Down Expand Up @@ -238,7 +236,9 @@ export function useChat() {
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
if (done) {
break;
}

const chunk = new TextDecoder().decode(value);
const lines = chunk.split('\n');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Enhanced Custom Tooltip for Error Chart
export const ErrorChartTooltip = ({ active, payload, label }: any) => {
if (!(active && payload && payload.length)) return null;
if (!(active && payload && payload.length)) {
return null;
}

return (
<div className="rounded-lg border border-border bg-background p-3 text-xs shadow-lg">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,31 @@ import {

// Get icon for error type
export const getErrorTypeIcon = (type: string) => {
if (!type) return <BugIcon className="h-4 w-4" size={16} weight="duotone" />;
if (!type) {
return <BugIcon className="h-4 w-4" size={16} weight="duotone" />;
}

const lowerType = type.toLowerCase();
if (lowerType.includes('react'))
if (lowerType.includes('react')) {
return <CodeIcon className="h-4 w-4" size={16} weight="duotone" />;
if (lowerType.includes('network'))
}
if (lowerType.includes('network')) {
return <NetworkIcon className="h-4 w-4" size={16} weight="duotone" />;
if (lowerType.includes('script'))
}
if (lowerType.includes('script')) {
return <FileCodeIcon className="h-4 w-4" size={16} weight="duotone" />;
if (lowerType.includes('syntax'))
}
if (lowerType.includes('syntax')) {
return <TerminalIcon className="h-4 w-4" size={16} weight="duotone" />;
}
return <BugIcon className="h-4 w-4" size={16} weight="duotone" />;
};

// Get device icon
export const getDeviceIcon = (deviceType: string) => {
if (!deviceType)
if (!deviceType) {
return <MonitorIcon className="h-4 w-4" size={16} weight="duotone" />;
}

switch (deviceType.toLowerCase()) {
case 'mobile':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ export const createErrorTypeColumns = () => [

export const createDeviceColumn = () =>
createNameColumn('Device Type', (name) => {
if (!name)
if (!name) {
return (
<MonitorIcon
className="h-4 w-4 text-gray-500"
size={16}
weight="duotone"
/>
);
}

const device = name.toLowerCase();
return device.includes('mobile') || device.includes('phone') ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ export const ErrorTrendsChart = ({ errorChartData }: ErrorTrendsChartProps) => {
axisLine={false}
tick={{ fontSize: 10, fill: 'var(--muted-foreground)' }}
tickFormatter={(value) => {
if (value >= 1_000_000)
if (value >= 1_000_000) {
return `${(value / 1_000_000).toFixed(1)}M`;
if (value >= 1000) return `${(value / 1000).toFixed(1)}k`;
}
if (value >= 1000) {
return `${(value / 1000).toFixed(1)}k`;
}
return value.toString();
}}
tickLine={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export const ErrorsPageContent = ({ params }: ErrorsPageContentProps) => {
// Add a new filter
const addFilter = (field: string, value: string | number) => {
// Prevent adding duplicate filters
if (activeFilters.some((f) => f.field === field && f.value === value))
if (activeFilters.some((f) => f.field === field && f.value === value)) {
return;
}

const newFilter: DynamicQueryFilter = { field, operator: 'eq', value };
setActiveFilters((prev) => [...prev, newFilter]);
Expand Down Expand Up @@ -182,7 +183,9 @@ export const ErrorsPageContent = ({ params }: ErrorsPageContentProps) => {

// Find the top error
const topError = useMemo(() => {
if (!processedData.error_types?.length) return null;
if (!processedData.error_types?.length) {
return null;
}

return processedData.error_types.reduce(
(max, error) => (error.count > max.count ? error : max),
Expand All @@ -192,7 +195,9 @@ export const ErrorsPageContent = ({ params }: ErrorsPageContentProps) => {

// Chart data for error trends
const errorChartData = useMemo(() => {
if (!processedData.error_trends?.length) return [];
if (!processedData.error_trends?.length) {
return [];
}

return processedData.error_trends.map((point: any) => ({
date: safeFormatDate(point.date, 'MMM d'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ interface TopErrorCardProps {
}

export const TopErrorCard = ({ topError }: TopErrorCardProps) => {
if (!topError) return null;
if (!topError) {
return null;
}

return (
<Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ import { format, isValid, parseISO } from 'date-fns';

// Helper function to safely parse dates
export const safeDateParse = (dateString: string): Date => {
if (!dateString) return new Date();
if (!dateString) {
return new Date();
}

let date = parseISO(dateString);
if (isValid(date)) return date;
if (isValid(date)) {
return date;
}

const isoString = dateString.replace(' ', 'T');
date = parseISO(isoString);
if (isValid(date)) return date;
if (isValid(date)) {
return date;
}

date = new Date(dateString);
if (isValid(date)) return date;
if (isValid(date)) {
return date;
}

console.warn('Failed to parse date:', dateString);
return new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export function EditFunnelDialog({
}, [funnel]);

const handleSubmit = async () => {
if (!formData) return;
if (!formData) {
return;
}

if (isCreateMode && onCreate) {
const createData: CreateFunnelData = {
Expand Down Expand Up @@ -132,7 +134,9 @@ export function EditFunnelDialog({
}, [isCreateMode]);

const addStep = useCallback(() => {
if (!formData) return;
if (!formData) {
return;
}
setFormData((prev) =>
prev
? {
Expand All @@ -148,7 +152,9 @@ export function EditFunnelDialog({

const removeStep = useCallback(
(index: number) => {
if (!formData || formData.steps.length <= 2) return;
if (!formData || formData.steps.length <= 2) {
return;
}
setFormData((prev) =>
prev
? {
Expand All @@ -163,7 +169,9 @@ export function EditFunnelDialog({

const updateStep = useCallback(
(index: number, field: keyof FunnelStep, value: string) => {
if (!formData) return;
if (!formData) {
return;
}
setFormData((prev) =>
prev
? {
Expand All @@ -180,13 +188,17 @@ export function EditFunnelDialog({

const reorderSteps = useCallback(
(result: DropResult) => {
if (!(result.destination && formData)) return;
if (!(result.destination && formData)) {
return;
}

const sourceIndex = result.source.index;
const destinationIndex = result.destination.index;

// No change needed
if (sourceIndex === destinationIndex) return;
if (sourceIndex === destinationIndex) {
return;
}

const items = [...formData.steps];
const [reorderedItem] = items.splice(sourceIndex, 1);
Expand All @@ -205,7 +217,9 @@ export function EditFunnelDialog({
);

const addFilter = useCallback(() => {
if (!formData) return;
if (!formData) {
return;
}
setFormData((prev) =>
prev
? {
Expand All @@ -221,7 +235,9 @@ export function EditFunnelDialog({

const removeFilter = useCallback(
(index: number) => {
if (!formData) return;
if (!formData) {
return;
}
setFormData((prev) =>
prev
? {
Expand All @@ -236,7 +252,9 @@ export function EditFunnelDialog({

const updateFilter = useCallback(
(index: number, field: keyof FunnelFilter, value: string) => {
if (!formData) return;
if (!formData) {
return;
}
setFormData((prev) =>
prev
? {
Expand Down Expand Up @@ -275,7 +293,9 @@ export function EditFunnelDialog({

const getSuggestions = useCallback(
(field: string): string[] => {
if (!autocompleteData) return [];
if (!autocompleteData) {
return [];
}

switch (field) {
case 'browser_name':
Expand All @@ -301,7 +321,9 @@ export function EditFunnelDialog({

const getStepSuggestions = useCallback(
(stepType: string): string[] => {
if (!autocompleteData) return [];
if (!autocompleteData) {
return [];
}

if (stepType === 'PAGE_VIEW') {
return autocompleteData.pagePaths || [];
Expand All @@ -324,15 +346,19 @@ export function EditFunnelDialog({

// Memoize form validation
const isFormValid = useMemo(() => {
if (!formData) return false;
if (!formData) {
return false;
}
return (
formData.name &&
!formData.steps.some((s) => !(s.name && s.target)) &&
!(formData.filters || []).some((f) => !f.value || f.value === '')
);
}, [formData]);

if (!formData) return null;
if (!formData) {
return null;
}

return (
<Sheet onOpenChange={handleClose} open={isOpen}>
Expand Down
Loading
Loading