Skip to content

Commit

Permalink
remove extended component metadata reporting (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris authored Feb 7, 2024
1 parent ea870f1 commit d03c73c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,3 @@ test('should attach readonly metadata to the returned root DOM node', () => {
expect(rootNode[COMPONENT_METADATA_KEY]).toEqual({ name: 'test-component', version: '3.0.0' });
expect(Object.isFrozen(rootNode[COMPONENT_METADATA_KEY])).toBe(true);
});

test('supports optional component configuration information', () => {
function TestComponent() {
const ref = useComponentMetadata('test-component', '3.0.0', { type: 'success' });
return <div ref={ref}>Test</div>;
}

const { container } = render(<TestComponent />);
const rootNode: any = container.firstChild;

expect(rootNode[COMPONENT_METADATA_KEY]).toEqual({
name: 'test-component',
version: '3.0.0',
componentConfiguration: { type: 'success' },
});
});
25 changes: 10 additions & 15 deletions src/internal/base-component/component-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,22 @@ import { useEffect, useRef } from 'react';

export const COMPONENT_METADATA_KEY = '__awsuiMetadata__';

export function useComponentMetadata<T = any>(
componentName: string,
packageVersion: string,
componentConfiguration?: Record<string, any>
) {
interface AwsUiMetadata {
name: string;
version: string;
componentConfiguration?: Record<string, any>;
}

interface HTMLMetadataElement extends HTMLElement {
[COMPONENT_METADATA_KEY]: AwsUiMetadata;
}
interface AwsUiMetadata {
name: string;
version: string;
}

interface HTMLMetadataElement extends HTMLElement {
[COMPONENT_METADATA_KEY]: AwsUiMetadata;
}

export function useComponentMetadata<T = any>(componentName: string, packageVersion: string) {
const elementRef = useRef<T>(null);

useEffect(() => {
if (elementRef.current) {
const node = elementRef.current as unknown as HTMLMetadataElement;
const metadata: AwsUiMetadata = { componentConfiguration, name: componentName, version: packageVersion };
const metadata: AwsUiMetadata = { name: componentName, version: packageVersion };

Object.freeze(metadata);
Object.defineProperty(node, COMPONENT_METADATA_KEY, { value: metadata, writable: false, configurable: true });
Expand Down

0 comments on commit d03c73c

Please sign in to comment.