Skip to content

Commit

Permalink
chore: Add props telemerty reporting for code-view component (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris authored Mar 7, 2024
1 parent f2a97aa commit 577297e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/code-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { InternalCodeView } from "./internal";
export type { CodeViewProps };

export default function CodeView(props: CodeViewProps) {
const baseComponentProps = useBaseComponent("CodeView");
const baseComponentProps = useBaseComponent("CodeView", {
props: { lineNumbers: props.lineNumbers },
});
return <InternalCodeView {...props} {...baseComponentProps} />;
}

Expand Down
10 changes: 7 additions & 3 deletions src/internal/base-component/use-base-component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { initAwsUiVersions, useComponentMetadata } from "@cloudscape-design/component-toolkit/internal";
import {
ComponentConfiguration,
initAwsUiVersions,
useComponentMetadata,
} from "@cloudscape-design/component-toolkit/internal";
import { MutableRefObject } from "react";
import { PACKAGE_SOURCE, PACKAGE_VERSION } from "../environment";
import { useTelemetry } from "./use-telemetry";
Expand All @@ -17,8 +21,8 @@ export interface InternalBaseComponentProps {
* attached to the (internal) component's root DOM node. The hook takes care of attaching the metadata to this
* root DOM node and emits the telemetry for this component.
*/
export default function useBaseComponent<T = any>(componentName: string) {
useTelemetry(componentName);
export default function useBaseComponent<T = any>(componentName: string, config?: ComponentConfiguration) {

Check warning on line 24 in src/internal/base-component/use-base-component.ts

View workflow job for this annotation

GitHub Actions / build / build

Unexpected any. Specify a different type

Check warning on line 24 in src/internal/base-component/use-base-component.ts

View workflow job for this annotation

GitHub Actions / build / build

Unexpected any. Specify a different type

Check warning on line 24 in src/internal/base-component/use-base-component.ts

View workflow job for this annotation

GitHub Actions / release / release

Unexpected any. Specify a different type
useTelemetry(componentName, config);
const elementRef = useComponentMetadata<T>(componentName, PACKAGE_VERSION);
return { __internalRootRef: elementRef };
}
Expand Down
6 changes: 3 additions & 3 deletions src/internal/base-component/use-telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { useComponentMetrics } from "@cloudscape-design/component-toolkit/internal";
import { ComponentConfiguration, useComponentMetrics } from "@cloudscape-design/component-toolkit/internal";
import { PACKAGE_SOURCE, PACKAGE_VERSION, THEME } from "../environment";
import { useVisualRefresh } from "./use-visual-refresh";

export function useTelemetry(componentName: string) {
export function useTelemetry(componentName: string, config?: ComponentConfiguration) {
const theme = useVisualRefresh() ? "vr" : THEME;
useComponentMetrics(componentName, { packageSource: PACKAGE_SOURCE, packageVersion: PACKAGE_VERSION, theme });
useComponentMetrics(componentName, { packageSource: PACKAGE_SOURCE, packageVersion: PACKAGE_VERSION, theme }, config);
}

0 comments on commit 577297e

Please sign in to comment.