Skip to content

refactor(site): expose time values in render functions as centralized, pure state #17587

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
chore: add provider to base Storybook meta
  • Loading branch information
Parkreiner committed Apr 30, 2025
commit ebe8821fa7103b6d5610f937aa2ee5400107a384
2 changes: 1 addition & 1 deletion site/src/hooks/useTimeSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ export class TimeSync implements TimeSyncApi {
readonly #createNewDatetime: (prev: Date) => Date;
readonly #setInterval: SetInterval;
readonly #clearInterval: ClearInterval;
readonly #selectionCache: Map<string, unknown>;

#latestDateSnapshot: Date;
#subscriptions: SubscriptionEntry[];
#selectionCache: Map<string, unknown>;
#latestIntervalId: number | undefined;

constructor(options: Partial<TimeSyncInitOptions>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
withDashboardProvider,
withGlobalSnackbar,
withOrganizationSettingsProvider,
withTimeSyncProvider,
} from "testHelpers/storybook";
import type { NotificationsPage } from "./NotificationsPage";

Expand Down Expand Up @@ -214,5 +215,6 @@ export const baseMeta = {
withAuthProvider,
withDashboardProvider,
withOrganizationSettingsProvider,
withTimeSyncProvider,
],
} satisfies Meta<typeof NotificationsPage>;
17 changes: 16 additions & 1 deletion site/src/testHelpers/storybook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { hasFirstUserKey, meKey } from "api/queries/users";
import type { Entitlements } from "api/typesGenerated";
import { GlobalSnackbar } from "components/GlobalSnackbar/GlobalSnackbar";
import { AuthProvider } from "contexts/auth/AuthProvider";
import { TimeSyncProvider } from "hooks/useTimeSync";
import { DashboardContext } from "modules/dashboard/DashboardProvider";
import { DeploymentConfigContext } from "modules/management/DeploymentConfigProvider";
import { OrganizationSettingsContext } from "modules/management/OrganizationSettingsLayout";
import { permissionChecks } from "modules/permissions";
import type { FC } from "react";
import type { FC, ReactElement } from "react";
import { useQueryClient } from "react-query";
import {
MockAppearanceConfig,
Expand Down Expand Up @@ -156,6 +157,20 @@ export const withGlobalSnackbar = (Story: FC) => (
</>
);

const storyDate = new Date("March 15, 2022");
export const withTimeSyncProvider = (Story: FC): ReactElement => {
return (
<TimeSyncProvider
options={{
initialDatetime: storyDate,
resyncOnNewSubscription: false,
}}
>
<Story />
</TimeSyncProvider>
);
};

export const withOrganizationSettingsProvider = (Story: FC) => {
return (
<OrganizationSettingsContext.Provider
Expand Down
Loading