Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(meta): Fix lint warnings #944

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useState, useEffect, useMemo } from "react";
import { useGetUser } from "@/api";
import { useEffect, useMemo, useState } from "react";
import { UserRoles, opensearch } from "shared-types";

import * as C from "./consts";
import { checkMultiFilter, useOsAggregate, useOsUrl } from "@/components";
import { useLabelMapping } from "@/hooks";
import { useFilterDrawerContext } from "../FilterProvider";
import { checkMultiFilter, useOsAggregate, useOsUrl } from "@/components";
import * as C from "./consts";

type FilterGroup = Partial<Record<opensearch.main.Field, C.DrawerFilterableGroup>>;

Expand Down Expand Up @@ -146,6 +146,7 @@ export const useFilterDrawer = () => {
}, {} as any);
});
setAccordionValues(updateAccordions);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [url.state.filters, drawer.drawerOpen]);

const aggs = useMemo(() => {
Expand All @@ -163,7 +164,7 @@ export const useFilterDrawer = () => {
},
{} as Record<opensearch.main.Field, { label: string; value: string }[]>,
);
}, [_aggs]);
}, [_aggs, labelMap]);

return {
aggs,
Expand Down
11 changes: 6 additions & 5 deletions react-app/src/components/Opensearch/main/useOpensearch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect, useState } from "react";
import { getOsData, useGetUser, useOsSearch } from "@/api";
import { useLzUrl } from "@/hooks";
import { useQuery } from "@tanstack/react-query";
import { useEffect, useState } from "react";
import { useLocation } from "react-router";
import { UserRoles, opensearch } from "shared-types";
import { getOsData, useOsSearch, useGetUser } from "@/api";
import { useLzUrl } from "@/hooks";
import { OsTab } from "./types";
import { createSearchFilterable } from "../utils";
import { useLocation } from "react-router";
import { OsTab } from "./types";

export const DEFAULT_FILTERS: Record<OsTab, Partial<OsUrlState>> = {
spas: {
Expand Down Expand Up @@ -71,6 +71,7 @@ export const useOsData = () => {
};
useEffect(() => {
onRequest(params.state);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [params.queryString]);
return { data, isLoading, error, ...params };
};
Expand Down
4 changes: 2 additions & 2 deletions react-app/src/components/RHF/Slot.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { cn } from "@/utils";
import { useEffect } from "react";
import { ControllerProps, FieldPath, FieldValues } from "react-hook-form";
import type { RHFSlotProps, RHFTextField } from "shared-types";
import { FormControl, FormDescription, FormItem, FormLabel, FormMessage } from "../Inputs";
import { RHFTextDisplay } from ".";
import { SlotField } from "./SlotField";
import { cn } from "@/utils";

export const RHFSlot = <
TFieldValues extends FieldValues = FieldValues,
Expand All @@ -30,7 +30,7 @@ export const RHFSlot = <
return () => {
control.unregister(field.name);
};
}, []);
}, [field.name]);

return (
<FormItem
Expand Down
1 change: 1 addition & 0 deletions react-app/src/components/RHF/dependencyWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const DependencyWrapperHandler = ({
});
changeMethod(filteredArray);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dependentValues, parentValue, changeMethod, dependency]);

switch (dependency?.effect.type) {
Expand Down
1 change: 1 addition & 0 deletions react-app/src/components/SearchForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const SearchForm: FC<{

useEffect(() => {
handleSearch(debouncedSearchString);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedSearchString]);

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand Down
7 changes: 4 additions & 3 deletions react-app/src/features/package/admin-changes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { FC, useMemo } from "react";
import { opensearch } from "shared-types";
import { format } from "date-fns";
import {
Accordion,
AccordionContent,
Expand All @@ -9,6 +6,9 @@ import {
DetailsSection,
} from "@/components";
import { BLANK_VALUE } from "@/consts";
import { format } from "date-fns";
import { FC, useMemo } from "react";
import { opensearch } from "shared-types";
import { usePackageDetailsCache } from "..";

export const AC_WithdrawEnabled: FC<opensearch.changelog.Document> = (props) => {
Expand Down Expand Up @@ -64,6 +64,7 @@ export const AdminChange: FC<opensearch.changelog.Document> = (props) => {
default:
return [BLANK_VALUE, AC_Update];
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.actionType, props.changeType]);

return (
Expand Down
2 changes: 1 addition & 1 deletion react-app/src/hooks/UseMediaQuery.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from "@testing-library/react";
import { describe, it, vi, expect } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { useMediaQuery } from "./useMediaQuery";

describe("UseMediaQuery", () => {
Expand Down
2 changes: 1 addition & 1 deletion react-app/src/hooks/useIdle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function useIdle(
return () => {
events.forEach((event) => document.removeEventListener(event, handleEvents));
};
}, [timeout]);
}, [timeout, events]);

return idle;
}
30 changes: 10 additions & 20 deletions react-app/src/hooks/useMediaQuery.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import { useEffect, useState } from "react";

export function useMediaQuery(query: string): boolean {
const getMatches = (query: string): boolean => {
// Prevents SSR issues
if (typeof window !== "undefined") {
return window.matchMedia(query).matches;
}
return false;
};

const [matches, setMatches] = useState<boolean>(getMatches(query));

function handleChange() {
setMatches(getMatches(query));
}
const [matches, setMatches] = useState(
() => typeof window !== "undefined" && window.matchMedia(query).matches,
);

useEffect(() => {
const matchMedia = window.matchMedia(query);
const mediaQuery = window.matchMedia(query);

// Triggered at the first client-side load and if query changes
handleChange();
const handleChange = () => setMatches(mediaQuery.matches);

matchMedia.addEventListener("change", handleChange);
// Initial check and event listener
handleChange();
mediaQuery.addEventListener("change", handleChange);

return () => {
matchMedia.removeEventListener("change", handleChange);
};
// Cleanup
return () => mediaQuery.removeEventListener("change", handleChange);
}, [query]);

return matches;
Expand Down
Loading