Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Oct 28, 2024
1 parent 52df6b5 commit 5f6de87
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 66 deletions.
8 changes: 8 additions & 0 deletions scripts/tsc-with-whitelist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ web-admin/src/features/dashboards/query-mappers/mapQueryToDashboard.ts: error TS
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/billing/issues/getMessageForTrialPlan.ts: error TS18048
web-admin/src/features/billing/plans/selectors.ts: error TS18048
web-admin/src/routes/[organization]/-/settings/+layout.ts: error TS2307
web-admin/src/routes/[organization]/-/settings/billing/+page.ts: error TS2307
web-admin/src/routes/[organization]/-/settings/billing/payment/+page.ts: error TS2307
web-admin/src/routes/[organization]/-/settings/billing/upgrade/+page.ts: error TS2307
web-admin/src/routes/[organization]/-/upgrade-callback/+page.ts: error TS2307
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
Expand Down Expand Up @@ -52,6 +59,7 @@ 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/lib/time/config.ts: error TS2322
"

# Run TypeScript compiler and find all distinct error per file
Expand Down
8 changes: 5 additions & 3 deletions web-admin/src/features/billing/BillingCTAHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BillingIssueMessage } from "@rilldata/web-admin/features/billing/issues/useBillingIssueMessage";
import { fetchPaymentsPortalURL } from "@rilldata/web-admin/features/billing/plans/selectors";
import type { TeamPlanDialogTypes } from "@rilldata/web-admin/features/billing/plans/StartTeamPlanDialog.svelte";
import type { TeamPlanDialogTypes } from "@rilldata/web-admin/features/billing/plans/types";
import { wakeAllProjects } from "@rilldata/web-admin/features/organizations/hibernating/wakeAllProjects";
import { eventBus } from "@rilldata/web-common/lib/event-bus/event-bus";
import { writable } from "svelte/store";
Expand All @@ -19,7 +19,7 @@ export class BillingCTAHandler {
public static get(organization: string) {
let instance: BillingCTAHandler;
if (this.instances.has(organization)) {
instance = this.instances.get(organization);
instance = this.instances.get(organization)!;
instance.wakingProjects.set(false);
} else {
instance = new BillingCTAHandler(organization);
Expand All @@ -33,7 +33,9 @@ export class BillingCTAHandler {
switch (issueMessage.cta.type) {
case "upgrade":
this.showStartTeamPlanDialog.set(true);
this.startTeamPlanType.set(issueMessage.cta.teamPlanDialogType);
this.startTeamPlanType.set(
issueMessage.cta.teamPlanDialogType ?? "base",
);
this.teamPlanEndDate.set(issueMessage.cta.teamPlanEndDate ?? "");
break;

Expand Down
16 changes: 10 additions & 6 deletions web-admin/src/features/billing/invalidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export async function waitForUpdatedBillingIssues(
queryKey: getAdminServiceListOrganizationBillingIssuesQueryKey(org),
queryFn: () => adminServiceListOrganizationBillingIssues(org),
});
const currentBillingIssues = new Set(issuesResp.issues.map((i) => i.type));
const currentBillingIssues = new Set(
issuesResp.issues?.map((i) => i.type) ?? [],
);
if (expectedIssueTypes.every((t) => currentBillingIssues.has(t))) {
// already has expected issues
return;
}

const currentlyHasBlockerIssues = hasBlockerIssues(issuesResp.issues);
const currentlyHasBlockerIssues = hasBlockerIssues(issuesResp.issues ?? []);

while (tries < IssuesUpdateMaxTries) {
await queryClient.refetchQueries(
Expand All @@ -56,14 +58,16 @@ export async function waitForUpdatedBillingIssues(
queryFn: () => adminServiceListOrganizationBillingIssues(org),
});
const issuesChangedFromPreviousFetch =
newIssuesResp.issues &&
// difference in sizes means there was a change
newIssuesResp.issues.length !== currentBillingIssues.size ||
// some issue had a different type
newIssuesResp.issues.some((i) => !currentBillingIssues.has(i.type));
(newIssuesResp.issues.length !== currentBillingIssues.size ||
// some issue had a different type
newIssuesResp.issues.some((i) => !currentBillingIssues.has(i.type)));
// NOTE: if issues already changed from previous fetch we don't need to check against expectedIssueTypes
if (issuesChangedFromPreviousFetch) {
if (
currentlyHasBlockerIssues !== hasBlockerIssues(newIssuesResp.issues)
currentlyHasBlockerIssues !==
hasBlockerIssues(newIssuesResp.issues ?? [])
) {
// when blocker issues are either added or removed projects hibernation status changes.
// so re-retch projects list to get updated hibernation status.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export function getMessageForCancelledIssue(cancelledSubIssue: V1BillingIssue) {
let accessTimeout = "";
let ended = false;

if (cancelledSubIssue.metadata.subscriptionCancelled?.endDate) {
if (cancelledSubIssue.metadata?.subscriptionCancelled?.endDate) {
const endDate = DateTime.fromJSDate(
new Date(cancelledSubIssue.metadata.subscriptionCancelled?.endDate),
new Date(cancelledSubIssue.metadata.subscriptionCancelled.endDate),
);
if (endDate.isValid && endDate.toMillis() > Date.now()) {
accessTimeout = `but you still have access until ${endDate.toLocaleString(DateTime.DATE_MED)}`;
Expand All @@ -42,7 +42,7 @@ export function getMessageForCancelledIssue(cancelledSubIssue: V1BillingIssue) {
type: "upgrade",
teamPlanDialogType: "renew",
teamPlanEndDate:
cancelledSubIssue.metadata.subscriptionCancelled?.endDate,
cancelledSubIssue.metadata?.subscriptionCancelled?.endDate,
},
};
}
Expand All @@ -51,7 +51,7 @@ export function cancelledSubscriptionHasEnded(
cancelledSubIssue: V1BillingIssue,
) {
const endDate = new Date(
cancelledSubIssue.metadata?.subscriptionCancelled?.endDate,
cancelledSubIssue.metadata?.subscriptionCancelled?.endDate ?? "",
);
const endTime = endDate.getTime();
return Number.isNaN(endTime) || endTime < Date.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ export const PaymentBillingIssueTypes: Partial<
export function getPaymentIssues(issues: V1BillingIssue[]) {
return issues?.filter(
(i) =>
i.type in PaymentBillingIssueTypes ||
i.type === V1BillingIssueType.BILLING_ISSUE_TYPE_PAYMENT_FAILED,
i.type &&
(i.type in PaymentBillingIssueTypes ||
i.type === V1BillingIssueType.BILLING_ISSUE_TYPE_PAYMENT_FAILED),
);
}

export function getPaymentIssueErrorText(paymentIssues: V1BillingIssue[]) {
const issueTexts = paymentIssues
.map((i) => PaymentBillingIssueTypes[i.type]?.short)
.filter(Boolean);
.map((i) => PaymentBillingIssueTypes[i.type ?? ""]?.short)
.filter(Boolean) as string[];

return `No valid ${issueTexts.length ? issueTexts.join(" or ") : "payment method"} on file.`;
}
Expand All @@ -54,8 +55,8 @@ export function getMessageForPaymentIssues(
const overdue = invoiceIsOverdue(oldestInvoice);

const issueTexts = issues
.map((i) => PaymentBillingIssueTypes[i.type]?.short)
.filter(Boolean);
.map((i) => PaymentBillingIssueTypes[i.type ?? ""]?.short)
.filter(Boolean) as string[];

const message: BillingIssueMessage = {
type: overdue ? "error" : "warning",
Expand Down Expand Up @@ -92,6 +93,9 @@ export function getMessageForPaymentIssues(
}

function findOldestInvoice(paymentFailed: V1BillingIssue) {
if (!paymentFailed.metadata?.paymentFailed?.invoices?.length)
return undefined;

let oldest = paymentFailed.metadata.paymentFailed.invoices[0];
for (
let i = 1;
Expand All @@ -100,7 +104,8 @@ function findOldestInvoice(paymentFailed: V1BillingIssue) {
) {
const invoice = paymentFailed.metadata.paymentFailed.invoices[i];
if (
new Date(invoice.dueDate).getTime() > new Date(oldest.dueDate).getTime()
new Date(invoice.dueDate ?? "").getTime() >
new Date(oldest.dueDate ?? "").getTime()
) {
oldest = invoice;
}
Expand All @@ -110,13 +115,13 @@ function findOldestInvoice(paymentFailed: V1BillingIssue) {
}

function invoiceIsDue(invoice: V1BillingIssueMetadataPaymentFailedMeta) {
const dueDate = new Date(invoice.dueDate);
const dueDate = new Date(invoice.dueDate ?? "");
const dueDateTime = dueDate.getTime();
return Number.isNaN(dueDateTime) || dueDateTime < Date.now();
}

function invoiceIsOverdue(invoice: V1BillingIssueMetadataPaymentFailedMeta) {
const gracePeriod = new Date(invoice.gracePeriodEndDate);
const gracePeriod = new Date(invoice.gracePeriodEndDate ?? "");
const gracePeriodTime = gracePeriod.getTime();
return Number.isNaN(gracePeriodTime) || gracePeriodTime < Date.now();
}
13 changes: 8 additions & 5 deletions web-admin/src/features/billing/issues/getMessageForTrialPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {
type V1BillingIssue,
V1BillingIssueType,
} from "@rilldata/web-admin/client";
import type { BillingIssueMessage } from "@rilldata/web-admin/features/billing/issues/useBillingIssueMessage";
import type {
BillingIssueMessage,
BillingIssueMessageCTA,

Check failure on line 7 in web-admin/src/features/billing/issues/getMessageForTrialPlan.ts

View workflow job for this annotation

GitHub Actions / build

'BillingIssueMessageCTA' is defined but never used
} from "@rilldata/web-admin/features/billing/issues/useBillingIssueMessage";
import { shiftToLargest } from "@rilldata/web-common/lib/time/ranges/iso-ranges";
import { DateTime, type Duration } from "luxon";

Expand All @@ -20,8 +23,8 @@ export function getMessageForTrialPlan(
trialIssue: V1BillingIssue,
): BillingIssueMessage {
const endDateStr =
trialIssue.metadata.onTrial?.endDate ??
trialIssue.metadata.trialEnded?.gracePeriodEndDate ??
trialIssue.metadata?.onTrial?.endDate ??
trialIssue.metadata?.trialEnded?.gracePeriodEndDate ??
"";

const message: BillingIssueMessage = {
Expand Down Expand Up @@ -53,7 +56,7 @@ export function getMessageForTrialPlan(
message.type = daysDiff.days < WarningPeriodInDays ? "warning" : "info";
} else {
const gracePeriodDate = DateTime.fromJSDate(
new Date(trialIssue.metadata?.trialEnded?.gracePeriodEndDate),
new Date(trialIssue.metadata?.trialEnded?.gracePeriodEndDate ?? ""),
);
const gracePeriodDiff = gracePeriodDate.isValid
? gracePeriodDate.diff(today)
Expand All @@ -80,7 +83,7 @@ export function getTrialMessageForDays(diff: Duration) {

export function trialHasPastGracePeriod(trialEndedIssue: V1BillingIssue) {
const gracePeriodDate = new Date(
trialEndedIssue.metadata?.trialEnded?.gracePeriodEndDate,
trialEndedIssue.metadata?.trialEnded?.gracePeriodEndDate ?? "",
);
const gracePeriodTime = gracePeriodDate.getTime();
return Number.isNaN(gracePeriodTime) || gracePeriodTime < Date.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createAdminServiceGetBillingSubscription } from "@rilldata/web-admin/cl
import { getMessageForPaymentIssues } from "@rilldata/web-admin/features/billing/issues/getMessageForPaymentIssues";
import { getMessageForCancelledIssue } from "@rilldata/web-admin/features/billing/issues/getMessageForCancelledIssue";
import { getMessageForTrialPlan } from "@rilldata/web-admin/features/billing/issues/getMessageForTrialPlan";
import type { TeamPlanDialogTypes } from "@rilldata/web-admin/features/billing/plans/StartTeamPlanDialog.svelte";
import type { TeamPlanDialogTypes } from "@rilldata/web-admin/features/billing/plans/types";
import { isTeamPlan } from "@rilldata/web-admin/features/billing/plans/utils";
import { useCategorisedOrganizationBillingIssues } from "@rilldata/web-admin/features/billing/selectors";
import { areAllProjectsHibernating } from "@rilldata/web-admin/features/organizations/selectors";
Expand Down Expand Up @@ -59,7 +59,7 @@ export function useBillingIssueMessage(
};
}

if (categorisedIssuesResp.data.cancelled) {
if (categorisedIssuesResp.data?.cancelled) {
return {
isFetching: false,
error: undefined,
Expand All @@ -69,7 +69,7 @@ export function useBillingIssueMessage(
};
}

if (categorisedIssuesResp.data.trial) {
if (categorisedIssuesResp.data?.trial) {
return {
isFetching: false,
error: undefined,
Expand All @@ -78,7 +78,7 @@ export function useBillingIssueMessage(
}

if (
categorisedIssuesResp.data.payment.length &&
categorisedIssuesResp.data?.payment.length &&
subscriptionResp.data?.subscription
) {
return {
Expand Down
19 changes: 1 addition & 18 deletions web-admin/src/features/billing/plans/StartTeamPlanDialog.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
<script lang="ts" context="module">
/**
* 1. base - When user chooses to upgrade from a trial plan.
* 2. size - When user hits the size limit and wants to upgrade.
* 3. org - When user hits the organization limit and wants to upgrade.
* 4. proj - When user hits the project limit and wants to upgrade.
* 5. renew - After user cancels a subscription and wants to renew.
* 6. trial-expired - After a trial has expired with grace period also ended.
*/
export type TeamPlanDialogTypes =
| "base"
| "size"
| "org"
| "proj"
| "renew"
| "trial-expired";
</script>

<script lang="ts">
import { page } from "$app/stores";
import { mergedQueryStatus } from "@rilldata/web-admin/client/utils";
Expand All @@ -25,6 +7,7 @@
fetchTeamPlan,
getBillingUpgradeUrl,
} from "@rilldata/web-admin/features/billing/plans/selectors";
import type { TeamPlanDialogTypes } from "@rilldata/web-admin/features/billing/plans/types";
import {
getSubscriptionResumedText,
showWelcomeToRillDialog,
Expand Down
5 changes: 2 additions & 3 deletions web-admin/src/features/billing/plans/TrialPlan.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import ContactUs from "@rilldata/web-admin/features/billing/ContactUs.svelte";
import { getTrialMessageForDays } from "@rilldata/web-admin/features/billing/issues/getMessageForTrialPlan";
import PlanQuotas from "@rilldata/web-admin/features/billing/plans/PlanQuotas.svelte";
import StartTeamPlanDialog, {
type TeamPlanDialogTypes,
} from "@rilldata/web-admin/features/billing/plans/StartTeamPlanDialog.svelte";
import StartTeamPlanDialog from "@rilldata/web-admin/features/billing/plans/StartTeamPlanDialog.svelte";
import type { TeamPlanDialogTypes } from "@rilldata/web-admin/features/billing/plans/types";
import PricingDetails from "@rilldata/web-admin/features/billing/PricingDetails.svelte";
import { useCategorisedOrganizationBillingIssues } from "@rilldata/web-admin/features/billing/selectors";
import SettingsContainer from "@rilldata/web-admin/features/organizations/settings/SettingsContainer.svelte";
Expand Down
4 changes: 2 additions & 2 deletions web-admin/src/features/billing/plans/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function fetchTeamPlan() {
queryFn: () => adminServiceListPublicBillingPlans(),
});

return plansResp.plans.find(isTeamPlan);
return plansResp.plans?.find(isTeamPlan);
}

/**
Expand All @@ -40,7 +40,7 @@ export async function fetchPaymentsPortalURL(
staleTime: 0,
});

return portalUrlResp.url;
return portalUrlResp.url ?? "";
}

export function getBillingUpgradeUrl(page: Page, organization: string) {
Expand Down
15 changes: 15 additions & 0 deletions web-admin/src/features/billing/plans/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* 1. base - When user chooses to upgrade from a trial plan.
* 2. size - When user hits the size limit and wants to upgrade.
* 3. org - When user hits the organization limit and wants to upgrade.
* 4. proj - When user hits the project limit and wants to upgrade.
* 5. renew - After user cancels a subscription and wants to renew.
* 6. trial-expired - After a trial has expired with grace period also ended.
*/
export type TeamPlanDialogTypes =
| "base"
| "size"
| "org"
| "proj"
| "renew"
| "trial-expired";
2 changes: 1 addition & 1 deletion web-admin/src/features/navigation/nav-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Page } from "@sveltejs/kit";
export function isOrganizationPage(page: Page): boolean {
return (
page.route.id === "/[organization]" ||
page.route.id.startsWith("/[organization]/-/settings")
!!page.route?.id?.startsWith("/[organization]/-/settings")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ async function redeployProject(
) {
const resp = await get(projectDeployer).mutateAsync({
organization,
project: project.name,
project: project.name ?? "",
});
void queryClient.refetchQueries(
getAdminServiceGetProjectQueryKey(organization, project.name),
getAdminServiceGetProjectQueryKey(organization, project.name ?? ""),
{
// avoid invalidating createAdminServiceGetProjectWithBearerToken
exact: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
const column = String(e.currentTarget.dataset.column);
const index = Number(e.currentTarget.dataset.index);
const value =
description ?? isHeader
(description ?? isHeader)
? column
: (rows[index]?.[column] as string | number | null);
const type = columns.find((c) => c.name === column)?.type ?? "string";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
on:focus={focus}
on:blur={blur}
on:click={modified({ shift: onShiftClick, click: onClick })}
style:transform="translate{position === "left" ? "Y" : "X"}({header.start}px)"
style:transform="translate{position === 'left' ? 'Y' : 'X'}({header.start}px)"
style:width="{header.size}px"
style:height="{position === "left"
style:height="{position === 'left'
? config.rowHeight
: config.columnHeaderHeight}px"
class="block {positionClasses}
Expand Down
2 changes: 1 addition & 1 deletion web-common/src/features/dashboards/stores/filter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export function getValueIndexInExpression(expr: V1Expression, value: string) {
}

export function getValuesInExpression(expr?: V1Expression): any[] {
return expr ? expr.cond?.exprs?.slice(1).map((e) => e.val) ?? [] : [];
return expr ? (expr.cond?.exprs?.slice(1).map((e) => e.val) ?? []) : [];
}

export const matchExpressionByName = (e: V1Expression, name: string) => {
Expand Down
Loading

0 comments on commit 5f6de87

Please sign in to comment.