Skip to content

Commit

Permalink
Frontend: Cleanup 42 js warnings (#16219)
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelElysia authored Jan 23, 2024
1 parent 2d33344 commit 82887fc
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import { Meta, StoryObj } from "@storybook/react";

import DeviceUserError from "./DeviceUserError";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import { Meta, StoryObj } from "@storybook/react";

import FleetMarkdown from "./FleetMarkdown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Story = StoryObj<typeof LastUpdatedText>;

export const Basic: Story = {};

export const withLastUpdatedAt: Story = {
export const WithLastUpdatedAt: Story = {
args: {
lastUpdatedAt: "2021-01-01T00:00:00Z",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Children } from "react";
import React from "react";
import { render, screen } from "@testing-library/react";
import { DEFAULT_EMPTY_CELL_VALUE } from "utilities/constants";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ChangeEmailForm extends Component {
const { fields, handleSubmit, onCancel } = this.props;

return (
<form onSubmit={handleSubmit}>
<form className={baseClass} onSubmit={handleSubmit}>
To update your email you must confirm your password.
<InputField
{...fields.password}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import React from "react";
import { Meta, StoryObj } from "@storybook/react";

import InputField from ".";

const meta = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const ActivityFeed = ({
{
keepPreviousData: true,
staleTime: 5000,
onSuccess: (data) => {
onSuccess: () => {
setShowActivityFeedTitle(true);
},
onError: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import createMockActivity from "__mocks__/activityMock";
import createMockQuery from "__mocks__/queryMock";
import { createMockTeamSummary } from "__mocks__/teamMock";
import { ActivityType } from "interfaces/activity";
import { createCustomRenderer } from "test/test-utils";
import createMockConfig from "__mocks__/configMock";

import ActivityItem from ".";

Expand Down
34 changes: 17 additions & 17 deletions frontend/pages/LabelPage/LabelPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ const LabelPage = ({
);
const { renderFlash } = useContext(NotificationContext);

const { data: labels, error: labelsError } = useQuery<
ILabelsResponse,
Error,
ILabel[]
>(["labels"], () => labelsAPI.loadAll(), {
select: (data: ILabelsResponse) => data.labels,
onSuccess: (responseLabels: ILabel[]) => {
if (params.label_id) {
const selectLabel = responseLabels.find(
(label) => label.id === parseInt(params.label_id, 10)
);
setSelectedLabel(selectLabel);
setIsLoading(false);
}
},
});
const { error: labelsError } = useQuery<ILabelsResponse, Error, ILabel[]>(
["labels"],
() => labelsAPI.loadAll(),
{
select: (data: ILabelsResponse) => data.labels,
onSuccess: (responseLabels: ILabel[]) => {
if (params.label_id) {
const selectLabel = responseLabels.find(
(label) => label.id === parseInt(params.label_id, 10)
);
setSelectedLabel(selectLabel);
setIsLoading(false);
}
},
}
);

const onCloseSchemaSidebar = () => {
setSidePanelOpen(false);
Expand Down Expand Up @@ -145,7 +145,7 @@ const LabelPage = ({
"Label created. Try refreshing this page in just a moment to see the updated host count for your label."
);
})
.catch((updateError: any) => {
.catch((updateError: { data: IApiError }) => {
if (updateError.data.errors[0].reason.includes("Duplicate")) {
setLabelValidator({
name: "A label with this name already exists",
Expand Down
27 changes: 11 additions & 16 deletions frontend/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useEffect, useContext, useCallback } from "react";
import { useQuery } from "react-query";
import { InjectedRouter } from "react-router";
import { size } from "lodash";
import { AxiosError } from "axios";

import paths from "router/paths";
Expand Down Expand Up @@ -62,21 +61,17 @@ const LoginPage = ({ router, location }: ILoginPageProps) => {

const [errors, setErrors] = useState<Record<string, string>>({});

const {
data: ssoSettings,
isLoading: isLoadingSSOSettings,
error: errorSSOSettings,
} = useQuery<ISSOSettingsResponse, Error, ISSOSettings>(
["ssoSettings"],
() => sessionsAPI.ssoSettings(),
{
enabled: !currentUser,
onError: (err) => {
console.error(err);
},
select: (data) => data.settings,
}
);
const { data: ssoSettings, isLoading: isLoadingSSOSettings } = useQuery<
ISSOSettingsResponse,
Error,
ISSOSettings
>(["ssoSettings"], () => sessionsAPI.ssoSettings(), {
enabled: !currentUser,
onError: (err) => {
console.error(err);
},
select: (data) => data.settings,
});

useEffect(() => {
// this only needs to run once so we can wrap it in useEffect to avoid unneccesary third-party
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/LoginPage/LoginPreviewPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useContext } from "react";
import React, { useEffect, useContext } from "react";
import { InjectedRouter } from "react-router";

import paths from "router/paths";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useContext } from "react";
import React from "react";
import { useQuery } from "react-query";

import { AppContext } from "context/app";
import mdmAPI, { IDiskEncryptionSummaryResponse } from "services/entities/mdm";

import TableContainer from "components/TableContainer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const TargetSection = ({

// We make the call at this component as multiple children components need
// this data.
const { data: teamData, isLoading: isLoadingTeam, isError } = useQuery<
const { data: teamData, isLoading: isLoadingTeam } = useQuery<
ILoadTeamResponse,
Error,
ITeamConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FormEvent, useState, useContext, useEffect } from "react";
import React, { FormEvent, useState, useContext } from "react";

import { AppContext } from "context/app";

Expand Down
1 change: 0 additions & 1 deletion frontend/pages/admin/OrgSettingsPage/cards/Info/Info.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState } from "react";
import classnames from "classnames";

import Button from "components/buttons/Button";
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useContext } from "react";

import { ITeam } from "interfaces/team";
import { IRole } from "interfaces/role";
import { UserRole } from "interfaces/user";
// ignore TS error for now until these are rewritten in ts.
// @ts-ignore
Expand All @@ -18,8 +17,6 @@ interface ISelectRoleFormProps {
isApiOnly?: boolean;
}

const baseClass = "select-role-form";

const generateSelectedTeamData = (
allTeams: ITeam[],
updatedTeam?: any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useCallback, useContext, useMemo } from "react";
import { InjectedRouter } from "react-router";
import { useQuery } from "react-query";
import memoize from "memoize-one";

import paths from "router/paths";
import { IApiError } from "interfaces/errors";
Expand Down
4 changes: 2 additions & 2 deletions frontend/pages/hosts/ManageHostsPage/HostTableConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ const allHostTableHeaders: IDataColumn[] = [
},
{
title: "MDM status",
Header: (cellProps: IHeaderProps): JSX.Element => {
Header: (): JSX.Element => {
const titleWithToolTip = (
<TooltipWrapper
tipContent={
Expand Down Expand Up @@ -414,7 +414,7 @@ const allHostTableHeaders: IDataColumn[] = [
},
{
title: "MDM server URL",
Header: (cellProps: IHeaderProps): JSX.Element => {
Header: (): JSX.Element => {
const titleWithToolTip = (
<TooltipWrapper
tipContent={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
MdmProfileStatus,
} from "interfaces/mdm";
import { IMunkiIssuesAggregate } from "interfaces/macadmins";
import { ISoftware } from "interfaces/software";
import { IPolicy } from "interfaces/policy";
import {
HOSTS_QUERY_PARAMS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const HostDetailsPage = ({
const [refetchStartTime, setRefetchStartTime] = useState<number | null>(null);
const [showRefetchSpinner, setShowRefetchSpinner] = useState(false);
const [schedule, setSchedule] = useState<IQueryStats[]>();
const [packsState, setPacksState] = useState<IPackStats[]>();
const [packsState, setPackState] = useState<IPackStats[]>();
const [hostSoftware, setHostSoftware] = useState<ISoftware[]>([]);
const [usersState, setUsersState] = useState<{ username: string }[]>([]);
const [usersSearchString, setUsersSearchString] = useState("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { IHostEncrpytionKeyResponse } from "interfaces/host";
import hostAPI from "services/entities/hosts";

import Modal from "components/Modal";
import CustomLink from "components/CustomLink";
import Button from "components/buttons/Button";
import InputFieldHiddenContent from "components/forms/fields/InputFieldHiddenContent";
import DataError from "components/DataError";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ interface IDataColumn {
// or one of the custom `filterTypes` defined for the `useTable` instance (see `DataTable`)
}

interface IMunkiIssueTableData extends IMunkiIssue {
time: string;
}

// NOTE: cellProps come from react-table
// more info here https://react-table.tanstack.com/docs/api/useTable#cell-properties
export const munkiIssuesTableHeaders: IDataColumn[] = [
Expand Down
3 changes: 0 additions & 3 deletions frontend/pages/hosts/details/cards/Policies/Policies.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React from "react";

import { IHostPolicy } from "interfaces/policy";
import InfoBanner from "components/InfoBanner";
import TableContainer from "components/TableContainer";
import CustomLink from "components/CustomLink";
import EmptyTable from "components/EmptyTable";

import {
generatePolicyTableHeaders,
generatePolicyDataSet,
} from "./HostPoliciesTable/HostPoliciesTableConfig";
import PolicyFailingCount from "./HostPoliciesTable/PolicyFailingCount";
import { isValidPolicyResponse } from "../../../ManageHostsPage/helpers";

interface IPoliciesProps {
policies: IHostPolicy[];
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/hosts/details/cards/Queries/HostQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const HostQueries = ({
);

return (
<div className="section section--host-queries">
<div className={`section section--${baseClass}`}>
<p className="section__header">Queries</p>
{!schedule || !schedule.length || isChromeOSHost ? (
renderEmptyQueriesTab()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ const generateTableHeaders = (
};

// The next update will match the next host count update, unless extra time is needed for hosts to send in their policy results.
const nextPolicyUpdateMs = function (
const nextPolicyUpdateMs = (
policyItemUpdatedAtMs: Date,
nextHostCountUpdateMs: number,
hostCountUpdateIntervalMs: number,
osqueryPolicyMs: number
) {
) => {
let timeFromPolicyItemUpdateToNextHostCountUpdateMs =
Date.now() - policyItemUpdatedAtMs.getTime() + nextHostCountUpdateMs;
let additionalUpdateTimeMs = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const ManageQueriesPage = ({
filteredQueriesPath,
isPremiumTier,
isSandboxMode,
isGlobalObserver,
config,
} = useContext(AppContext);
const { setLastEditedQueryBody, setSelectedQueryTargetsByType } = useContext(
Expand Down
Loading

0 comments on commit 82887fc

Please sign in to comment.