Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('getComponentsTree', () => {
);
const target = container.querySelector('#outer-target') as HTMLElement;
expect(getComponentsTree(target)).toEqual([
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' }, children: [] },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' } },
]);
});
test('only includes components inside the specified element', () => {
Expand All @@ -38,10 +38,10 @@ describe('getComponentsTree', () => {
</>
);
expect(getComponentsTree(container.querySelector('#outer-target-1') as HTMLElement)).toEqual([
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' }, children: [] },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' } },
]);
expect(getComponentsTree(container.querySelector('#outer-target-2') as HTMLElement)).toEqual([
{ name: 'ComponentTwo', label: 'sub label', children: [] },
{ name: 'ComponentTwo', label: 'sub label' },
]);
});
test('can include multiple components', () => {
Expand All @@ -55,11 +55,11 @@ describe('getComponentsTree', () => {
{
name: 'ComponentThree',
children: [
{ name: 'ComponentTwo', label: 'sub label', children: [] },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' }, children: [] },
{ name: 'ComponentTwo', label: 'sub label' },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' } },
],
},
{ name: 'ComponentTwo', label: 'sub label', children: [] },
{ name: 'ComponentTwo', label: 'sub label' },
]);
});
test('can include multiple nested components', () => {
Expand All @@ -74,13 +74,13 @@ describe('getComponentsTree', () => {
{
name: 'ComponentThree',
children: [
{ name: 'ComponentTwo', label: 'sub label', children: [] },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' }, children: [] },
{ name: 'ComponentTwo', label: 'sub label' },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' } },
{
name: 'ComponentThree',
children: [
{ name: 'ComponentTwo', label: 'sub label', children: [] },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' }, children: [] },
{ name: 'ComponentTwo', label: 'sub label' },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' } },
],
},
],
Expand All @@ -98,11 +98,11 @@ describe('getComponentsTree', () => {
{
name: 'ComponentThree',
children: [
{ name: 'ComponentTwo', label: 'sub label', children: [] },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' }, children: [] },
{ name: 'ComponentTwo', label: 'sub label' },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' } },
],
},
{ name: 'ComponentTwo', label: 'sub label', children: [] },
{ name: 'ComponentTwo', label: 'sub label' },
]);
});
test('skips malformed metadata', () => {
Expand All @@ -113,7 +113,7 @@ describe('getComponentsTree', () => {
);
const target = container.querySelector('#outer-target') as HTMLElement;
expect(getComponentsTree(target)).toEqual([
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' }, children: [] },
{ name: 'ComponentOne', label: 'component label', properties: { multi: 'true' } },
]);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/internal/analytics-metadata/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface GeneratedAnalyticsMetadata {
contexts: Array<GeneratedAnalyticsMetadataComponentContext>;
}

export interface GeneratedAnalyticsMetadataComponent {
interface GeneratedAnalyticsMetadataComponent {
// name of the component. For example: "awsui.RadioGroup". We prefix the actual name with awsui to account for future tagging of custom components
name: string;

Expand Down
16 changes: 11 additions & 5 deletions src/internal/analytics-metadata/page-scanner-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import { METADATA_ATTRIBUTE } from './attributes';
import { isNodeComponent } from './dom-utils';
import { GeneratedAnalyticsMetadataComponent } from './interfaces';
import { getGeneratedAnalyticsMetadata } from './utils';

interface GeneratedAnalyticsMetadataComponentTree extends GeneratedAnalyticsMetadataComponent {
interface GeneratedAnalyticsMetadataComponentTree {
name: string;
label: string;
properties?: Record<string, string>;
children?: Array<GeneratedAnalyticsMetadataComponentTree>;
}

Expand All @@ -26,10 +28,14 @@ const getComponentsTreeRecursive = (
return;
}
visited.add(componentNode);
tree.push({
const treeItem: GeneratedAnalyticsMetadataComponentTree = {
...getGeneratedAnalyticsMetadata(componentNode).contexts[0].detail,
children: getComponentsTreeRecursive(componentNode, visited),
});
};
const children = getComponentsTreeRecursive(componentNode, visited);
if (children.length > 0) {
treeItem.children = children;
}
tree.push(treeItem);
});
return tree;
};
Expand Down
Loading