Skip to content

Commit 50698de

Browse files
committed
fix: disable inspect for non-previewable assets
1 parent 91ad50b commit 50698de

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
lines changed

packages/shared-frontend-utils/src/formatUtil.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest'
33
import {
44
getMediaTypeFromFilename,
55
highlightQuery,
6+
isPreviewableMediaType,
67
truncateFilename
78
} from './formatUtil'
89

@@ -196,4 +197,18 @@ describe('formatUtil', () => {
196197
)
197198
})
198199
})
200+
201+
describe('isPreviewableMediaType', () => {
202+
it('returns true for image/video/audio/3D', () => {
203+
expect(isPreviewableMediaType('image')).toBe(true)
204+
expect(isPreviewableMediaType('video')).toBe(true)
205+
expect(isPreviewableMediaType('audio')).toBe(true)
206+
expect(isPreviewableMediaType('3D')).toBe(true)
207+
})
208+
209+
it('returns false for text/other', () => {
210+
expect(isPreviewableMediaType('text')).toBe(false)
211+
expect(isPreviewableMediaType('other')).toBe(false)
212+
})
213+
})
199214
})

packages/shared-frontend-utils/src/formatUtil.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,12 @@ export function getMediaTypeFromFilename(
583583

584584
return 'other'
585585
}
586+
587+
export function isPreviewableMediaType(mediaType: MediaType): boolean {
588+
return (
589+
mediaType === 'image' ||
590+
mediaType === 'video' ||
591+
mediaType === 'audio' ||
592+
mediaType === '3D'
593+
)
594+
}

src/components/sidebar/tabs/AssetsSidebarTab.vue

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ import { resolveOutputAssetItems } from '@/platform/assets/utils/outputAssetUtil
243243
import { isCloud } from '@/platform/distribution/types'
244244
import { useDialogStore } from '@/stores/dialogStore'
245245
import { ResultItemImpl } from '@/stores/queueStore'
246-
import { formatDuration, getMediaTypeFromFilename } from '@/utils/formatUtil'
246+
import {
247+
formatDuration,
248+
getMediaTypeFromFilename,
249+
isPreviewableMediaType
250+
} from '@/utils/formatUtil'
247251
import { cn } from '@/utils/tailwindUtil'
248252
249253
const { t } = useI18n()
@@ -404,6 +408,12 @@ const visibleAssets = computed(() => {
404408
return listViewSelectableAssets.value
405409
})
406410
411+
const previewableVisibleAssets = computed(() =>
412+
visibleAssets.value.filter((asset) =>
413+
isPreviewableMediaType(getMediaTypeFromFilename(asset.name))
414+
)
415+
)
416+
407417
const selectedAssets = computed(() => getSelectedAssets(visibleAssets.value))
408418
409419
const isBulkMode = computed(
@@ -429,12 +439,10 @@ watch(visibleAssets, (newAssets) => {
429439
// so selection stays consistent with what this view can act on.
430440
reconcileSelection(newAssets)
431441
if (currentGalleryAssetId.value && galleryActiveIndex.value !== -1) {
432-
const newIndex = newAssets.findIndex(
442+
const newIndex = previewableVisibleAssets.value.findIndex(
433443
(asset) => asset.id === currentGalleryAssetId.value
434444
)
435-
if (newIndex !== -1) {
436-
galleryActiveIndex.value = newIndex
437-
}
445+
galleryActiveIndex.value = newIndex
438446
}
439447
})
440448
@@ -445,7 +453,7 @@ watch(galleryActiveIndex, (index) => {
445453
})
446454
447455
const galleryItems = computed(() => {
448-
return visibleAssets.value.map((asset) => {
456+
return previewableVisibleAssets.value.map((asset) => {
449457
const mediaType = getMediaTypeFromFilename(asset.name)
450458
const resultItem = new ResultItemImpl({
451459
filename: asset.name,
@@ -545,6 +553,9 @@ const handleDeleteSelected = async () => {
545553
546554
const handleZoomClick = (asset: AssetItem) => {
547555
const mediaType = getMediaTypeFromFilename(asset.name)
556+
if (!isPreviewableMediaType(mediaType)) {
557+
return
558+
}
548559
549560
if (mediaType === '3D') {
550561
const dialogStore = useDialogStore()
@@ -564,7 +575,9 @@ const handleZoomClick = (asset: AssetItem) => {
564575
}
565576
566577
currentGalleryAssetId.value = asset.id
567-
const index = visibleAssets.value.findIndex((a) => a.id === asset.id)
578+
const index = previewableVisibleAssets.value.findIndex(
579+
(a) => a.id === asset.id
580+
)
568581
if (index !== -1) {
569582
galleryActiveIndex.value = index
570583
}

src/platform/assets/components/MediaAssetCard.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
>
6060
<IconGroup background-class="bg-white">
6161
<Button
62+
v-if="canInspect"
6263
variant="overlay-white"
6364
size="icon"
6465
:aria-label="$t('mediaAsset.actions.zoom')"
@@ -141,7 +142,8 @@ import {
141142
formatDuration,
142143
formatSize,
143144
getFilenameDetails,
144-
getMediaTypeFromFilename
145+
getMediaTypeFromFilename,
146+
isPreviewableMediaType
145147
} from '@/utils/formatUtil'
146148
import { cn } from '@/utils/tailwindUtil'
147149
@@ -217,6 +219,8 @@ const previewKind = computed((): PreviewKind => {
217219
return getMediaTypeFromFilename(asset?.name || '')
218220
})
219221
222+
const canInspect = computed(() => isPreviewableMediaType(fileKind.value))
223+
220224
// Get filename without extension
221225
const fileName = computed(() => {
222226
return getFilenameDetails(asset?.name || '').filename
@@ -278,7 +282,7 @@ const showActionsOverlay = computed(() => {
278282
})
279283
280284
const handleZoomClick = () => {
281-
if (asset) {
285+
if (asset && canInspect.value) {
282286
emit('zoom', asset)
283287
}
284288
}

src/platform/assets/components/MediaAssetContextMenu.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { useI18n } from 'vue-i18n'
3939
import Button from '@/components/ui/button/Button.vue'
4040
import { isCloud } from '@/platform/distribution/types'
4141
import { supportsWorkflowMetadata } from '@/platform/workflow/utils/workflowExtractionUtil'
42+
import { isPreviewableMediaType } from '@/utils/formatUtil'
4243
import { detectNodeTypeFromFilename } from '@/utils/loaderNodeUtil'
4344
import { cn } from '@/utils/tailwindUtil'
4445
@@ -193,8 +194,8 @@ const contextMenuItems = computed<MenuItem[]>(() => {
193194
194195
// Individual mode: Show all menu options
195196
196-
// Inspect (if not 3D)
197-
if (fileKind !== '3D') {
197+
// Inspect
198+
if (isPreviewableMediaType(fileKind)) {
198199
items.push({
199200
label: t('mediaAsset.actions.inspect'),
200201
icon: 'icon-[lucide--zoom-in]',

0 commit comments

Comments
 (0)