Skip to content

Commit

Permalink
Add createFilterUnique to deploy-web project
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Apr 3, 2024
1 parent a1ea942 commit c400d69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions deploy-web/src/components/providers/ProviderListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { Uptime } from "./Uptime";
import React from "react";
import { hasSomeParentTheClass } from "@src/utils/domUtils";
import { cx } from "@emotion/css";
import CheckIcon from "@mui/icons-material/Check";
import WarningIcon from "@mui/icons-material/Warning";
import { createFilterUnique } from "@src/utils/array";

const useStyles = makeStyles()(theme => ({
root: {
Expand Down Expand Up @@ -62,7 +62,7 @@ export const ProviderListRow: React.FunctionComponent<Props> = ({ provider }) =>
const _totalStorage = provider.isOnline
? bytesToShrink(provider.availableStats.storage + provider.pendingStats.storage + provider.activeStats.storage)
: null;
const gpuModels = provider.gpuModels.map(x => x.model).filter((x, i, arr) => arr.indexOf(x) === i);
const gpuModels = provider.gpuModels.map(x => x.model).filter(createFilterUnique());

const onStarClick = event => {
event.preventDefault();
Expand Down
3 changes: 2 additions & 1 deletion deploy-web/src/components/providers/ProviderSpecs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { makeStyles } from "tss-react/mui";
import { ClientProviderDetailWithStatus } from "@src/types/provider";
import { LabelValue } from "../shared/LabelValue";
import CheckIcon from "@mui/icons-material/Check";
import { createFilterUnique } from "@src/utils/array";

const useStyles = makeStyles()(theme => ({
root: {
Expand All @@ -26,7 +27,7 @@ export const ProviderSpecs: React.FunctionComponent<Props> = ({ provider }) => {
const gpuModels =
provider?.gpuModels
?.map(x => x.model + " " + x.ram)
.filter((x, i, arr) => arr.indexOf(x) === i)
.filter(createFilterUnique())
.sort((a, b) => a.localeCompare(b)) || [];

return (
Expand Down
7 changes: 7 additions & 0 deletions deploy-web/src/utils/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Matcher<T> = (a: T, b: T) => boolean;

export function createFilterUnique<T>(matcher: Matcher<T> = (a, b) => a === b): (value: T, index: number, array: T[]) => boolean {
return (value, index, array) => {
return array.findIndex(other => matcher(value, other)) === index;
};
}

0 comments on commit c400d69

Please sign in to comment.