Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(site): add defensive access to entitlement features#21381

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 9 commits intomainfromfix/defensive-feature-access
Dec 23, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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 numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
import { MockLicenseResponse } from "testHelpers/entities";
import type { Meta, StoryObj } from "@storybook/react-vite";
import LicensesSettingsPage from "./LicensesSettingsPage";

const meta: Meta<typeof LicensesSettingsPage> = {
title: "pages/DeploymentSettingsPage/LicensesSettingsPage",
component: LicensesSettingsPage,
parameters: {
queries: [
{ key: ["licenses"], data: MockLicenseResponse },
{ key: ["insights", "userStatusCounts"], data: { active: [] } },
],
},
};

export default meta;
type Story = StoryObj<typeof LicensesSettingsPage>;

export const WithoutUserLimitFeature: Story = {
parameters: {
queries: [
{ key: ["entitlements"], data: { features: {} } },
{ key: ["licenses"], data: MockLicenseResponse },
{ key: ["insights", "userStatusCounts"], data: { active: [] } },
],
},
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,8 +77,8 @@ const LicensesSettingsPage: FC = () => {
showConfetti={confettiOn}
isLoading={isLoading}
isRefreshing={refreshEntitlementsMutation.isPending}
userLimitActual={entitlementsQuery.data?.features.user_limit.actual}
userLimitLimit={entitlementsQuery.data?.features.user_limit.limit}
userLimitActual={entitlementsQuery.data?.features.user_limit?.actual}
userLimitLimit={entitlementsQuery.data?.features.user_limit?.limit}
Comment on lines +80 to +81
Copy link
Contributor

@EhabYEhabYDec 23, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

features: Record<FeatureName, Feature>;, technically any index access should use the?. notation (no guarantees on the existence). There's even atsconfig.json config for this:https://www.typescriptlang.org/tsconfig/#noUncheckedIndexedAccess

This issue is that if this is enabled it might require a humongous amount of changes

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

TIL!

I understand that it is something we definitely don't want to enable without wider refactor 😅 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

So I do not have a workingsite rn but if you add the option:

"compilerOptions": {"noUncheckedIndexedAccess":true  }

How many failures are there when compiling? This is def beyond the scope of this PR though 😓

Copy link
MemberAuthor

@mtojekmtojekDec 23, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I involved Claude & mux in this exercise. Here are the results:

Total: 257 errors, 89 files

TS253286Object is possibly 'undefined'
TS234562Argument of type 'X | undefined' is not assignable to...
TS232256Type 'X | undefined' is not assignable to type...
TS1804846'X' is possibly 'undefined'
Others7(TS2538, TS2339, TS2769, TS2488)

I asked to create a draft for better picture (clauding now), but we would need more eyes on this anyway 😅

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Here is the first draft:#21383

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hahahaha I love how the way it solves this is by asserting (and thus breaking at run time anyway). 145 lines is not bad though, I'm guessing in some cases we can assert and in others we just "handle" the undefined

licenses={licenses}
isRemovingLicense={isRemovingLicense}
removeLicense={(licenseId: number) => removeLicenseApi(licenseId)}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,14 +2,12 @@ import { useTheme } from "@emotion/react";
import LinearProgress from "@mui/material/LinearProgress";
import Link from "@mui/material/Link";
import { getErrorDetail, getErrorMessage } from "api/errors";
import { entitlements } from "api/queries/entitlements";
import {
insightsTemplate,
insightsUserActivity,
insightsUserLatency,
} from "api/queries/insights";
import type {
Entitlements,
Template,
TemplateAppUsage,
TemplateInsightsResponse,
Expand DownExpand Up@@ -39,7 +37,6 @@ import {
TooltipContent,
TooltipTrigger,
} from "components/Tooltip/Tooltip";
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
import {
CircleCheck as CircleCheckIcon,
CircleXIcon,
Expand DownExpand Up@@ -100,11 +97,6 @@ export default function TemplateInsightsPage() {
const userLatency = useQuery(insightsUserLatency(commonFilters));
const userActivity = useQuery(insightsUserActivity(commonFilters));

const { metadata } = useEmbeddedMetadata();
const { data: entitlementsQuery } = useQuery(
entitlements(metadata.entitlements),
);

return (
<>
<title>{getTemplatePageTitle("Insights", template)}</title>
Expand All@@ -123,7 +115,6 @@ export default function TemplateInsightsPage() {
userLatency={userLatency}
userActivity={userActivity}
interval={interval}
entitlements={entitlementsQuery}
/>
</>
);
Expand DownExpand Up@@ -215,7 +206,6 @@ interface TemplateInsightsPageViewProps {
data: UserActivityInsightsResponse | undefined;
error: unknown;
};
entitlements: Entitlements | undefined;
controls: ReactNode;
interval: InsightsInterval;
}
Expand All@@ -224,7 +214,6 @@ export const TemplateInsightsPageView: FC<TemplateInsightsPageViewProps> = ({
templateInsights,
userLatency,
userActivity,
entitlements,
controls,
interval,
}) => {
Expand All@@ -251,11 +240,6 @@ export const TemplateInsightsPageView: FC<TemplateInsightsPageViewProps> = ({
<ActiveUsersPanel
css={{ gridColumn: "span 2" }}
interval={interval}
userLimit={
entitlements?.features.user_limit.enabled
? entitlements?.features.user_limit.limit
: undefined
}
Comment on lines -254 to -258
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Was this just passed tonothing?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Passed andunused 👍

data={templateInsights.data?.interval_reports}
error={templateInsights.error}
/>
Expand DownExpand Up@@ -283,14 +267,12 @@ interface ActiveUsersPanelProps extends PanelProps {
data: TemplateInsightsResponse["interval_reports"] | undefined;
error: unknown;
interval: InsightsInterval;
userLimit: number | undefined;
}

const ActiveUsersPanel: FC<ActiveUsersPanelProps> = ({
data,
error,
interval,
userLimit,
...panelProps
}) => {
return (
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp