Skip to content

Commit

Permalink
fix type errors and prune whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
briangregoryholmes committed Oct 20, 2024
1 parent b8f3633 commit d11dbdf
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 212 deletions.
96 changes: 1 addition & 95 deletions scripts/tsc-with-whitelist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,125 +9,40 @@ web-admin/src/features/dashboards/listing/selectors.ts: error TS2345
web-admin/src/features/dashboards/listing/selectors.ts: error TS2769
web-admin/src/features/errors/error-utils.ts: error TS18048
web-admin/src/features/errors/error-utils.ts: error TS2322
web-admin/src/features/projects/selectors.ts: error TS18048
web-admin/src/features/dashboards/query-mappers/mapQueryToDashboard.ts: error TS2322
web-admin/src/features/dashboards/query-mappers/getDashboardFromAggregationRequest.ts: error TS2322
web-admin/src/features/scheduled-reports/selectors.ts: error TS18048
web-admin/src/features/scheduled-reports/selectors.ts: error TS2345
web-admin/src/features/view-as-user/clearViewedAsUser.ts: error TS18047
web-admin/src/features/view-as-user/clearViewedAsUser.ts: error TS2322
web-admin/src/features/view-as-user/setViewedAsUser.ts: error TS2322
web-admin/src/features/projects/github/GithubData.ts: error TS2769
web-admin/src/routes/[organization]/[project]/[dashboard]/+page.ts: error TS2307
web-admin/src/routes/[organization]/[project]/-/dashboards/+page.ts: error TS2307
web-common/src/components/button-group/ButtonGroup.spec.ts: error TS2345
web-common/src/components/data-graphic/actions/mouse-position-to-domain-action-factory.ts: error TS2322
web-common/src/components/data-graphic/actions/outline.ts: error TS18047
web-common/src/components/data-graphic/actions/outline.ts: error TS2345
web-common/src/components/data-graphic/marks/segment.ts: error TS2345
web-common/src/components/data-graphic/utils.ts: error TS2362
web-common/src/components/data-graphic/utils.ts: error TS2363
web-common/src/components/date-picker/datetime.ts: error TS18047
web-common/src/components/date-picker/datetime.ts: error TS2322
web-common/src/components/date-picker/datetime.ts: error TS2339
web-common/src/components/date-picker/datetime.ts: error TS2345
web-common/src/components/date-picker/datetime.ts: error TS2538
web-common/src/components/date-picker/util.ts: error TS18047
web-common/src/components/editor/indent-guide/index.ts: error TS2345
web-common/src/components/editor/line-status/line-number-gutter.ts: error TS2322
web-common/src/components/editor/line-status/line-number-gutter.ts: error TS2339
web-common/src/components/editor/line-status/line-status-gutter.ts: error TS2339
web-common/src/components/editor/line-status/state.ts: error TS2322
web-common/src/components/notifications/notificationStore.ts: error TS2322
web-common/src/features/dashboards/dashboard-utils.ts: error TS18048
web-common/src/features/dashboards/dashboard-utils.ts: error TS2322
web-common/src/features/dashboards/granular-access-policies/resetSelectedMockUserAfterNavigate.ts: error TS18047
web-common/src/features/dashboards/granular-access-policies/updateDevJWT.ts: error TS2322
web-common/src/features/dashboards/granular-access-policies/useDashboardPolicyCheck.ts: error TS2345
web-common/src/features/dashboards/granular-access-policies/useMockUsers.ts: error TS2345
web-common/src/features/dashboards/pivot/util.ts: error TS18047
web-common/src/features/dashboards/pivot/util.ts: error TS2322
web-common/src/features/dashboards/proto-state/dashboard-url-state.spec.ts: error TS2345
web-common/src/features/dashboards/proto-state/dashboard-url-state.ts: error TS2345
web-common/src/features/dashboards/proto-state/toProto.ts: error TS2322
web-common/src/features/dashboards/selectors.ts: error TS18048
web-common/src/features/dashboards/selectors.ts: error TS2322
web-common/src/features/dashboards/selectors.ts: error TS2345
web-common/src/features/dashboards/selectors/index.ts: error TS2345
web-common/src/features/dashboards/state-managers/selectors/dashboard-queries.ts: error TS2322
web-common/src/features/dashboards/state-managers/state-managers.ts: error TS2345
web-common/src/features/dashboards/stores/dashboard-store-defaults.ts: error TS18048
web-common/src/features/dashboards/stores/dashboard-store-defaults.ts: error TS2322
web-common/src/features/dashboards/stores/dashboard-store-defaults.ts: error TS2345
web-common/src/features/dashboards/stores/dashboard-store-defaults.ts: error TS2538
web-common/src/features/dashboards/stores/dashboard-store-defaults.ts: error TS2769
web-common/src/features/dashboards/stores/dashboard-stores.spec.ts: error TS2345
web-common/src/features/dashboards/stores/dashboard-stores.ts: error TS18048
web-common/src/features/dashboards/stores/dashboard-stores.ts: error TS2322
web-common/src/features/dashboards/stores/dashboard-stores.ts: error TS2345
web-common/src/features/dashboards/time-controls/time-control-store.spec.ts: error TS18048
web-common/src/features/dashboards/time-controls/time-control-store.spec.ts: error TS2322
web-common/src/features/dashboards/time-controls/time-control-store.spec.ts: error TS2345
web-common/src/features/dashboards/time-controls/time-range-store.ts: error TS18048
web-common/src/features/dashboards/time-controls/time-range-utils.ts: error TS2322
web-common/src/features/dashboards/time-series/multiple-dimension-queries.ts: error TS18048
web-common/src/features/dashboards/time-series/multiple-dimension-queries.ts: error TS2345
web-common/src/features/dashboards/url-state/filters/expression.cjs: error TS5097
web-common/src/features/entity-management/file-artifacts-store.ts: error TS18048
web-common/src/features/entity-management/file-artifacts-store.ts: error TS2345
web-common/src/features/entity-management/file-artifacts-store.ts: error TS2532
web-common/src/features/entity-management/file-artifacts-store.ts: error TS2538
web-common/src/features/entity-management/resource-invalidations.ts: error TS18048
web-common/src/features/entity-management/resource-invalidations.ts: error TS2345
web-common/src/features/entity-management/resource-invalidations.ts: error TS2538
web-common/src/features/entity-management/resource-selectors.ts: error TS18048
web-common/src/features/entity-management/resource-selectors.ts: error TS2345
web-common/src/features/entity-management/resource-status-utils.ts: error TS2322
web-common/src/features/entity-management/resources-store.ts: error TS18048
web-common/src/features/entity-management/resources-store.ts: error TS2322
web-common/src/features/entity-management/resources-store.ts: error TS2345
web-common/src/features/entity-management/resources-store.ts: error TS2538
web-common/src/features/entity-management/watch-files-client.ts: error TS18048
web-common/src/features/entity-management/watch-files-client.ts: error TS2345
web-common/src/features/help/initPylonChat.ts: error TS2322
web-common/src/features/help/initPylonWidget.ts: error TS18047
web-common/src/features/dashboards/url-state/filters/expression.cjs: error TS1286
web-common/src/features/metrics-views/column-selectors.ts: error TS18048
web-common/src/features/metrics-views/errors.ts: error TS2322
web-common/src/features/metrics-views/errors.ts: error TS2345
web-common/src/features/metrics-views/metrics-internal-store.ts: error TS18048
web-common/src/features/metrics-views/metrics-internal-store.ts: error TS2345
web-common/src/features/metrics-views/editor/create-placeholder.ts: error TS2322
web-common/src/features/models/selectors.ts: error TS18048
web-common/src/features/models/selectors.ts: error TS2345
web-common/src/features/models/utils/embedded.ts: error TS18048
web-common/src/features/models/utils/get-table-references/index.ts: error TS18048
web-common/src/features/models/utils/get-table-references/index.ts: error TS2322
web-common/src/features/models/utils/get-table-references/index.ts: error TS2532
web-common/src/features/models/inspector/utils.ts: error TS18048
web-common/src/features/project/selectors.ts: error TS2345
web-common/src/features/project/shorthand-title/index.spec.ts: error TS2345
web-common/src/features/sources/createModel.ts: error TS2345
web-common/src/features/sources/group-uris.ts: error TS18048
web-common/src/features/sources/group-uris.ts: error TS2322
web-common/src/features/sources/modal/file-upload.ts: error TS2322
web-common/src/features/sources/modal/file-upload.ts: error TS2345
web-common/src/features/sources/selectors.ts: error TS18048
web-common/src/features/sources/selectors.ts: error TS2322
web-common/src/features/sources/selectors.ts: error TS2345
web-common/src/features/welcome/is-project-initialized.ts: error TS18048
web-common/src/layout/navigation/navigation-utils.ts: error TS2345
web-common/src/lib/actions/truncate-middle-text.ts: error TS18047
web-common/src/lib/actions/truncate-middle-text.ts: error TS2345
web-common/src/lib/formatters.ts: error TS18046
web-common/src/lib/number-formatting/utils/format-with-order-of-magnitude.spec.ts: error TS2345
web-common/src/lib/store-utils/local-storage.ts: error TS2345
web-common/src/lib/time/comparisons/index.ts: error TS2322
web-common/src/lib/time/grains/index.spec.ts: error TS2345
web-common/src/lib/time/ranges/index.ts: error TS18048
web-common/src/lib/time/ranges/index.ts: error TS2345
web-common/src/lib/url-utils.ts: error TS2345
web-common/src/metrics/service/ServiceBase.ts: error TS18046
web-common/src/metrics/service/ServiceBase.ts: error TS18048
web-common/src/runtime-client/fetchWrapper.ts: error TS2345
web-common/src/runtime-client/http-request-queue/Heap.ts: error TS2322
web-common/src/runtime-client/http-request-queue/Heap.ts: error TS2345
Expand All @@ -137,15 +52,6 @@ web-common/src/runtime-client/http-request-queue/HttpRequestQueue.ts: error TS23
web-common/src/runtime-client/http-request-queue/HttpRequestQueue.ts: error TS2532
web-common/src/runtime-client/http-request-queue/HttpRequestQueueTypes.ts: error TS18048
web-common/src/runtime-client/http-request-queue/HttpRequestQueueTypes.ts: error TS2322
web-common/src/runtime-client/invalidation.ts: error TS18048
web-common/src/runtime-client/invalidation.ts: error TS2345
web-common/src/runtime-client/watch-request-client.ts: error TS2322
web-common/vite.config.ts: error TS2322
web-admin/vite.config.ts: error TS2322
web-auth/vite.config.ts: error TS2322
web-local/vite.config.ts: error TS2345
web-common/src/features/dashboards/url-state/filters/expression.cjs: error TS1286
web-local/src/routes//dashboard/[name]/+page.ts: error TS2307
"

# Run TypeScript compiler and find all distinct error per file
Expand Down
6 changes: 3 additions & 3 deletions web-admin/src/features/projects/github/GithubData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class GithubData {
>
>;

private userPromptWindow: Window | null;
private windowCheckTimer: ReturnType<typeof setInterval> | null;
private userPromptWindow: Window | null = null;
private windowCheckTimer: ReturnType<typeof setInterval> | null = null;

public readonly status = derived(
[this.userStatus, this.userRepos],
Expand Down Expand Up @@ -112,7 +112,7 @@ export class GithubData {
// periodically check if the new window was closed
this.windowCheckTimer = setInterval(() => {
if (!this.userPromptWindow?.closed) return;
clearInterval(this.windowCheckTimer);
if (this.windowCheckTimer) clearInterval(this.windowCheckTimer);
this.windowCheckTimer = null;
this.userPromptWindow = null;
void this.refetch();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { redirect } from "@sveltejs/kit";
import type { PageLoad } from "./$types";

export const load: PageLoad = ({ params }) => {
export const load = ({ params }) => {
throw redirect(307, `/${params.organization}/${params.project}`);
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { redirect } from "@sveltejs/kit";
import type { PageLoad } from "./$types";

/**
* Redirect `/[organization]/[project]/[dashboard]` to `/[organization]/[project]/explore/[dashboard]`.
* Maintains backwards compatibility with legacy URLs.
*/
export const load: PageLoad = ({ params }) => {
export const load = ({ params }) => {
throw redirect(
307,
`/${params.organization}/${params.project}/explore/${params.dashboard}`,
Expand Down
60 changes: 38 additions & 22 deletions web-common/src/components/button-group/ButtonGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import ButtonGroupTestingWrapper from "./ButtonGroupTestingWrapper.svelte";

describe("ButtonGroup", () => {
it("ButtonGroupTestingWrapper -- buttons in test wrapper exist", async () => {
it("ButtonGroupTestingWrapper -- buttons in test wrapper exist", () => {
const { unmount } = render(ButtonGroupTestingWrapper, {
values: [1, 2, 3],
selected: [1, 2, 3],
disabled: [1, 2, 3],
});

[1, 2, 3].forEach(async (i) => {
const buttons = [1, 2, 3];

for (const i of buttons) {
const button = screen.getByRole("button", { name: `button-${i}` });
expect(button).toBeInstanceOf(HTMLButtonElement);
});
}

unmount();
});
Expand All @@ -28,11 +30,13 @@ describe("ButtonGroup", () => {
});
component.$on("subbutton-click", onClick);

[1, 2, 3].forEach(async (i) => {
const buttons = [1, 2, 3];

for (const i of buttons) {
const button = screen.getByRole("button", { name: `button-${i}` });
await fireEvent.click(button);
expect(onClick).toBeCalledWith(expect.objectContaining({ detail: i }));
});
}

expect(onClick).toBeCalledTimes(3);
unmount();
Expand All @@ -48,10 +52,12 @@ describe("ButtonGroup", () => {
});
component.$on("subbutton-click", onClick);

[1, 2, 3].forEach(async (i) => {
const buttons = [1, 2, 3];

for (const i of buttons) {
const button = screen.getByRole("button", { name: `button-${i}` });
await fireEvent.click(button);
});
}

expect(onClick).toBeCalledTimes(0);
unmount();
Expand All @@ -64,26 +70,29 @@ describe("ButtonGroup", () => {
disabled: [3],
});

[
const buttons = [
[1, "selected tt"],
[2, "unselected tt"],
[3, "disabled tt"],
].forEach(async ([i, tt]) => {
];

for (const [i, tt] of buttons) {
const button = screen.getByRole("button", { name: `button-${i}` });
if (!button?.parentElement) return;
await fireEvent.mouseEnter(button.parentElement);
const toolTip = await waitFor(() => screen.getByText(tt));
expect(toolTip).toBeTruthy();
await fireEvent.mouseLeave(button.parentElement);
});
}

unmount();
});
});

describe("ButtonGroup - adding buttons", () => {
let component;
let unmount;
let onClick;
let component: ButtonGroupTestingWrapper;
let unmount: () => void;
let onClick: (event: CustomEvent<unknown>) => void;

beforeEach(() => {
const { component: component_before, unmount: unmount_before } = render(
Expand Down Expand Up @@ -135,6 +144,8 @@ describe("ButtonGroup - adding buttons", () => {
const errorObject = console.error;
console.error = vi.fn();

if (!button?.parentElement) return;

await fireEvent.mouseEnter(button.parentElement);
let toolTip = await screen.findByText("unselected tt");
expect(toolTip).toBeTruthy();
Expand All @@ -158,9 +169,9 @@ describe("ButtonGroup - adding buttons", () => {
});

describe("ButtonGroup - removing buttons", () => {
let component;
let unmount;
let onClick;
let component: ButtonGroupTestingWrapper;
let unmount: () => void;
let onClick: (event: CustomEvent<unknown>) => void;

beforeEach(() => {
const { component: component_before, unmount: unmount_before } = render(
Expand All @@ -181,16 +192,16 @@ describe("ButtonGroup - removing buttons", () => {
unmount();
});

it("removed buttons not found", async () => {
await component.$set({ values: [1, 3, 4] });
const button2 = await screen.queryByRole("button", { name: `button-2` });
it("removed buttons not found", () => {
component.$set({ values: [1, 3, 4] });
const button2 = screen.queryByRole("button", { name: `button-2` });
expect(button2).toBeNull();

Check failure on line 198 in web-common/src/components/button-group/ButtonGroup.spec.ts

View workflow job for this annotation

GitHub Actions / build

src/components/button-group/ButtonGroup.spec.ts > ButtonGroup - removing buttons > removed buttons not found

AssertionError: expected <button …(2)></button> to be null ❯ src/components/button-group/ButtonGroup.spec.ts:198:21
const button5 = await screen.queryByRole("button", { name: `button-5` });
const button5 = screen.queryByRole("button", { name: `button-5` });
expect(button5).toBeNull();
});

it("after removal, remaining buttons dispatch correct actions", async () => {
await component.$set({ values: [1, 3, 4] });
component.$set({ values: [1, 3, 4] });

let button = screen.getByRole("button", { name: `button-1` });
await fireEvent.click(button);
Expand All @@ -208,26 +219,31 @@ describe("ButtonGroup - removing buttons", () => {
});

it("after removal, remaining buttons have correct tooltips", async () => {
await component.$set({ values: [1, 3, 4] });
component.$set({ values: [1, 3, 4] });

// mock console.error to avoid irrelevant errors about
// `scrollTo` not being implemented in jsdom
const errorObject = console.error;
console.error = vi.fn();

let button = await screen.findByRole("button", { name: `button-1` });

if (!button?.parentElement) return;

await fireEvent.mouseEnter(button.parentElement);
let toolTip = await screen.findByText("selected tt");
expect(toolTip).toBeTruthy();
await fireEvent.mouseLeave(button.parentElement);

button = await screen.findByRole("button", { name: `button-3` });
if (!button?.parentElement) return;
await fireEvent.mouseEnter(button.parentElement);
toolTip = await waitFor(() => screen.getByText("unselected tt"));
expect(toolTip).toBeTruthy();
await fireEvent.mouseLeave(button.parentElement);

button = await screen.findByRole("button", { name: `button-4` });
if (!button?.parentElement) return;
await fireEvent.mouseEnter(button.parentElement);
toolTip = await waitFor(() => screen.getByText("disabled tt"));
expect(toolTip).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import type { DimensionTableConfig } from "./DimensionTableConfig";

/** Returns an updated filter set for a given dimension on search */
export function updateFilterOnSearch(
filterForDimension: V1Expression | undefined,
filterForDimension: V1Expression,
searchText: string,
dimensionName: string,
): V1Expression | undefined {
Expand Down Expand Up @@ -86,10 +86,9 @@ export function getDimensionFilterWithSearch(
searchText: string,
dimensionName: string,
) {
let filterForDimension = getFiltersForOtherDimensions(filters, dimensionName);
if (filters && !filterForDimension) {
filterForDimension = createAndExpression([]); // create an empty query for consistency
}
const filterForDimension =
getFiltersForOtherDimensions(filters, dimensionName) ??
createAndExpression([]);

return updateFilterOnSearch(filterForDimension, searchText, dimensionName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export function useDashboardPolicyCheck(instanceId: string, filePath: string) {
{
query: {
select: (data) => {
const yamlObj = parse(data?.blob);
if (!data.blob) return false;
const yamlObj = parse(data.blob);
const securityPolicy = yamlObj?.security;
return !!securityPolicy;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function useMockUsers(instanceId: string) {
{
query: {
select: (data) => {
if (!data.blob) return [];
const yamlObj = parseDocument(data.blob, {
logLevel: "error",
})?.toJS();
Expand Down
Loading

0 comments on commit d11dbdf

Please sign in to comment.