Skip to content

Commit

Permalink
chore: Simplified filter logic for variants resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
matvp91 committed Oct 3, 2024
1 parent f78b946 commit b77f6c1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
1 change: 0 additions & 1 deletion packages/dashboard/src/components/Storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export function Storage({ path }: StorageProps) {
</div>
{contents ? (
<StorageTable
path={path}
contents={contents}
onNext={fetchNextPage}
setFile={setFile}
Expand Down
3 changes: 0 additions & 3 deletions packages/dashboard/src/components/StorageTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import { StoragePathBreadcrumbs } from "./StoragePathBreadcrumbs";
import { StorageRow } from "./StorageRow";
import type { UIEventHandler } from "react";
import type { FileDto, FolderContentDto } from "@/tsr";

type StorageExplorerProps = {
path: string;
contents: FolderContentDto[];
onNext(): void;
setFile(file: FileDto): void;
};

export function StorageTable({
path,
contents,
onNext,
setFile,
Expand Down
2 changes: 1 addition & 1 deletion packages/stitcher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ RUN turbo run build
FROM base as runner
WORKDIR /app
COPY --from=installer ./app .
CMD [ "node", "packages/stitcher/dist/src/index.js" ]
CMD [ "node", "packages/stitcher/dist/index.js" ]
36 changes: 13 additions & 23 deletions packages/stitcher/src/presentation/filters.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import type { Variant } from "../parser/index.js";

const FILTER_VARIANTS_OPERATOR = {
"<": (a: number, b: number) => a < b,
"<=": (a: number, b: number) => a <= b,
">": (a: number, b: number) => a > b,
">=": (a: number, b: number) => a >= b,
} as const;

export function filterVariants(variants: Variant[], resolution: string) {
const [operator, value] = resolution.split(" ");

const height = parseInt(value, 10);

if (operator === "<") {
return variants.filter(
(item) => item.resolution && item.resolution?.height < height,
);
}

if (operator === "<=") {
return variants.filter(
(item) => item.resolution && item.resolution?.height <= height,
);
}

if (operator === ">") {
return variants.filter(
(item) => item.resolution && item.resolution?.height > height,
);
}

if (operator === ">=") {
return variants.filter(
(item) => item.resolution && item.resolution?.height >= height,
);
const fn = FILTER_VARIANTS_OPERATOR[operator];
if (typeof fn !== "function") {
throw new Error(`Invalid filter: ${operator} ${value}`);
}

throw new Error("Invalid filter");
return variants.filter(
(item) => item.resolution && fn(item.resolution.height, height),
);
}

0 comments on commit b77f6c1

Please sign in to comment.