Skip to content

Commit

Permalink
chore: Add support for analytics tag
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldowseza committed Jul 2, 2024
1 parent 081f197 commit f6af30b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
15 changes: 15 additions & 0 deletions fixtures/components/analytics-tag/example/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import * as React from 'react';

export interface ExampleProps {
/**
* @analytics View details in Analytics tab
*/
analyticsMetadata?: string;
children?: React.ReactNode;
}

export default function Example({ children }: ExampleProps): JSX.Element {
return <div>{children}</div>;
}
7 changes: 7 additions & 0 deletions fixtures/components/analytics-tag/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["./**/*.tsx"]
}
3 changes: 2 additions & 1 deletion src/components/build-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { DeclarationReflection, ReflectionKind } from 'typedoc';
import { Type } from 'typedoc/dist/lib/models';
import { ComponentDefinition, ComponentFunction } from './interfaces';
import { ComponentDefinition, ComponentFunction, ComponentProperty } from './interfaces';
import schema from '../schema';
import buildTypeDefinition from './build-type-definition';
import extractDefaultValues from './default-values-extractor';
Expand Down Expand Up @@ -133,6 +133,7 @@ export default function buildDefinition(
visualRefreshTag: prop.comment?.tags?.find(tag => tag.tagName === 'visualrefresh')?.text.trim(),
deprecatedTag: prop.comment?.tags?.find(tag => tag.tagName === 'deprecated')?.text.trim(),
i18nTag: prop.comment?.tags?.some(tag => tag.tagName === 'i18n') || undefined,
analyticsTag: prop.comment?.tags?.find(tag => tag.tagName === 'analytics')?.text.trim(),
};
}),
events: events.map(handler => buildEventInfo(handler)),
Expand Down
1 change: 1 addition & 0 deletions src/components/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ComponentProperty {
type: string;
inlineType?: TypeDefinition;
defaultValue?: string;
analyticsTag?: string;
}

export interface ComponentRegion {
Expand Down
46 changes: 46 additions & 0 deletions test/components/analytics-tag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { ComponentDefinition } from '../../src/components/interfaces';
import { buildProject } from './test-helpers';

describe('Analytics tag', () => {
let component: ComponentDefinition;
beforeAll(() => {
const result = buildProject('analytics-tag');
expect(result).toHaveLength(1);

component = result[0];
});

test('should have correct properties definitions', () => {
expect(component.properties).toEqual([
{
name: 'analyticsMetadata',
analyticsTag: 'View details in Analytics tab',
defaultValue: undefined,
deprecatedTag: undefined,
description: '',
i18nTag: undefined,
inlineType: undefined,
optional: true,
type: 'string',
visualRefreshTag: undefined,
},
]);
});

test('should have correct regions definitions', () => {
expect(component.regions).toEqual([
{
name: 'children',
analyticsTag: undefined,
isDefault: true,
deprecatedTag: undefined,
description: undefined,
displayName: undefined,
i18nTag: undefined,
visualRefreshTag: undefined,
},
]);
});
});

0 comments on commit f6af30b

Please sign in to comment.