mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-23 16:24:06 +00:00
fix: type safety and i18n improvements for dropdown components
- Add i18n for sort options (sortDefault, sortAZ) - Fix type assertions in FormSearchInput and FormDropdown - Fix missing value check using getAssetFilename - Add aria-label to ownership filter button - Update test for undefined date handling Amp-Thread-ID: https://ampcode.com/threads/T-019c1136-78ff-7149-a185-a814b0e4f933 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -2560,6 +2560,7 @@
|
||||
"selectModelType": "Select model type",
|
||||
"selectProjects": "Select Projects",
|
||||
"sortAZ": "A-Z",
|
||||
"sortDefault": "Default",
|
||||
"sortBy": "Sort by",
|
||||
"sortingType": "Sorting Type",
|
||||
"sortPopular": "Popular",
|
||||
|
||||
@@ -148,6 +148,7 @@ describe('AssetFilterBar', () => {
|
||||
expect(finalState.fileFormats).toEqual(['ckpt', 'safetensors'])
|
||||
expect(finalState.baseModels).toEqual(['sdxl'])
|
||||
expect(finalState.sortBy).toBe('name-desc')
|
||||
expect(finalState.ownership).toBe('all')
|
||||
})
|
||||
|
||||
it('ensures AssetFilterState interface compliance', async () => {
|
||||
|
||||
@@ -104,7 +104,7 @@ describe('sortAssets', () => {
|
||||
const items = [
|
||||
createItem('no-date'),
|
||||
createItem('has-date', { created_at: '2024-01-01T00:00:00Z' }),
|
||||
createItem('null-date', { created_at: null as unknown as string })
|
||||
createItem('undefined-date', { created_at: undefined })
|
||||
]
|
||||
const result = sortAssets(items, 'recent')
|
||||
expect(result[0].name).toBe('has-date')
|
||||
|
||||
@@ -176,7 +176,7 @@ const missingValueItem = computed<FormDropdownItem | undefined>(() => {
|
||||
// Check in cloud mode assets
|
||||
if (props.isAssetMode && assetData) {
|
||||
const existsInAssets = assetData.assets.value.some(
|
||||
(asset) => asset.name === currentValue
|
||||
(asset) => getAssetFilename(asset) === currentValue
|
||||
)
|
||||
if (existsInAssets) return undefined
|
||||
|
||||
@@ -398,9 +398,9 @@ async function handleFilesUpdate(files: File[]) {
|
||||
|
||||
// 2. Update widget options to include new files
|
||||
// This simulates what addToComboValues does but for SimplifiedWidget
|
||||
if (props.widget.options?.values) {
|
||||
const values = props.widget.options?.values
|
||||
if (Array.isArray(values)) {
|
||||
uploadedPaths.forEach((path) => {
|
||||
const values = props.widget.options!.values as string[]
|
||||
if (!values.includes(path)) {
|
||||
values.push(path)
|
||||
}
|
||||
|
||||
@@ -53,8 +53,10 @@ watch(
|
||||
)
|
||||
|
||||
function handleFocus(event: FocusEvent) {
|
||||
const target = event.target as HTMLInputElement
|
||||
target.select()
|
||||
const target = event.target
|
||||
if (target instanceof HTMLInputElement) {
|
||||
target.select()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -125,11 +125,12 @@ const closeDropdown = () => {
|
||||
|
||||
function handleFileChange(event: Event) {
|
||||
if (props.disabled) return
|
||||
const input = event.target as HTMLInputElement
|
||||
if (input.files) {
|
||||
files.value = Array.from(input.files)
|
||||
const target = event.target
|
||||
if (!(target instanceof HTMLInputElement)) return
|
||||
if (target.files) {
|
||||
files.value = Array.from(target.files)
|
||||
}
|
||||
input.value = ''
|
||||
target.value = ''
|
||||
}
|
||||
|
||||
function handleSelection(item: FormDropdownItem, index: number) {
|
||||
|
||||
@@ -165,6 +165,7 @@ function handleOwnershipSelected(item: OwnershipFilterOption) {
|
||||
<button
|
||||
v-if="showOwnershipFilter && ownershipOptions?.length"
|
||||
ref="ownershipTriggerRef"
|
||||
:aria-label="t('assetBrowser.ownership')"
|
||||
:title="t('assetBrowser.ownership')"
|
||||
:class="
|
||||
cn(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { t } from '@/i18n'
|
||||
import type { AssetSortOption } from '@/platform/assets/types/filterTypes'
|
||||
import { sortAssets } from '@/platform/assets/utils/assetSortUtils'
|
||||
|
||||
@@ -31,7 +32,7 @@ function createSortOption(
|
||||
|
||||
export function getDefaultSortOptions(): SortOption<AssetSortOption>[] {
|
||||
return [
|
||||
createSortOption('default', 'Default'),
|
||||
createSortOption('name-asc', 'A-Z')
|
||||
createSortOption('default', t('assetBrowser.sortDefault')),
|
||||
createSortOption('name-asc', t('assetBrowser.sortAZ'))
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user