From 60e8e8f2f7a07e54986f7b4f6085e168f2ec1f12 Mon Sep 17 00:00:00 2001 From: Pavel Denisjuk Date: Tue, 23 Jul 2024 16:35:30 +0200 Subject: [PATCH] fix(app-file-manager): use type_startsWith for asset filtering --- .../modules/FileManagerApiProvider/graphql.ts | 2 +- .../FileManagerViewProvider/useListFiles.ts | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/app-file-manager/src/modules/FileManagerApiProvider/graphql.ts b/packages/app-file-manager/src/modules/FileManagerApiProvider/graphql.ts index 48da25ea3f0..cb14d6bf8bf 100644 --- a/packages/app-file-manager/src/modules/FileManagerApiProvider/graphql.ts +++ b/packages/app-file-manager/src/modules/FileManagerApiProvider/graphql.ts @@ -53,9 +53,9 @@ export interface ListFilesWhereQueryVariables { tags_in?: string[]; tags_startsWith?: string; tags_not_startsWith?: string; - type_in?: string[]; createdBy?: string; AND?: ListFilesWhereQueryVariables[]; + [key: string]: any; } export interface ListFilesQueryVariables { diff --git a/packages/app-file-manager/src/modules/FileManagerRenderer/FileManagerViewProvider/useListFiles.ts b/packages/app-file-manager/src/modules/FileManagerRenderer/FileManagerViewProvider/useListFiles.ts index 2a8843727e9..a28a45b6629 100644 --- a/packages/app-file-manager/src/modules/FileManagerRenderer/FileManagerViewProvider/useListFiles.ts +++ b/packages/app-file-manager/src/modules/FileManagerRenderer/FileManagerViewProvider/useListFiles.ts @@ -16,9 +16,13 @@ import { useFileManagerApi } from "~/modules/FileManagerApiProvider/FileManagerA import { getScopeWhereParams, State } from "./state"; import { ROOT_FOLDER } from "~/constants"; +const toTypeInput = (value: string) => { + return value.replace("*", ""); +}; + function nonEmptyArray(value: string[] | undefined, fallback: string[] | undefined = undefined) { if (Array.isArray(value)) { - return value.length ? value : undefined; + return value.length ? value.map(toTypeInput) : undefined; } return fallback; @@ -98,6 +102,15 @@ export function useListFiles({ modifiers, folderId, state }: UseListFilesParams) const AND: ListFilesWhereQueryVariables[] = []; + if (modifiers.accept.length) { + const types = nonEmptyArray(modifiers.accept); + if (types) { + AND.push({ + OR: types.map(type => ({ type_startsWith: type })) + }); + } + } + if (state.filters) { AND.push(state.filters); } @@ -130,7 +143,6 @@ export function useListFiles({ modifiers, folderId, state }: UseListFilesParams) ...getScopeWhereParams(modifiers.scope), location: locationWhere, createdBy: modifiers.own ? identity!.id : undefined, - type_in: nonEmptyArray(modifiers.accept), AND: AND.length > 0 ? AND : undefined } };