-
Notifications
You must be signed in to change notification settings - Fork 171
chore: Provide additinal component metadata #3483
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,14 @@ import { MutableRefObject } from 'react'; | |
import { | ||
ComponentConfiguration, | ||
useComponentMetadata, | ||
useComponentMetrics, | ||
useFocusVisible, | ||
} from '@cloudscape-design/component-toolkit/internal'; | ||
|
||
import { AnalyticsMetadata } from '../../analytics/interfaces'; | ||
import { PACKAGE_VERSION } from '../../environment'; | ||
import { useTelemetry } from '../use-telemetry'; | ||
import { PACKAGE_SOURCE, PACKAGE_VERSION, THEME } from '../../environment'; | ||
import { getVisualTheme } from '../../utils/get-visual-theme'; | ||
import { useVisualRefresh } from '../use-visual-mode'; | ||
|
||
export interface InternalBaseComponentProps<T = any> { | ||
__internalRootRef?: MutableRefObject<T | null> | null; | ||
|
@@ -26,8 +28,14 @@ export default function useBaseComponent<T = any>( | |
config?: ComponentConfiguration, | ||
analyticsMetadata?: AnalyticsMetadata | ||
) { | ||
useTelemetry(componentName, config); | ||
const isVisualRefresh = useVisualRefresh(); | ||
const theme = getVisualTheme(THEME, isVisualRefresh); | ||
useComponentMetrics(componentName, { packageSource: PACKAGE_SOURCE, packageVersion: PACKAGE_VERSION, theme }, config); | ||
useFocusVisible(); | ||
const elementRef = useComponentMetadata<T>(componentName, PACKAGE_VERSION, { ...analyticsMetadata }); | ||
const elementRef = useComponentMetadata<T>( | ||
componentName, | ||
{ packageName: PACKAGE_SOURCE, version: PACKAGE_VERSION, theme }, | ||
Comment on lines
+33
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an annoying structure difference between |
||
analyticsMetadata as any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This value is typed differently in the toolkit and this package // this package
export interface AnalyticsMetadata {
instanceIdentifier?: string;
flowType?: FlowType;
errorContext?: string;
resourceType?: string;
}
// toolkit
export type AnalyticsMetadata = JSONObject; This component's more strict type is not assignable to the toolkit. Before my change we used to fool typescript with runtime code |
||
); | ||
return { __internalRootRef: elementRef }; | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched all non-UI components to
useBaseComponent
for consistency.The only difference, there is
__internalRootRef
which is left unused in these components, but the ref handling code checks its presence anyway, so this ref is effectively a no-op