feat(webui): integrate i18n into search and sort control components

This commit is contained in:
yiling
2026-06-27 10:30:57 +08:00
parent 4dc53063ea
commit 1b60c8df83
12 changed files with 228 additions and 135 deletions
@@ -18,6 +18,7 @@ import RatingField from '../fields/rating-field'
import { useEffect, useMemo } from 'react' import { useEffect, useMemo } from 'react'
import { useMemberStore } from '@/ui/stores/members' import { useMemberStore } from '@/ui/stores/members'
import { useTeamId } from '@/ui/hooks/use-team-id' import { useTeamId } from '@/ui/hooks/use-team-id'
import { m } from '@/ui/paraglide/messages.js'
interface FilterPanelProps { interface FilterPanelProps {
fields: FieldInfo[] fields: FieldInfo[]
@@ -28,13 +29,6 @@ interface FilterPanelProps {
hidePrefix?: boolean hidePrefix?: boolean
} }
const SYSTEM_FIELDS = [
{ id: 'name', label: 'Name', type: 'text' },
{ id: 'createdAt', label: 'Created At', type: 'date' },
{ id: 'updatedAt', label: 'Updated At', type: 'date' },
{ id: 'sizeByte', label: 'Size', type: 'number' },
]
export function FilterPanel({ export function FilterPanel({
fields, fields,
conditions, conditions,
@@ -60,19 +54,25 @@ export function FilterPanel({
})) }))
}, [members]) }, [members])
const allFields = [ const allFields = useMemo(() => {
...SYSTEM_FIELDS, const sys = [
...fields.map((f) => ({ { id: 'name', label: m.sort_name(), type: 'text' },
{ id: 'createdAt', label: m.field_created_at(), type: 'date' },
{ id: 'updatedAt', label: m.field_updated_at(), type: 'date' },
{ id: 'sizeByte', label: m.field_size(), type: 'number' },
]
const custom = fields.map((f) => ({
id: f.id!, id: f.id!,
label: f.config?.name || f.description || 'Unknown', label: f.config?.name || f.description || m.unknown(),
type: getFieldType(f), type: getFieldType(f),
options: options:
f.config?.type === 'user' || f.config?.type === 'userMulti' f.config?.type === 'user' || f.config?.type === 'userMulti'
? memberOptions ? memberOptions
: f.config?.select?.options || f.config?.selectMulti?.options, : f.config?.select?.options || f.config?.selectMulti?.options,
config: f.config, config: f.config,
})), }))
].filter((f) => !excludeFields?.includes(f.id)) return [...sys, ...custom].filter((f) => !excludeFields?.includes(f.id))
}, [fields, memberOptions, excludeFields])
const handleAddCondition = () => { const handleAddCondition = () => {
onChange([ onChange([
@@ -136,7 +136,7 @@ export function FilterPanel({
<div key={index} className="flex items-center gap-2"> <div key={index} className="flex items-center gap-2">
{!hidePrefix && ( {!hidePrefix && (
<div className="w-16 text-sm text-muted-foreground font-medium text-right"> <div className="w-16 text-sm text-muted-foreground font-medium text-right">
{index === 0 ? 'Where' : 'and'} {index === 0 ? m.filter_where() : m.filter_and()}
</div> </div>
)} )}
<div className="flex-1 flex items-center gap-2"> <div className="flex-1 flex items-center gap-2">
@@ -145,7 +145,7 @@ export function FilterPanel({
onValueChange={(val) => handleConditionChange(index, 'field', val)} onValueChange={(val) => handleConditionChange(index, 'field', val)}
> >
<SelectTrigger className="w-[180px]"> <SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select field" /> <SelectValue placeholder={m.select_field()} />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{allFields.map((field) => ( {allFields.map((field) => (
@@ -161,7 +161,7 @@ export function FilterPanel({
onValueChange={(val) => handleConditionChange(index, 'operator', val)} onValueChange={(val) => handleConditionChange(index, 'operator', val)}
> >
<SelectTrigger className="w-[140px]"> <SelectTrigger className="w-[140px]">
<SelectValue placeholder="Operator" /> <SelectValue placeholder={m.operator()} />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{getOperators( {getOperators(
@@ -202,7 +202,7 @@ export function FilterPanel({
className="text-muted-foreground hover:text-foreground" className="text-muted-foreground hover:text-foreground"
onClick={handleAddCondition} onClick={handleAddCondition}
> >
+ Add condition {m.add_condition()}
</Button> </Button>
</div> </div>
</div> </div>
@@ -242,22 +242,22 @@ function getOperators(field: { id: string; label: string; type: string }): {
if (id === 'name') { if (id === 'name') {
return [ return [
{ value: 'eq' as SearchConditionOperator, label: 'is' }, { value: 'eq' as SearchConditionOperator, label: m.operator_is() },
{ value: 'neq' as SearchConditionOperator, label: 'is not' }, { value: 'neq' as SearchConditionOperator, label: m.operator_is_not() },
{ value: 'contains' as SearchConditionOperator, label: 'contains' }, { value: 'contains' as SearchConditionOperator, label: m.operator_contains() },
{ value: 'notContains' as SearchConditionOperator, label: 'does not contain' }, { value: 'notContains' as SearchConditionOperator, label: m.operator_does_not_contain() },
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' }, { value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' }, { value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
] ]
} }
switch (type) { switch (type) {
case 'text': case 'text':
return [ return [
{ value: 'eq' as SearchConditionOperator, label: 'is' }, { value: 'eq' as SearchConditionOperator, label: m.operator_is() },
{ value: 'neq' as SearchConditionOperator, label: 'is not' }, { value: 'neq' as SearchConditionOperator, label: m.operator_is_not() },
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' }, { value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' }, { value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
] ]
case 'number': case 'number':
case 'rating': case 'rating':
@@ -268,43 +268,43 @@ function getOperators(field: { id: string; label: string; type: string }): {
{ value: 'lt' as SearchConditionOperator, label: '<' }, { value: 'lt' as SearchConditionOperator, label: '<' },
{ value: 'lte' as SearchConditionOperator, label: '≤' }, { value: 'lte' as SearchConditionOperator, label: '≤' },
{ value: 'gte' as SearchConditionOperator, label: '≥' }, { value: 'gte' as SearchConditionOperator, label: '≥' },
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' }, { value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' }, { value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
] ]
case 'select': case 'select':
return [ return [
{ value: 'eq' as SearchConditionOperator, label: 'is' }, { value: 'eq' as SearchConditionOperator, label: m.operator_is() },
{ value: 'neq' as SearchConditionOperator, label: 'is not' }, { value: 'neq' as SearchConditionOperator, label: m.operator_is_not() },
{ value: 'in' as SearchConditionOperator, label: 'is any of' }, { value: 'in' as SearchConditionOperator, label: m.operator_is_any_of() },
{ value: 'notIn' as SearchConditionOperator, label: 'is none of' }, { value: 'notIn' as SearchConditionOperator, label: m.operator_is_none_of() },
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' }, { value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' }, { value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
] ]
case 'selectMulti': case 'selectMulti':
return [ return [
{ value: 'hasAny' as SearchConditionOperator, label: 'has any of' }, { value: 'hasAny' as SearchConditionOperator, label: m.operator_has_any_of() },
{ value: 'hasAll' as SearchConditionOperator, label: 'has all of' }, { value: 'hasAll' as SearchConditionOperator, label: m.operator_has_all_of() },
{ value: 'eq' as SearchConditionOperator, label: 'is exactly' }, { value: 'eq' as SearchConditionOperator, label: m.operator_is_exactly() },
{ value: 'hasNone' as SearchConditionOperator, label: 'has none of' }, { value: 'hasNone' as SearchConditionOperator, label: m.operator_has_none_of() },
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' }, { value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' }, { value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
] ]
case 'date': case 'date':
return [ return [
{ value: 'eq' as SearchConditionOperator, label: 'is' }, { value: 'eq' as SearchConditionOperator, label: m.operator_is() },
{ value: 'isWithin' as SearchConditionOperator, label: 'is within' }, { value: 'isWithin' as SearchConditionOperator, label: m.operator_is_within() },
{ value: 'lt' as SearchConditionOperator, label: 'is before' }, { value: 'lt' as SearchConditionOperator, label: m.operator_is_before() },
{ value: 'gt' as SearchConditionOperator, label: 'is after' }, { value: 'gt' as SearchConditionOperator, label: m.operator_is_after() },
{ value: 'lte' as SearchConditionOperator, label: 'is on or before' }, { value: 'lte' as SearchConditionOperator, label: m.operator_is_on_or_before() },
{ value: 'gte' as SearchConditionOperator, label: 'is on or after' }, { value: 'gte' as SearchConditionOperator, label: m.operator_is_on_or_after() },
{ value: 'neq' as SearchConditionOperator, label: 'is not' }, { value: 'neq' as SearchConditionOperator, label: m.operator_is_not() },
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' }, { value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' }, { value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
] ]
case 'toggle': case 'toggle':
return [{ value: 'eq' as SearchConditionOperator, label: 'is' }] return [{ value: 'eq' as SearchConditionOperator, label: m.operator_is() }]
default: default:
return [{ value: 'eq' as SearchConditionOperator, label: 'is' }] return [{ value: 'eq' as SearchConditionOperator, label: m.operator_is() }]
} }
} }
@@ -362,7 +362,7 @@ function MultiSelectValueInput({
> >
<div className="flex flex-wrap gap-1 items-center max-w-[90%]"> <div className="flex flex-wrap gap-1 items-center max-w-[90%]">
{selectedOptions.length === 0 ? ( {selectedOptions.length === 0 ? (
<span className="text-muted-foreground">Select options...</span> <span className="text-muted-foreground">{m.select_options()}</span>
) : ( ) : (
selectedOptions.map((option) => ( selectedOptions.map((option) => (
<span <span
@@ -433,7 +433,7 @@ function ConditionValueInput({
return ( return (
<Select value={value as string} onValueChange={onChange}> <Select value={value as string} onValueChange={onChange}>
<SelectTrigger> <SelectTrigger>
<SelectValue placeholder="Select option" /> <SelectValue placeholder={m.select_option()} />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{field.options.map((opt) => ( {field.options.map((opt) => (
@@ -453,13 +453,13 @@ function ConditionValueInput({
if (field.type === 'date') { if (field.type === 'date') {
const relativeDates = [ const relativeDates = [
{ value: 'today', label: 'Today' }, { value: 'today', label: m.date_today() },
{ value: 'yesterday', label: 'Yesterday' }, { value: 'yesterday', label: m.date_yesterday() },
{ value: 'tomorrow', label: 'Tomorrow' }, { value: 'tomorrow', label: m.date_tomorrow() },
{ value: 'one week ago', label: 'One week ago' }, { value: 'one week ago', label: m.date_one_week_ago() },
{ value: 'one week from now', label: 'One week from now' }, { value: 'one week from now', label: m.date_one_week_from_now() },
{ value: 'one month ago', label: 'One month ago' }, { value: 'one month ago', label: m.date_one_month_ago() },
{ value: 'one month from now', label: 'One month from now' }, { value: 'one month from now', label: m.date_one_month_from_now() },
] ]
const isRelative = relativeDates.some((rd) => rd.value === value) const isRelative = relativeDates.some((rd) => rd.value === value)
@@ -474,7 +474,7 @@ function ConditionValueInput({
}} }}
> >
<SelectTrigger className="w-[140px]"> <SelectTrigger className="w-[140px]">
<SelectValue placeholder="Date type" /> <SelectValue placeholder={m.date_type()} />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{relativeDates.map((rd) => ( {relativeDates.map((rd) => (
@@ -482,7 +482,7 @@ function ConditionValueInput({
{rd.label} {rd.label}
</SelectItem> </SelectItem>
))} ))}
<SelectItem value="exact">Exact date...</SelectItem> <SelectItem value="exact">{m.exact_date()}</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
{!isRelative && ( {!isRelative && (
@@ -527,8 +527,8 @@ function ConditionValueInput({
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="true">Checked</SelectItem> <SelectItem value="true">{m.toggle_checked()}</SelectItem>
<SelectItem value="false">Unchecked</SelectItem> <SelectItem value="false">{m.toggle_unchecked()}</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
) )
@@ -537,7 +537,7 @@ function ConditionValueInput({
return ( return (
<DebouncedInput <DebouncedInput
type="text" type="text"
placeholder="Enter a value" placeholder={m.enter_a_value()}
value={value as string} value={value as string}
onChange={onChange} onChange={onChange}
/> />
@@ -26,6 +26,7 @@ import { useEffect, useMemo, useState } from 'react'
import { useInView } from 'react-intersection-observer' import { useInView } from 'react-intersection-observer'
import { toast } from 'sonner' import { toast } from 'sonner'
import { FilterPanel } from './filter-panel' import { FilterPanel } from './filter-panel'
import { m } from '@/ui/paraglide/messages.js'
interface SearchFilterDialogProps { interface SearchFilterDialogProps {
open: boolean open: boolean
@@ -72,7 +73,7 @@ export function SearchFilterDialog({
const res = await client.api.teams[':teamId'].settings.$get({ const res = await client.api.teams[':teamId'].settings.$get({
param: { teamId }, param: { teamId },
}) })
if (!res.ok) throw new Error('Failed to fetch team settings') if (!res.ok) throw new Error(m.failed_load_settings())
return (await res.json()) as { semanticSearchEnabled: boolean } return (await res.json()) as { semanticSearchEnabled: boolean }
}, },
enabled: open, enabled: open,
@@ -123,7 +124,7 @@ export function SearchFilterDialog({
const fieldName = field?.config?.name || first.field const fieldName = field?.config?.name || first.field
name = `${fieldName} ${first.operator} ${first.value}` name = `${fieldName} ${first.operator} ${first.value}`
} }
if (!name) name = 'Untitled Collection' if (!name) name = m.untitled_collection()
const res = await client.api.projects[':projectId'].collections.$post({ const res = await client.api.projects[':projectId'].collections.$post({
param: { projectId }, param: { projectId },
@@ -140,12 +141,12 @@ export function SearchFilterDialog({
}, },
}, },
}) })
if (!res.ok) throw new Error('Failed to save collection') if (!res.ok) throw new Error(m.failed_save_collection())
return await res.json() return await res.json()
}, },
onSuccess: (data) => { onSuccess: (data) => {
queryClient.invalidateQueries({ queryKey: ['collections', projectId] }) queryClient.invalidateQueries({ queryKey: ['collections', projectId] })
toast.success('Collection saved') toast.success(m.collection_saved())
onOpenChange(false) onOpenChange(false)
navigate({ navigate({
to: '/projects/$projectId/collections/$collectionId', to: '/projects/$projectId/collections/$collectionId',
@@ -184,7 +185,7 @@ export function SearchFilterDialog({
}) })
if (!res.ok) { if (!res.ok) {
const errorData = (await res.json().catch(() => ({}))) as Record<string, unknown> const errorData = (await res.json().catch(() => ({}))) as Record<string, unknown>
throw new Error((errorData.message as string) || 'Search failed') throw new Error((errorData.message as string) || m.search_failed())
} }
return (await res.json()) as { return (await res.json()) as {
data: AssetInfo[] data: AssetInfo[]
@@ -255,7 +256,7 @@ export function SearchFilterDialog({
<Dialog open={open} onOpenChange={onOpenChange}> <Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[900px] p-0 gap-0 overflow-hidden bg-background border-border rounded-2xl shadow-2xl flex flex-col h-[85vh]"> <DialogContent className="sm:max-w-[900px] p-0 gap-0 overflow-hidden bg-background border-border rounded-2xl shadow-2xl flex flex-col h-[85vh]">
<DialogHeader className="px-6 pt-3 pb-0 text-left"> <DialogHeader className="px-6 pt-3 pb-0 text-left">
<DialogTitle className="text-lg font-bold">Search</DialogTitle> <DialogTitle className="text-lg font-bold">{m.search_dialog_title()}</DialogTitle>
</DialogHeader> </DialogHeader>
<div className="px-6 pb-6 pt-4 border-b border-border bg-muted/30 flex flex-col gap-3"> <div className="px-6 pb-6 pt-4 border-b border-border bg-muted/30 flex flex-col gap-3">
@@ -271,7 +272,7 @@ export function SearchFilterDialog({
value={searchInput} value={searchInput}
onChange={(e) => setSearchInput(e.target.value)} onChange={(e) => setSearchInput(e.target.value)}
placeholder={ placeholder={
isSemantic ? 'Search records by content...' : 'Search records by name...' isSemantic ? m.search_by_content_placeholder() : m.search_by_name_placeholder()
} }
className="w-full pl-4 pr-24 py-3 bg-background border-border rounded-xl text-sm h-12 focus-visible:ring-2 focus-visible:ring-primary/20 shadow-sm" className="w-full pl-4 pr-24 py-3 bg-background border-border rounded-xl text-sm h-12 focus-visible:ring-2 focus-visible:ring-primary/20 shadow-sm"
/> />
@@ -291,7 +292,7 @@ export function SearchFilterDialog({
type="submit" type="submit"
className="absolute right-1.5 top-1.5 bottom-1.5 px-4 bg-primary hover:bg-primary/90 text-primary-foreground text-xs font-semibold rounded-lg flex items-center justify-center transition-colors shadow-sm" className="absolute right-1.5 top-1.5 bottom-1.5 px-4 bg-primary hover:bg-primary/90 text-primary-foreground text-xs font-semibold rounded-lg flex items-center justify-center transition-colors shadow-sm"
> >
Search {m.search_button()}
</button> </button>
</div> </div>
@@ -315,12 +316,12 @@ export function SearchFilterDialog({
!semanticSearchEnabled && 'opacity-50 cursor-not-allowed', !semanticSearchEnabled && 'opacity-50 cursor-not-allowed',
)} )}
> >
Semantic Search {m.semantic_search()}
</Label> </Label>
</div> </div>
{!semanticSearchEnabled && ( {!semanticSearchEnabled && (
<span className="text-[10px] text-muted-foreground italic"> <span className="text-[10px] text-muted-foreground italic">
* Semantic search requires an enabled embedding agent. {m.semantic_search_requires_embedding()}
</span> </span>
)} )}
</div> </div>
@@ -338,12 +339,12 @@ export function SearchFilterDialog({
) : ( ) : (
<ChevronDown className="w-4 h-4 text-muted-foreground group-hover:text-foreground" /> <ChevronDown className="w-4 h-4 text-muted-foreground group-hover:text-foreground" />
)} )}
<span className="text-xs font-semibold text-foreground/80">Filters</span> <span className="text-xs font-semibold text-foreground/80">{m.filters()}</span>
</button> </button>
{activeFiltersCount > 0 && ( {activeFiltersCount > 0 && (
<span className="px-1.5 py-0.5 rounded-full text-[10px] font-mono font-bold bg-primary/10 text-primary border border-primary/20"> <span className="px-1.5 py-0.5 rounded-full text-[10px] font-mono font-bold bg-primary/10 text-primary border border-primary/20">
{activeFiltersCount} active {activeFiltersCount} {m.active_filters()}
</span> </span>
)} )}
</div> </div>
@@ -357,7 +358,7 @@ export function SearchFilterDialog({
}} }}
className="text-[11px] font-medium text-destructive hover:text-destructive/80 underline underline-offset-2 transition-colors" className="text-[11px] font-medium text-destructive hover:text-destructive/80 underline underline-offset-2 transition-colors"
> >
Reset {m.reset()}
</button> </button>
)} )}
</div> </div>
@@ -383,14 +384,12 @@ export function SearchFilterDialog({
<div className="p-4 md:p-5"> <div className="p-4 md:p-5">
<div className="flex items-center justify-between mb-3 px-1"> <div className="flex items-center justify-between mb-3 px-1">
<span className="text-[11px] font-bold uppercase tracking-wider text-muted-foreground/60 font-mono"> <span className="text-[11px] font-bold uppercase tracking-wider text-muted-foreground/60 font-mono">
Search Results {m.search_results()}
</span> </span>
{isLoading && ( {isLoading && (
<span className="inline-flex items-center gap-1.5 text-xs text-primary"> <span className="inline-flex items-center gap-1.5 text-xs text-primary">
<Loader2 className="h-3 w-3 animate-spin" /> <Loader2 className="h-3 w-3 animate-spin" />
{isSemantic {isSemantic ? m.semantic_search_slow() : m.querying_database()}
? 'Semantic search using media intelligence might be slow...'
: 'Querying database...'}
</span> </span>
)} )}
</div> </div>
@@ -399,25 +398,25 @@ export function SearchFilterDialog({
{!hasActiveCriteria ? ( {!hasActiveCriteria ? (
<div className="py-20 text-center flex flex-col items-center justify-center bg-muted/20 px-4"> <div className="py-20 text-center flex flex-col items-center justify-center bg-muted/20 px-4">
<Search className="w-10 h-10 text-muted-foreground/30 mb-2" /> <Search className="w-10 h-10 text-muted-foreground/30 mb-2" />
<h3 className="text-sm font-semibold text-foreground/80">Ready to Search</h3> <h3 className="text-sm font-semibold text-foreground/80">
{m.ready_to_search()}
</h3>
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto"> <p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
Type your query above and click the Search button to display results. {m.type_query_instruction()}
</p> </p>
{isSemantic && ( {isSemantic && (
<p className="text-xs text-muted-foreground/80 max-w-md mt-4 mx-auto border-t border-border/60 pt-3"> <p className="text-xs text-muted-foreground/80 max-w-md mt-4 mx-auto border-t border-border/60 pt-3">
Semantic search results will be ordered by their relevance to the search query {m.semantic_search_note()}
text, but won't be strictly filtered. If you need accurate filtering, please
add filter conditions to control that.
</p> </p>
)} )}
</div> </div>
) : searchError ? ( ) : searchError ? (
<div className="py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20"> <div className="py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
<AlertCircle className="w-10 h-10 text-destructive/50 mb-2" /> <AlertCircle className="w-10 h-10 text-destructive/50 mb-2" />
<h3 className="text-sm font-semibold text-foreground/80">Search failed</h3> <h3 className="text-sm font-semibold text-foreground/80">{m.search_failed()}</h3>
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto"> <p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
{searchError.message.includes('Embedding agent not configured') {searchError.message.includes('Embedding agent not configured')
? 'Please create and enable an embedding agent in the team settings to use semantic search.' ? m.enable_embedding_agent_hint()
: searchError.message} : searchError.message}
</p> </p>
</div> </div>
@@ -438,10 +437,10 @@ export function SearchFilterDialog({
<div className="py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20"> <div className="py-12 px-4 text-center flex flex-col items-center justify-center bg-muted/20">
<AlertCircle className="w-10 h-10 text-muted-foreground/30 mb-2" /> <AlertCircle className="w-10 h-10 text-muted-foreground/30 mb-2" />
<h3 className="text-sm font-semibold text-foreground/80"> <h3 className="text-sm font-semibold text-foreground/80">
No records matched your criteria {m.no_records_matched()}
</h3> </h3>
<p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto"> <p className="text-xs text-muted-foreground max-w-sm mt-1 mx-auto">
Try adjusting spelling or removing filter rows. {m.try_adjusting_spelling()}
</p> </p>
</div> </div>
) : ( ) : (
@@ -479,15 +478,15 @@ export function SearchFilterDialog({
</span> </span>
<span className="text-xs text-muted-foreground block mt-0.5 truncate"> <span className="text-xs text-muted-foreground block mt-0.5 truncate">
{record.type === 'folder' {record.type === 'folder'
? 'Folder' ? m.folder()
: `Size: ${formatSize(record.sizeByte || 0)}`} : `${m.size_prefix()} ${formatSize(record.sizeByte || 0)}`}
</span> </span>
{record.startTime !== undefined && {record.startTime !== undefined &&
record.startTime !== null && record.startTime !== null &&
record.endTime !== undefined && record.endTime !== undefined &&
record.endTime !== null && ( record.endTime !== null && (
<span className="text-[10px] font-semibold text-primary bg-primary/10 border border-primary/20 px-1.5 py-0.5 rounded mt-1 inline-block"> <span className="text-[10px] font-semibold text-primary bg-primary/10 border border-primary/20 px-1.5 py-0.5 rounded mt-1 inline-block">
Match found at {formatTimestamp(record.startTime)} -{' '} {m.match_found_at()} {formatTimestamp(record.startTime)} -{' '}
{formatTimestamp(record.endTime)} {formatTimestamp(record.endTime)}
</span> </span>
)} )}
@@ -516,13 +515,7 @@ export function SearchFilterDialog({
{/* Footer ported from Demo */} {/* Footer ported from Demo */}
<div className="p-4 border-t border-border bg-muted/30 flex items-center justify-between shrink-0"> <div className="p-4 border-t border-border bg-muted/30 flex items-center justify-between shrink-0">
<div className="text-xs text-muted-foreground flex items-center gap-2"> <div className="text-xs text-muted-foreground flex items-center gap-2">
<span> <span>{m.matched_items({ count: formatMatchedCount(totalCount) })}</span>
Matched{' '}
<strong className="font-mono font-bold text-foreground">
{formatMatchedCount(totalCount)}
</strong>{' '}
items
</span>
</div> </div>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
@@ -536,10 +529,10 @@ export function SearchFilterDialog({
{isSaving ? ( {isSaving ? (
<> <>
<Loader2 className="mr-2 h-3 w-3 animate-spin" /> <Loader2 className="mr-2 h-3 w-3 animate-spin" />
Saving... {m.saving_ellipsis()}
</> </>
) : ( ) : (
'Save as collection' m.save_as_collection()
)} )}
</Button> </Button>
@@ -548,7 +541,7 @@ export function SearchFilterDialog({
className="h-8 text-[10px] font-semibold uppercase tracking-wider" className="h-8 text-[10px] font-semibold uppercase tracking-wider"
onClick={isSemantic ? () => onOpenChange(false) : handleApply} onClick={isSemantic ? () => onOpenChange(false) : handleApply}
> >
{isSemantic ? 'Close' : 'Apply and Close'} {isSemantic ? m.close() : m.apply_and_close()}
</Button> </Button>
</div> </div>
</div> </div>
@@ -10,6 +10,8 @@ import {
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from '@/ui/components/ui/select' } from '@/ui/components/ui/select'
import { useMemo } from 'react'
import { m } from '@/ui/paraglide/messages.js'
interface SortControlProps { interface SortControlProps {
fields: MetadataFieldInfo[] fields: MetadataFieldInfo[]
@@ -18,22 +20,21 @@ interface SortControlProps {
disabled?: boolean disabled?: boolean
} }
const SYSTEM_FIELDS = [
{ id: 'custom', label: 'Custom' },
{ id: 'name', label: 'Name' },
{ id: 'createdAt', label: 'Date Created' },
{ id: 'updatedAt', label: 'Date Modified' },
{ id: 'sizeByte', label: 'Size' },
]
export function SortControl({ fields, sort, onSortChange, disabled }: SortControlProps) { export function SortControl({ fields, sort, onSortChange, disabled }: SortControlProps) {
const allFields = [ const allFields = useMemo(() => {
...SYSTEM_FIELDS, const sys = [
...fields.map((f) => ({ { id: 'custom', label: m.sort_custom() },
{ id: 'name', label: m.sort_name() },
{ id: 'createdAt', label: m.sort_date_created() },
{ id: 'updatedAt', label: m.sort_date_modified() },
{ id: 'sizeByte', label: m.sort_size() },
]
const custom = fields.map((f) => ({
id: f.id!, id: f.id!,
label: f.config?.name || f.description || 'Unknown', label: f.config?.name || f.description || m.unknown(),
})), }))
] return [...sys, ...custom]
}, [fields])
// Default to Custom if no sort selected // Default to Custom if no sort selected
const currentFieldId = sort?.field || 'custom' const currentFieldId = sort?.field || 'custom'
@@ -43,15 +44,15 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
const getDirectionOptions = (fieldId: string) => { const getDirectionOptions = (fieldId: string) => {
if (fieldId === 'name') { if (fieldId === 'name') {
return { asc: 'A → Z', desc: 'Z → A' } return { asc: m.sort_a_to_z(), desc: m.sort_z_to_a() }
} }
if (['createdAt', 'updatedAt'].includes(fieldId)) { if (['createdAt', 'updatedAt'].includes(fieldId)) {
return { asc: 'Oldest → Newest', desc: 'Newest → Oldest' } return { asc: m.sort_oldest_to_newest(), desc: m.sort_newest_to_oldest() }
} }
if (fieldId === 'sizeByte') { if (fieldId === 'sizeByte') {
return { asc: 'Smallest → Largest', desc: 'Largest → Smallest' } return { asc: m.sort_smallest_to_largest(), desc: m.sort_largest_to_smallest() }
} }
return { asc: 'Ascending', desc: 'Descending' } return { asc: m.ascending(), desc: m.descending() }
} }
const dirOptions = getDirectionOptions(currentFieldId) const dirOptions = getDirectionOptions(currentFieldId)
@@ -79,13 +80,13 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
className="h-8" className="h-8"
disabled={disabled} disabled={disabled}
> >
{sort ? `Sorted by ${currentField.label}` : 'Sort by'} {sort ? m.sorted_by({ field: currentField.label }) : m.sort_by()}
</Button> </Button>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent className="w-[280px] p-3" align="end"> <PopoverContent className="w-[280px] p-3" align="end">
<div className="grid gap-4"> <div className="grid gap-4">
<div className="grid gap-2"> <div className="grid gap-2">
<span className="text-sm text-muted-foreground">Sort by</span> <span className="text-sm text-muted-foreground">{m.sort_by()}</span>
<Select value={currentFieldId} onValueChange={handleFieldChange}> <Select value={currentFieldId} onValueChange={handleFieldChange}>
<SelectTrigger className="w-full"> <SelectTrigger className="w-full">
<SelectValue /> <SelectValue />
@@ -102,7 +103,7 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
{currentFieldId !== 'custom' && ( {currentFieldId !== 'custom' && (
<div className="grid gap-2"> <div className="grid gap-2">
<span className="text-sm text-muted-foreground">Order</span> <span className="text-sm text-muted-foreground">{m.order()}</span>
<Button <Button
variant="outline" variant="outline"
className="w-full justify-between font-normal" className="w-full justify-between font-normal"
+10 -9
View File
@@ -6,6 +6,7 @@ import {
DropdownMenuTrigger, DropdownMenuTrigger,
} from '@/ui/components/ui/dropdown-menu' } from '@/ui/components/ui/dropdown-menu'
import { ArrowDownWideNarrow, ArrowUpNarrowWide, Check } from 'lucide-react' import { ArrowDownWideNarrow, ArrowUpNarrowWide, Check } from 'lucide-react'
import { m } from '@/ui/paraglide/messages.js'
interface SortDropdownProps { interface SortDropdownProps {
sortBy: string sortBy: string
@@ -26,11 +27,11 @@ export function SortDropdown({ sortBy, sortDirection, onSortChange }: SortDropdo
const formatSortBy = (field: string) => { const formatSortBy = (field: string) => {
switch (field) { switch (field) {
case 'name': case 'name':
return 'Name' return m.sort_name()
case 'created_at': case 'created_at':
return 'Created' return m.sort_created()
case 'updated_at': case 'updated_at':
return 'Updated' return m.sort_updated()
default: default:
return field return field
} }
@@ -42,12 +43,12 @@ export function SortDropdown({ sortBy, sortDirection, onSortChange }: SortDropdo
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<Button variant="outline" className="gap-2 bg-muted/50"> <Button variant="outline" className="gap-2 bg-muted/50">
<span className="text-muted-foreground">Sorted by</span> <span className="text-muted-foreground">{m.sorted_by_label()}</span>
<span className="font-medium text-foreground">{formatSortBy(sortBy)}</span> <span className="font-medium text-foreground">{formatSortBy(sortBy)}</span>
</Button> </Button>
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56 p-2"> <DropdownMenuContent align="end" className="w-56 p-2">
<div className="text-xs font-semibold text-muted-foreground mb-2 px-2">Sort by</div> <div className="text-xs font-semibold text-muted-foreground mb-2 px-2">{m.sort_by()}</div>
{/* Field Selection */} {/* Field Selection */}
<DropdownMenu> <DropdownMenu>
@@ -83,14 +84,14 @@ export function SortDropdown({ sortBy, sortDirection, onSortChange }: SortDropdo
<span className="text-muted-foreground"> <span className="text-muted-foreground">
{sortBy === 'name' ? ( {sortBy === 'name' ? (
isAsc ? ( isAsc ? (
<>from A &rarr; Z</> <>{m.sort_a_to_z()}</>
) : ( ) : (
<>from Z &rarr; A</> <>{m.sort_z_to_a()}</>
) )
) : isAsc ? ( ) : isAsc ? (
<>Oldest &rarr; Newest</> <>{m.sort_oldest_to_newest()}</>
) : ( ) : (
<>Newest &rarr; Oldest</> <>{m.sort_newest_to_oldest()}</>
)} )}
</span> </span>
{isAsc ? ( {isAsc ? (
+2
View File
@@ -137,6 +137,7 @@
"created_date": "Created Date", "created_date": "Created Date",
"collection_created": "Collection created", "collection_created": "Collection created",
"failed_create_collection": "Failed to create collection", "failed_create_collection": "Failed to create collection",
"failed_save_collection": "Failed to save collection",
"loading_collection": "Loading collection...", "loading_collection": "Loading collection...",
"untitled_collection": "Untitled Collection", "untitled_collection": "Untitled Collection",
"collection_saved": "Collection saved", "collection_saved": "Collection saved",
@@ -178,6 +179,7 @@
"field": "Field", "field": "Field",
"sort_by": "Sort by", "sort_by": "Sort by",
"sorted_by": "Sorted by {field}", "sorted_by": "Sorted by {field}",
"sorted_by_label": "Sorted by",
"order": "Order", "order": "Order",
"custom": "Custom", "custom": "Custom",
"date_created": "Date Created", "date_created": "Date Created",
+2
View File
@@ -137,6 +137,7 @@
"created_date": "创建日期", "created_date": "创建日期",
"collection_created": "收藏集已创建", "collection_created": "收藏集已创建",
"failed_create_collection": "创建收藏集失败", "failed_create_collection": "创建收藏集失败",
"failed_save_collection": "保存收藏集失败",
"loading_collection": "正在加载收藏集...", "loading_collection": "正在加载收藏集...",
"untitled_collection": "未命名收藏集", "untitled_collection": "未命名收藏集",
"collection_saved": "收藏集已保存", "collection_saved": "收藏集已保存",
@@ -178,6 +179,7 @@
"field": "字段", "field": "字段",
"sort_by": "排序", "sort_by": "排序",
"sorted_by": "按{field}排序", "sorted_by": "按{field}排序",
"sorted_by_label": "排序方式",
"order": "顺序", "order": "顺序",
"custom": "自定义", "custom": "自定义",
"date_created": "创建日期", "date_created": "创建日期",
+2
View File
@@ -128,6 +128,7 @@ export * from "./creator.js";
export * from "./created_date.js"; export * from "./created_date.js";
export * from "./collection_created.js"; export * from "./collection_created.js";
export * from "./failed_create_collection.js"; export * from "./failed_create_collection.js";
export * from "./failed_save_collection.js";
export * from "./loading_collection.js"; export * from "./loading_collection.js";
export * from "./untitled_collection.js"; export * from "./untitled_collection.js";
export * from "./collection_saved.js"; export * from "./collection_saved.js";
@@ -167,6 +168,7 @@ export * from "./list.js";
export * from "./field.js"; export * from "./field.js";
export * from "./sort_by.js"; export * from "./sort_by.js";
export * from "./sorted_by.js"; export * from "./sorted_by.js";
export * from "./sorted_by_label.js";
export * from "./order.js"; export * from "./order.js";
export * from "./custom.js"; export * from "./custom.js";
export * from "./date_created.js"; export * from "./date_created.js";
@@ -130,6 +130,7 @@ export * from './creator.js'
export * from './created_date.js' export * from './created_date.js'
export * from './collection_created.js' export * from './collection_created.js'
export * from './failed_create_collection.js' export * from './failed_create_collection.js'
export * from './failed_save_collection.js'
export * from './loading_collection.js' export * from './loading_collection.js'
export * from './untitled_collection.js' export * from './untitled_collection.js'
export * from './collection_saved.js' export * from './collection_saved.js'
@@ -169,6 +170,7 @@ export * from './list.js'
export * from './field.js' export * from './field.js'
export * from './sort_by.js' export * from './sort_by.js'
export * from './sorted_by.js' export * from './sorted_by.js'
export * from './sorted_by_label.js'
export * from './order.js' export * from './order.js'
export * from './custom.js' export * from './custom.js'
export * from './date_created.js' export * from './date_created.js'
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Failed to save collection" |
*
* @param {Failed_Save_CollectionInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const failed_save_collection: ((inputs?: Failed_Save_CollectionInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Failed_Save_CollectionInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Failed_Save_CollectionInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Failed_Save_CollectionInputs */
const en_failed_save_collection = /** @type {(inputs: Failed_Save_CollectionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Failed to save collection`)
};
const zh_failed_save_collection = /** @type {(inputs: Failed_Save_CollectionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`保存收藏集失败`)
};
/**
* | output |
* | --- |
* | "Failed to save collection" |
*
* @param {Failed_Save_CollectionInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const failed_save_collection = /** @type {((inputs?: Failed_Save_CollectionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Failed_Save_CollectionInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_failed_save_collection(inputs)
return zh_failed_save_collection(inputs)
});
+16
View File
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Sorted by" |
*
* @param {Sorted_By_LabelInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const sorted_by_label: ((inputs?: Sorted_By_LabelInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Sorted_By_LabelInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Sorted_By_LabelInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Sorted_By_LabelInputs */
const en_sorted_by_label = /** @type {(inputs: Sorted_By_LabelInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Sorted by`)
};
const zh_sorted_by_label = /** @type {(inputs: Sorted_By_LabelInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`排序方式`)
};
/**
* | output |
* | --- |
* | "Sorted by" |
*
* @param {Sorted_By_LabelInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const sorted_by_label = /** @type {((inputs?: Sorted_By_LabelInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Sorted_By_LabelInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_sorted_by_label(inputs)
return zh_sorted_by_label(inputs)
});