Skip to content

Commit

Permalink
fix(app-file-manager): use type_startsWith for asset filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Jul 23, 2024
1 parent bcac0a9 commit 60e8e8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
}
};
Expand Down

0 comments on commit 60e8e8f

Please sign in to comment.