mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 02:29:35 +00:00
feat(webui): integrate i18n into search and sort control components
This commit is contained in:
@@ -18,6 +18,7 @@ import RatingField from '../fields/rating-field'
|
||||
import { useEffect, useMemo } from 'react'
|
||||
import { useMemberStore } from '@/ui/stores/members'
|
||||
import { useTeamId } from '@/ui/hooks/use-team-id'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
interface FilterPanelProps {
|
||||
fields: FieldInfo[]
|
||||
@@ -28,13 +29,6 @@ interface FilterPanelProps {
|
||||
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({
|
||||
fields,
|
||||
conditions,
|
||||
@@ -60,19 +54,25 @@ export function FilterPanel({
|
||||
}))
|
||||
}, [members])
|
||||
|
||||
const allFields = [
|
||||
...SYSTEM_FIELDS,
|
||||
...fields.map((f) => ({
|
||||
const allFields = useMemo(() => {
|
||||
const sys = [
|
||||
{ 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!,
|
||||
label: f.config?.name || f.description || 'Unknown',
|
||||
label: f.config?.name || f.description || m.unknown(),
|
||||
type: getFieldType(f),
|
||||
options:
|
||||
f.config?.type === 'user' || f.config?.type === 'userMulti'
|
||||
? memberOptions
|
||||
: f.config?.select?.options || f.config?.selectMulti?.options,
|
||||
config: f.config,
|
||||
})),
|
||||
].filter((f) => !excludeFields?.includes(f.id))
|
||||
}))
|
||||
return [...sys, ...custom].filter((f) => !excludeFields?.includes(f.id))
|
||||
}, [fields, memberOptions, excludeFields])
|
||||
|
||||
const handleAddCondition = () => {
|
||||
onChange([
|
||||
@@ -136,7 +136,7 @@ export function FilterPanel({
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
{!hidePrefix && (
|
||||
<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 className="flex-1 flex items-center gap-2">
|
||||
@@ -145,7 +145,7 @@ export function FilterPanel({
|
||||
onValueChange={(val) => handleConditionChange(index, 'field', val)}
|
||||
>
|
||||
<SelectTrigger className="w-[180px]">
|
||||
<SelectValue placeholder="Select field" />
|
||||
<SelectValue placeholder={m.select_field()} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{allFields.map((field) => (
|
||||
@@ -161,7 +161,7 @@ export function FilterPanel({
|
||||
onValueChange={(val) => handleConditionChange(index, 'operator', val)}
|
||||
>
|
||||
<SelectTrigger className="w-[140px]">
|
||||
<SelectValue placeholder="Operator" />
|
||||
<SelectValue placeholder={m.operator()} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{getOperators(
|
||||
@@ -202,7 +202,7 @@ export function FilterPanel({
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
onClick={handleAddCondition}
|
||||
>
|
||||
+ Add condition
|
||||
{m.add_condition()}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -242,22 +242,22 @@ function getOperators(field: { id: string; label: string; type: string }): {
|
||||
|
||||
if (id === 'name') {
|
||||
return [
|
||||
{ value: 'eq' as SearchConditionOperator, label: 'is' },
|
||||
{ value: 'neq' as SearchConditionOperator, label: 'is not' },
|
||||
{ value: 'contains' as SearchConditionOperator, label: 'contains' },
|
||||
{ value: 'notContains' as SearchConditionOperator, label: 'does not contain' },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' },
|
||||
{ value: 'eq' as SearchConditionOperator, label: m.operator_is() },
|
||||
{ value: 'neq' as SearchConditionOperator, label: m.operator_is_not() },
|
||||
{ value: 'contains' as SearchConditionOperator, label: m.operator_contains() },
|
||||
{ value: 'notContains' as SearchConditionOperator, label: m.operator_does_not_contain() },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
|
||||
]
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 'text':
|
||||
return [
|
||||
{ value: 'eq' as SearchConditionOperator, label: 'is' },
|
||||
{ value: 'neq' as SearchConditionOperator, label: 'is not' },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' },
|
||||
{ value: 'eq' as SearchConditionOperator, label: m.operator_is() },
|
||||
{ value: 'neq' as SearchConditionOperator, label: m.operator_is_not() },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
|
||||
]
|
||||
case 'number':
|
||||
case 'rating':
|
||||
@@ -268,43 +268,43 @@ function getOperators(field: { id: string; label: string; type: string }): {
|
||||
{ value: 'lt' as SearchConditionOperator, label: '<' },
|
||||
{ value: 'lte' as SearchConditionOperator, label: '≤' },
|
||||
{ value: 'gte' as SearchConditionOperator, label: '≥' },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
|
||||
]
|
||||
case 'select':
|
||||
return [
|
||||
{ value: 'eq' as SearchConditionOperator, label: 'is' },
|
||||
{ value: 'neq' as SearchConditionOperator, label: 'is not' },
|
||||
{ value: 'in' as SearchConditionOperator, label: 'is any of' },
|
||||
{ value: 'notIn' as SearchConditionOperator, label: 'is none of' },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' },
|
||||
{ value: 'eq' as SearchConditionOperator, label: m.operator_is() },
|
||||
{ value: 'neq' as SearchConditionOperator, label: m.operator_is_not() },
|
||||
{ value: 'in' as SearchConditionOperator, label: m.operator_is_any_of() },
|
||||
{ value: 'notIn' as SearchConditionOperator, label: m.operator_is_none_of() },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
|
||||
]
|
||||
case 'selectMulti':
|
||||
return [
|
||||
{ value: 'hasAny' as SearchConditionOperator, label: 'has any of' },
|
||||
{ value: 'hasAll' as SearchConditionOperator, label: 'has all of' },
|
||||
{ value: 'eq' as SearchConditionOperator, label: 'is exactly' },
|
||||
{ value: 'hasNone' as SearchConditionOperator, label: 'has none of' },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' },
|
||||
{ value: 'hasAny' as SearchConditionOperator, label: m.operator_has_any_of() },
|
||||
{ value: 'hasAll' as SearchConditionOperator, label: m.operator_has_all_of() },
|
||||
{ value: 'eq' as SearchConditionOperator, label: m.operator_is_exactly() },
|
||||
{ value: 'hasNone' as SearchConditionOperator, label: m.operator_has_none_of() },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
|
||||
]
|
||||
case 'date':
|
||||
return [
|
||||
{ value: 'eq' as SearchConditionOperator, label: 'is' },
|
||||
{ value: 'isWithin' as SearchConditionOperator, label: 'is within' },
|
||||
{ value: 'lt' as SearchConditionOperator, label: 'is before' },
|
||||
{ value: 'gt' as SearchConditionOperator, label: 'is after' },
|
||||
{ value: 'lte' as SearchConditionOperator, label: 'is on or before' },
|
||||
{ value: 'gte' as SearchConditionOperator, label: 'is on or after' },
|
||||
{ value: 'neq' as SearchConditionOperator, label: 'is not' },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: 'is empty' },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: 'is not empty' },
|
||||
{ value: 'eq' as SearchConditionOperator, label: m.operator_is() },
|
||||
{ value: 'isWithin' as SearchConditionOperator, label: m.operator_is_within() },
|
||||
{ value: 'lt' as SearchConditionOperator, label: m.operator_is_before() },
|
||||
{ value: 'gt' as SearchConditionOperator, label: m.operator_is_after() },
|
||||
{ value: 'lte' as SearchConditionOperator, label: m.operator_is_on_or_before() },
|
||||
{ value: 'gte' as SearchConditionOperator, label: m.operator_is_on_or_after() },
|
||||
{ value: 'neq' as SearchConditionOperator, label: m.operator_is_not() },
|
||||
{ value: 'isEmpty' as SearchConditionOperator, label: m.operator_is_empty() },
|
||||
{ value: 'isNotEmpty' as SearchConditionOperator, label: m.operator_is_not_empty() },
|
||||
]
|
||||
case 'toggle':
|
||||
return [{ value: 'eq' as SearchConditionOperator, label: 'is' }]
|
||||
return [{ value: 'eq' as SearchConditionOperator, label: m.operator_is() }]
|
||||
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%]">
|
||||
{selectedOptions.length === 0 ? (
|
||||
<span className="text-muted-foreground">Select options...</span>
|
||||
<span className="text-muted-foreground">{m.select_options()}</span>
|
||||
) : (
|
||||
selectedOptions.map((option) => (
|
||||
<span
|
||||
@@ -433,7 +433,7 @@ function ConditionValueInput({
|
||||
return (
|
||||
<Select value={value as string} onValueChange={onChange}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select option" />
|
||||
<SelectValue placeholder={m.select_option()} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{field.options.map((opt) => (
|
||||
@@ -453,13 +453,13 @@ function ConditionValueInput({
|
||||
|
||||
if (field.type === 'date') {
|
||||
const relativeDates = [
|
||||
{ value: 'today', label: 'Today' },
|
||||
{ value: 'yesterday', label: 'Yesterday' },
|
||||
{ value: 'tomorrow', label: 'Tomorrow' },
|
||||
{ value: 'one week ago', label: 'One week ago' },
|
||||
{ value: 'one week from now', label: 'One week from now' },
|
||||
{ value: 'one month ago', label: 'One month ago' },
|
||||
{ value: 'one month from now', label: 'One month from now' },
|
||||
{ value: 'today', label: m.date_today() },
|
||||
{ value: 'yesterday', label: m.date_yesterday() },
|
||||
{ value: 'tomorrow', label: m.date_tomorrow() },
|
||||
{ value: 'one week ago', label: m.date_one_week_ago() },
|
||||
{ value: 'one week from now', label: m.date_one_week_from_now() },
|
||||
{ value: 'one month ago', label: m.date_one_month_ago() },
|
||||
{ value: 'one month from now', label: m.date_one_month_from_now() },
|
||||
]
|
||||
|
||||
const isRelative = relativeDates.some((rd) => rd.value === value)
|
||||
@@ -474,7 +474,7 @@ function ConditionValueInput({
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="w-[140px]">
|
||||
<SelectValue placeholder="Date type" />
|
||||
<SelectValue placeholder={m.date_type()} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{relativeDates.map((rd) => (
|
||||
@@ -482,7 +482,7 @@ function ConditionValueInput({
|
||||
{rd.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
<SelectItem value="exact">Exact date...</SelectItem>
|
||||
<SelectItem value="exact">{m.exact_date()}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{!isRelative && (
|
||||
@@ -527,8 +527,8 @@ function ConditionValueInput({
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="true">Checked</SelectItem>
|
||||
<SelectItem value="false">Unchecked</SelectItem>
|
||||
<SelectItem value="true">{m.toggle_checked()}</SelectItem>
|
||||
<SelectItem value="false">{m.toggle_unchecked()}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)
|
||||
@@ -537,7 +537,7 @@ function ConditionValueInput({
|
||||
return (
|
||||
<DebouncedInput
|
||||
type="text"
|
||||
placeholder="Enter a value"
|
||||
placeholder={m.enter_a_value()}
|
||||
value={value as string}
|
||||
onChange={onChange}
|
||||
/>
|
||||
|
||||
@@ -26,6 +26,7 @@ import { useEffect, useMemo, useState } from 'react'
|
||||
import { useInView } from 'react-intersection-observer'
|
||||
import { toast } from 'sonner'
|
||||
import { FilterPanel } from './filter-panel'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
interface SearchFilterDialogProps {
|
||||
open: boolean
|
||||
@@ -72,7 +73,7 @@ export function SearchFilterDialog({
|
||||
const res = await client.api.teams[':teamId'].settings.$get({
|
||||
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 }
|
||||
},
|
||||
enabled: open,
|
||||
@@ -123,7 +124,7 @@ export function SearchFilterDialog({
|
||||
const fieldName = field?.config?.name || first.field
|
||||
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({
|
||||
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()
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['collections', projectId] })
|
||||
toast.success('Collection saved')
|
||||
toast.success(m.collection_saved())
|
||||
onOpenChange(false)
|
||||
navigate({
|
||||
to: '/projects/$projectId/collections/$collectionId',
|
||||
@@ -184,7 +185,7 @@ export function SearchFilterDialog({
|
||||
})
|
||||
if (!res.ok) {
|
||||
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 {
|
||||
data: AssetInfo[]
|
||||
@@ -255,7 +256,7 @@ export function SearchFilterDialog({
|
||||
<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]">
|
||||
<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>
|
||||
|
||||
<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}
|
||||
onChange={(e) => setSearchInput(e.target.value)}
|
||||
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"
|
||||
/>
|
||||
@@ -291,7 +292,7 @@ export function SearchFilterDialog({
|
||||
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"
|
||||
>
|
||||
Search
|
||||
{m.search_button()}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -315,12 +316,12 @@ export function SearchFilterDialog({
|
||||
!semanticSearchEnabled && 'opacity-50 cursor-not-allowed',
|
||||
)}
|
||||
>
|
||||
Semantic Search
|
||||
{m.semantic_search()}
|
||||
</Label>
|
||||
</div>
|
||||
{!semanticSearchEnabled && (
|
||||
<span className="text-[10px] text-muted-foreground italic">
|
||||
* Semantic search requires an enabled embedding agent.
|
||||
{m.semantic_search_requires_embedding()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
@@ -338,12 +339,12 @@ export function SearchFilterDialog({
|
||||
) : (
|
||||
<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>
|
||||
|
||||
{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">
|
||||
{activeFiltersCount} active
|
||||
{activeFiltersCount} {m.active_filters()}
|
||||
</span>
|
||||
)}
|
||||
</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"
|
||||
>
|
||||
Reset
|
||||
{m.reset()}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
@@ -383,14 +384,12 @@ export function SearchFilterDialog({
|
||||
<div className="p-4 md:p-5">
|
||||
<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">
|
||||
Search Results
|
||||
{m.search_results()}
|
||||
</span>
|
||||
{isLoading && (
|
||||
<span className="inline-flex items-center gap-1.5 text-xs text-primary">
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
{isSemantic
|
||||
? 'Semantic search using media intelligence might be slow...'
|
||||
: 'Querying database...'}
|
||||
{isSemantic ? m.semantic_search_slow() : m.querying_database()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
@@ -399,25 +398,25 @@ export function SearchFilterDialog({
|
||||
{!hasActiveCriteria ? (
|
||||
<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" />
|
||||
<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">
|
||||
Type your query above and click the Search button to display results.
|
||||
{m.type_query_instruction()}
|
||||
</p>
|
||||
{isSemantic && (
|
||||
<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
|
||||
text, but won't be strictly filtered. If you need accurate filtering, please
|
||||
add filter conditions to control that.
|
||||
{m.semantic_search_note()}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : searchError ? (
|
||||
<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" />
|
||||
<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">
|
||||
{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}
|
||||
</p>
|
||||
</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">
|
||||
<AlertCircle className="w-10 h-10 text-muted-foreground/30 mb-2" />
|
||||
<h3 className="text-sm font-semibold text-foreground/80">
|
||||
No records matched your criteria
|
||||
{m.no_records_matched()}
|
||||
</h3>
|
||||
<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>
|
||||
</div>
|
||||
) : (
|
||||
@@ -479,15 +478,15 @@ export function SearchFilterDialog({
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground block mt-0.5 truncate">
|
||||
{record.type === 'folder'
|
||||
? 'Folder'
|
||||
: `Size: ${formatSize(record.sizeByte || 0)}`}
|
||||
? m.folder()
|
||||
: `${m.size_prefix()} ${formatSize(record.sizeByte || 0)}`}
|
||||
</span>
|
||||
{record.startTime !== undefined &&
|
||||
record.startTime !== null &&
|
||||
record.endTime !== undefined &&
|
||||
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">
|
||||
Match found at {formatTimestamp(record.startTime)} -{' '}
|
||||
{m.match_found_at()} {formatTimestamp(record.startTime)} -{' '}
|
||||
{formatTimestamp(record.endTime)}
|
||||
</span>
|
||||
)}
|
||||
@@ -516,13 +515,7 @@ export function SearchFilterDialog({
|
||||
{/* Footer ported from Demo */}
|
||||
<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">
|
||||
<span>
|
||||
Matched{' '}
|
||||
<strong className="font-mono font-bold text-foreground">
|
||||
{formatMatchedCount(totalCount)}
|
||||
</strong>{' '}
|
||||
items
|
||||
</span>
|
||||
<span>{m.matched_items({ count: formatMatchedCount(totalCount) })}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -536,10 +529,10 @@ export function SearchFilterDialog({
|
||||
{isSaving ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-3 w-3 animate-spin" />
|
||||
Saving...
|
||||
{m.saving_ellipsis()}
|
||||
</>
|
||||
) : (
|
||||
'Save as collection'
|
||||
m.save_as_collection()
|
||||
)}
|
||||
</Button>
|
||||
|
||||
@@ -548,7 +541,7 @@ export function SearchFilterDialog({
|
||||
className="h-8 text-[10px] font-semibold uppercase tracking-wider"
|
||||
onClick={isSemantic ? () => onOpenChange(false) : handleApply}
|
||||
>
|
||||
{isSemantic ? 'Close' : 'Apply and Close'}
|
||||
{isSemantic ? m.close() : m.apply_and_close()}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/ui/components/ui/select'
|
||||
import { useMemo } from 'react'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
interface SortControlProps {
|
||||
fields: MetadataFieldInfo[]
|
||||
@@ -18,22 +20,21 @@ interface SortControlProps {
|
||||
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) {
|
||||
const allFields = [
|
||||
...SYSTEM_FIELDS,
|
||||
...fields.map((f) => ({
|
||||
const allFields = useMemo(() => {
|
||||
const sys = [
|
||||
{ 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!,
|
||||
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
|
||||
const currentFieldId = sort?.field || 'custom'
|
||||
@@ -43,15 +44,15 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
|
||||
|
||||
const getDirectionOptions = (fieldId: string) => {
|
||||
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)) {
|
||||
return { asc: 'Oldest → Newest', desc: 'Newest → Oldest' }
|
||||
return { asc: m.sort_oldest_to_newest(), desc: m.sort_newest_to_oldest() }
|
||||
}
|
||||
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)
|
||||
@@ -79,13 +80,13 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
|
||||
className="h-8"
|
||||
disabled={disabled}
|
||||
>
|
||||
{sort ? `Sorted by ${currentField.label}` : 'Sort by'}
|
||||
{sort ? m.sorted_by({ field: currentField.label }) : m.sort_by()}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-[280px] p-3" align="end">
|
||||
<div className="grid gap-4">
|
||||
<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}>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue />
|
||||
@@ -102,7 +103,7 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
|
||||
|
||||
{currentFieldId !== 'custom' && (
|
||||
<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
|
||||
variant="outline"
|
||||
className="w-full justify-between font-normal"
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from '@/ui/components/ui/dropdown-menu'
|
||||
import { ArrowDownWideNarrow, ArrowUpNarrowWide, Check } from 'lucide-react'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
interface SortDropdownProps {
|
||||
sortBy: string
|
||||
@@ -26,11 +27,11 @@ export function SortDropdown({ sortBy, sortDirection, onSortChange }: SortDropdo
|
||||
const formatSortBy = (field: string) => {
|
||||
switch (field) {
|
||||
case 'name':
|
||||
return 'Name'
|
||||
return m.sort_name()
|
||||
case 'created_at':
|
||||
return 'Created'
|
||||
return m.sort_created()
|
||||
case 'updated_at':
|
||||
return 'Updated'
|
||||
return m.sort_updated()
|
||||
default:
|
||||
return field
|
||||
}
|
||||
@@ -42,12 +43,12 @@ export function SortDropdown({ sortBy, sortDirection, onSortChange }: SortDropdo
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<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>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<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 */}
|
||||
<DropdownMenu>
|
||||
@@ -83,14 +84,14 @@ export function SortDropdown({ sortBy, sortDirection, onSortChange }: SortDropdo
|
||||
<span className="text-muted-foreground">
|
||||
{sortBy === 'name' ? (
|
||||
isAsc ? (
|
||||
<>from A → Z</>
|
||||
<>{m.sort_a_to_z()}</>
|
||||
) : (
|
||||
<>from Z → A</>
|
||||
<>{m.sort_z_to_a()}</>
|
||||
)
|
||||
) : isAsc ? (
|
||||
<>Oldest → Newest</>
|
||||
<>{m.sort_oldest_to_newest()}</>
|
||||
) : (
|
||||
<>Newest → Oldest</>
|
||||
<>{m.sort_newest_to_oldest()}</>
|
||||
)}
|
||||
</span>
|
||||
{isAsc ? (
|
||||
|
||||
@@ -137,6 +137,7 @@
|
||||
"created_date": "Created Date",
|
||||
"collection_created": "Collection created",
|
||||
"failed_create_collection": "Failed to create collection",
|
||||
"failed_save_collection": "Failed to 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": "Sorted by {field}",
|
||||
"sorted_by_label": "Sorted by",
|
||||
"order": "Order",
|
||||
"custom": "Custom",
|
||||
"date_created": "Date Created",
|
||||
|
||||
@@ -137,6 +137,7 @@
|
||||
"created_date": "创建日期",
|
||||
"collection_created": "收藏集已创建",
|
||||
"failed_create_collection": "创建收藏集失败",
|
||||
"failed_save_collection": "保存收藏集失败",
|
||||
"loading_collection": "正在加载收藏集...",
|
||||
"untitled_collection": "未命名收藏集",
|
||||
"collection_saved": "收藏集已保存",
|
||||
@@ -178,6 +179,7 @@
|
||||
"field": "字段",
|
||||
"sort_by": "排序",
|
||||
"sorted_by": "按{field}排序",
|
||||
"sorted_by_label": "排序方式",
|
||||
"order": "顺序",
|
||||
"custom": "自定义",
|
||||
"date_created": "创建日期",
|
||||
|
||||
@@ -128,6 +128,7 @@ export * from "./creator.js";
|
||||
export * from "./created_date.js";
|
||||
export * from "./collection_created.js";
|
||||
export * from "./failed_create_collection.js";
|
||||
export * from "./failed_save_collection.js";
|
||||
export * from "./loading_collection.js";
|
||||
export * from "./untitled_collection.js";
|
||||
export * from "./collection_saved.js";
|
||||
@@ -167,6 +168,7 @@ export * from "./list.js";
|
||||
export * from "./field.js";
|
||||
export * from "./sort_by.js";
|
||||
export * from "./sorted_by.js";
|
||||
export * from "./sorted_by_label.js";
|
||||
export * from "./order.js";
|
||||
export * from "./custom.js";
|
||||
export * from "./date_created.js";
|
||||
|
||||
@@ -130,6 +130,7 @@ export * from './creator.js'
|
||||
export * from './created_date.js'
|
||||
export * from './collection_created.js'
|
||||
export * from './failed_create_collection.js'
|
||||
export * from './failed_save_collection.js'
|
||||
export * from './loading_collection.js'
|
||||
export * from './untitled_collection.js'
|
||||
export * from './collection_saved.js'
|
||||
@@ -169,6 +170,7 @@ export * from './list.js'
|
||||
export * from './field.js'
|
||||
export * from './sort_by.js'
|
||||
export * from './sorted_by.js'
|
||||
export * from './sorted_by_label.js'
|
||||
export * from './order.js'
|
||||
export * from './custom.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)
|
||||
});
|
||||
@@ -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)
|
||||
});
|
||||
Reference in New Issue
Block a user