chore: remove deprecated code, Meta & MetaProvider (#19407)

* chore: remove deprecated code Meta, MetaProvider

* fix type checks
This commit is contained in:
Benny Joo authored and GitHub committed 2025-02-21 09:01:44 -05:00
1 parent 829bb63eb9
commit c2be796a5b
13 files changed
+14 -169

No files matched your search

+1 -12
View File
@@ -1,21 +1,10 @@
import { ShellSubHeading } from "../layout";
import Meta from "../meta/Meta";
import { SkeletonText } from "../skeleton";
export function SkeletonLoader({
className,
title,
description,
}: {
className?: string;
title?: string;
description?: string;
}) {
export function SkeletonLoader({ className }: { className?: string }) {
return (
<>
<ShellSubHeading title={<div className="bg-subtle h-6 w-32" />} {...{ className }} />
{title && description && <Meta title={title} description={description} />}
<ul className="bg-default border-subtle divide-subtle -mx-4 animate-pulse divide-y rounded-md border sm:mx-0 sm:overflow-hidden">
<SkeletonItem />
<SkeletonItem />
-69
View File
@@ -1,69 +0,0 @@
"use client";
import Head from "next/head";
import { createContext, useContext, useState, useEffect } from "react";
import type { ReactNode } from "react";
import { APP_NAME } from "@calcom/lib/constants";
type MetaType = {
title: string;
description: string;
backButton?: boolean;
CTA?: ReactNode;
borderInShellHeader?: boolean;
};
const initialMeta: MetaType = {
title: "",
description: "",
backButton: false,
CTA: null,
borderInShellHeader: true,
};
const MetaContext = createContext({
meta: initialMeta,
// eslint-disable-next-line @typescript-eslint/no-empty-function
setMeta: (_newMeta: Partial<MetaType>) => {},
});
export function useMeta() {
return useContext(MetaContext);
}
export function MetaProvider({ children }: { children: ReactNode }) {
const [value, setValue] = useState(initialMeta);
const setMeta = (newMeta: Partial<MetaType>) => {
setValue((v) => ({ ...v, ...newMeta }));
};
return <MetaContext.Provider value={{ meta: value, setMeta }}>{children}</MetaContext.Provider>;
}
/**
* The purpose of this component is to simplify title and description handling.
* Similarly to `next/head`'s `Head` component this allow us to update the metadata for a page
* from any children, also exposes the metadata via the `useMeta` hook in case we need them
* elsewhere (ie. on a Heading, Title, Subtitle, etc.)
* @example <Meta title="Password" description="Manage settings for your account passwords" />
*/
export default function Meta({ title, description, backButton, CTA, borderInShellHeader }: MetaType) {
const { setMeta, meta } = useMeta();
/* @TODO: maybe find a way to have this data on first render to prevent flicker */
useEffect(() => {
if (meta.title !== title || meta.description !== description || meta.CTA !== CTA) {
setMeta({ title, description, backButton, CTA, borderInShellHeader });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [title, description, backButton, CTA]);
const title_ = `${title} | ${APP_NAME}`;
return (
<Head>
<title>{title_}</title>
<meta name="description" content={description} />
</Head>
);
}
-1
View File
@@ -1 +0,0 @@
export { default as Meta, MetaProvider, useMeta } from "./Meta";
-54
View File
@@ -1,54 +0,0 @@
import { render } from "@testing-library/react";
import { vi } from "vitest";
import Meta, { useMeta } from "./Meta";
vi.mock("./Meta", async () => {
const actualMeta = (await vi.importActual("./Meta")) as object;
const MockMeta = ({ title, description }: { title: string; description: string }) => (
<div>
<h1>{title}</h1>
<p>{description}</p>
</div>
);
type MetaProviderProps = {
children: React.ReactNode;
};
return {
...actualMeta,
default: MockMeta,
useMeta: vi.fn(),
MetaProvider: ({ children }: MetaProviderProps) => children,
};
});
describe("Meta Component", () => {
test("Should render with default metadata", () => {
(useMeta as jest.Mock).mockReturnValue({
meta: { title: "", description: "", backButton: false, CTA: null },
});
const { getByText } = render(<Meta title="Page Title" description="Page Description" />);
expect(getByText("Page Title")).toBeInTheDocument();
expect(getByText("Page Description")).toBeInTheDocument();
});
test("Should update metadata when props change", () => {
(useMeta as jest.Mock).mockReturnValue({
meta: { title: "", description: "", backButton: false, CTA: null },
});
const { rerender, getByText } = render(<Meta title="Page Title" description="Page Description" />);
expect(getByText("Page Title")).toBeInTheDocument();
expect(getByText("Page Description")).toBeInTheDocument();
rerender(<Meta title="New Title" description="New Description" />);
expect(getByText("New Title")).toBeInTheDocument();
expect(getByText("New Description")).toBeInTheDocument();
});
});
-1
View File
@@ -124,7 +124,6 @@ export { AppListCard } from "./components/app-list-card";
export { DisconnectIntegrationComponent } from "./components/disconnect-calendar-integration";
export { CalendarSwitchComponent } from "./components/calendar-switch";
export { showToast, ErrorToast, SuccessToast, WarningToast } from "./components/toast"; // We don't export the toast components as they are only used in local storybook file
export { Meta, MetaProvider, useMeta } from "./components/meta";
export { ShellSubHeading } from "./components/layout";
/** ⬇️ TODO - Move these to components */