Skip to content
Closed
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
37 changes: 32 additions & 5 deletions web/src/components/data-table/layout/data-table-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ For commercial licensing, please contact support@quantumnous.com
*/
import * as React from 'react'

import { ErrorState } from '@/components/error-state'
import { PageFooterPortal } from '@/components/layout/components/page-footer'
import { useMediaQuery } from '@/hooks'
import { cn } from '@/lib/utils'
Expand Down Expand Up @@ -92,6 +93,19 @@ export type DataTablePageProps<TData> = {
*/
isFetching?: boolean

/**
* Initial query error. When provided, replaces the table with a retryable
* error state. Consumers should omit this when stale data remains available.
*/
error?: unknown

/**
* Optional copy and retry action for the query error state.
*/
errorTitle?: string
errorDescription?: string
onRetry?: () => void

/**
* Empty-state title (used for both desktop {@link TableEmpty} and mobile fallback).
*/
Expand Down Expand Up @@ -310,6 +324,7 @@ export type DataTablePageProps<TData> = {
export function DataTablePage<TData>(props: DataTablePageProps<TData>) {
const isMobile = useMediaQuery('(max-width: 640px)')
const showMobile = isMobile && !props.hideMobile
const hasError = props.error !== undefined && props.error !== null

const [internalViewMode, setInternalViewMode] = useDataTableViewMode({
storageKey: props.viewModeStorageKey,
Expand All @@ -331,7 +346,7 @@ export function DataTablePage<TData>(props: DataTablePageProps<TData>) {
const toolbarNode = renderToolbar(props, viewToggle)
const mobileNode = renderMobile(props, showMobile, cardViewActive, viewMode)
const desktopNode = renderDesktop(props, showMobile, cardViewActive, viewMode)
const paginationNode = renderPagination(props)
const paginationNode = hasError ? null : renderPagination(props)

return (
<>
Expand All @@ -344,14 +359,26 @@ export function DataTablePage<TData>(props: DataTablePageProps<TData>) {
)}
>
{toolbarNode}
{mobileNode}
{desktopNode}
{props.afterTable}
{hasError ? (
<ErrorState
error={props.error}
title={props.errorTitle}
description={props.errorDescription}
onRetry={props.onRetry}
className='min-h-0 flex-1'
/>
) : (
<>
{mobileNode}
{desktopNode}
{props.afterTable}
</>
)}
</div>

{/* Bulk actions are typically a fixed-position toolbar; let the consumer
handle its own visibility, we just gate it to non-mobile. */}
{!showMobile && props.bulkActions}
{!hasError && !showMobile && props.bulkActions}

{paginationNode}
</>
Expand Down
17 changes: 11 additions & 6 deletions web/src/components/error-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import {
EmptyMedia,
EmptyTitle,
} from '@/components/ui/empty'
import { getHttpStatus } from '@/features/errors/general-error-status'
import { cn } from '@/lib/utils'

interface ErrorStateProps {
icon?: LucideIcon
error?: unknown
title?: string
description?: string
onRetry?: () => void
Expand All @@ -44,6 +46,13 @@ interface ErrorStateProps {
export function ErrorState(props: ErrorStateProps) {
const { t } = useTranslation()
const Icon = props.icon ?? AlertTriangle
const isRateLimited = getHttpStatus(props.error) === 429
const title = isRateLimited
? t('Too many requests')
: (props.title ?? t('Oops! Something went wrong'))
const description = isRateLimited
? t('Please wait a moment before trying again.')
: (props.description ?? t('Please try again later.'))

return (
<FadeIn>
Expand All @@ -52,12 +61,8 @@ export function ErrorState(props: ErrorStateProps) {
<EmptyMedia variant='icon'>
<Icon className='text-destructive size-6' />
</EmptyMedia>
<EmptyTitle>
{props.title ?? t('Oops! Something went wrong')}
</EmptyTitle>
{props.description != null && (
<EmptyDescription>{props.description}</EmptyDescription>
)}
<EmptyTitle>{title}</EmptyTitle>
<EmptyDescription>{description}</EmptyDescription>
</EmptyHeader>
<EmptyContent>
{props.onRetry != null && (
Expand Down
5 changes: 5 additions & 0 deletions web/src/features/about/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

For commercial licensing, please contact support@quantumnous.com
*/
import { t } from 'i18next'

import { api } from '@/lib/api'

import type { AboutResponse } from './types'

export async function getAboutContent() {
const res = await api.get<AboutResponse>('/api/about')
if (!res.data.success) {
throw new Error(res.data.message || t('Request failed') || 'Request failed')
}
return res.data
}
15 changes: 14 additions & 1 deletion web/src/features/about/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useQuery } from '@tanstack/react-query'
import { Construction } from 'lucide-react'
import { useTranslation } from 'react-i18next'

import { ErrorState } from '@/components/error-state'
import { PublicLayout } from '@/components/layout'
import { RichContent } from '@/components/rich-content'
import { Skeleton } from '@/components/ui/skeleton'
Expand Down Expand Up @@ -114,7 +115,7 @@ function EmptyAboutState() {

export function About() {
const { t } = useTranslation()
const { data, isLoading } = useQuery({
const { data, error, isError, isLoading, refetch } = useQuery({
queryKey: ['about-content'],
queryFn: getAboutContent,
})
Expand All @@ -137,6 +138,18 @@ export function About() {
)
}

if (isError && data === undefined) {
return (
<PublicLayout>
<ErrorState
error={error}
description={t('Please try again later.')}
onRetry={() => void refetch()}
/>
</PublicLayout>
)
}

if (!hasContent) {
return (
<PublicLayout>
Expand Down
91 changes: 48 additions & 43 deletions web/src/features/channels/components/channels-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function ChannelsTable() {

// Fetch channels data
// eslint-disable-next-line @tanstack/query/exhaustive-deps
const { data, isLoading, isFetching } = useQuery({
const { data, error, isError, isLoading, isFetching, refetch } = useQuery({
queryKey: channelsQueryKeys.list({
keyword: globalFilter,
model: modelFilter,
Expand All @@ -243,49 +243,52 @@ export function ChannelsTable() {
page_size: pagination.pageSize,
}),
queryFn: async () => {
if (shouldSearch) {
return searchChannels({
keyword: globalFilter,
model: modelFilter,
group:
groupFilter.length > 0 && !groupFilter.includes('all')
? groupFilter[0]
: undefined,
status:
statusFilter.length > 0 && !statusFilter.includes('all')
? statusFilter[0]
: undefined,
type:
typeFilter.length > 0 && !typeFilter.includes('all')
? Number(typeFilter[0])
: undefined,
tag_mode: enableTagMode,
id_sort: idSort,
...sortParams,
p: pagination.pageIndex + 1,
page_size: pagination.pageSize,
})
} else {
return getChannels({
group:
groupFilter.length > 0 && !groupFilter.includes('all')
? groupFilter[0]
: undefined,
status:
statusFilter.length > 0 && !statusFilter.includes('all')
? statusFilter[0]
: undefined,
type:
typeFilter.length > 0 && !typeFilter.includes('all')
? Number(typeFilter[0])
: undefined,
tag_mode: enableTagMode,
id_sort: idSort,
...sortParams,
p: pagination.pageIndex + 1,
page_size: pagination.pageSize,
})
const result = shouldSearch
? await searchChannels({
keyword: globalFilter,
model: modelFilter,
group:
groupFilter.length > 0 && !groupFilter.includes('all')
? groupFilter[0]
: undefined,
status:
statusFilter.length > 0 && !statusFilter.includes('all')
? statusFilter[0]
: undefined,
type:
typeFilter.length > 0 && !typeFilter.includes('all')
? Number(typeFilter[0])
: undefined,
tag_mode: enableTagMode,
id_sort: idSort,
...sortParams,
p: pagination.pageIndex + 1,
page_size: pagination.pageSize,
})
: await getChannels({
group:
groupFilter.length > 0 && !groupFilter.includes('all')
? groupFilter[0]
: undefined,
status:
statusFilter.length > 0 && !statusFilter.includes('all')
? statusFilter[0]
: undefined,
type:
typeFilter.length > 0 && !typeFilter.includes('all')
? Number(typeFilter[0])
: undefined,
tag_mode: enableTagMode,
id_sort: idSort,
...sortParams,
p: pagination.pageIndex + 1,
page_size: pagination.pageSize,
})

if (!result.success) {
throw new Error(result.message || t('Request failed'))
}
return result
},
placeholderData: (previousData) => previousData,
})
Expand Down Expand Up @@ -413,6 +416,8 @@ export function ChannelsTable() {
columns={columns}
isLoading={isLoading}
isFetching={isFetching}
error={isError && data === undefined ? error : undefined}
onRetry={() => void refetch()}
emptyTitle={t('No Channels Found')}
emptyDescription={t(
'No channels available. Create your first channel to get started.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
sideDrawerSectionClassName,
sideDrawerSwitchItemClassName,
} from '@/components/drawer-layout'
import { ErrorState } from '@/components/error-state'
import { JsonCodeEditor } from '@/components/json-code-editor'
import { JsonEditor } from '@/components/json-editor'
import { MultiSelect } from '@/components/multi-select'
Expand Down Expand Up @@ -658,11 +659,19 @@ export function ChannelMutateDrawer({
const sensitiveLocked = isEditing && !canEditSensitive

// Fetch channel details if editing
const { data: channelData, isLoading: isChannelLoading } = useQuery({
const channelQuery = useQuery({
queryKey: channelsQueryKeys.detail(channelId || 0),
queryFn: () => getChannel(channelId || 0),
queryFn: async () => {
const response = await getChannel(channelId || 0)
if (!response.success || !response.data) {
throw new Error(response.message || t('Request failed'))
}
return response
},
enabled: isEditing && Boolean(channelId),
})
const channelData = channelQuery.data
const isChannelLoading = channelQuery.isLoading

// Fetch available groups
const { data: groupsData, isLoading: isLoadingGroups } = useQuery({
Expand Down Expand Up @@ -853,6 +862,7 @@ export function ChannelMutateDrawer({
const isBatchMode =
multiKeyMode === 'batch' || multiKeyMode === 'multi_to_single'
const isChannelDetailLoading = isEditing && isChannelLoading
const isChannelDetailError = isEditing && channelQuery.isError
const supportsMultiKeyAddMode =
currentType !== 57 && !(currentType === 41 && vertexKeyType === 'api_key')
const addModeOptions = useMemo(
Expand Down Expand Up @@ -1944,9 +1954,15 @@ export function ChannelMutateDrawer({
onSubmit={form.handleSubmit(onSubmit, onInvalid)}
className={sideDrawerFormClassName('gap-5')}
>
{isChannelDetailLoading ? (
<ChannelEditorLoadingState />
) : (
{isChannelDetailLoading && <ChannelEditorLoadingState />}
{isChannelDetailError && (
<ErrorState
error={channelQuery.error}
onRetry={() => void channelQuery.refetch()}
className='min-h-[320px]'
/>
)}
{!isChannelDetailLoading && !isChannelDetailError && (
<div className='grid gap-5 lg:grid-cols-[13rem_minmax(0,1fr)] lg:items-start'>
<ChannelEditorNav
providerLogo={
Expand Down Expand Up @@ -4233,9 +4249,7 @@ export function ChannelMutateDrawer({
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent
alignItemWithTrigger={false}
>
<SelectContent alignItemWithTrigger={false}>
<SelectGroup>
<SelectItem value='auto'>
{t('Auto')}
Expand Down Expand Up @@ -4771,7 +4785,13 @@ export function ChannelMutateDrawer({
>
{t('Cancel')}
</SheetClose>
<Button form='channel-form' type='submit' disabled={isSubmitting}>
<Button
form='channel-form'
type='submit'
disabled={
isSubmitting || isChannelDetailLoading || isChannelDetailError
}
>
{isSubmitting && (
<Loader2 className='mr-2 h-4 w-4 animate-spin' />
)}
Expand Down
Loading
Loading