Skip to content

chore: Add value in RadioGroup and Tiles analytics metadata #3668

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

Merged
merged 1 commit into from
Jul 21, 2025
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
36 changes: 27 additions & 9 deletions src/radio-group/__tests__/analytics-metadata.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import React from 'react';
import { render } from '@testing-library/react';

import {
activateAnalyticsMetadata,
GeneratedAnalyticsMetadataFragment,
} from '@cloudscape-design/component-toolkit/internal/analytics-metadata';
import { activateAnalyticsMetadata } from '@cloudscape-design/component-toolkit/internal/analytics-metadata';
import { getGeneratedAnalyticsMetadata } from '@cloudscape-design/component-toolkit/internal/analytics-metadata/utils';

import FormField from '../../../lib/components/form-field';
Expand Down Expand Up @@ -35,7 +32,13 @@ function renderRadioGroup(props: RadioGroupProps) {
return createWrapper(renderResult.container).findRadioGroup()!;
}

const getMetadata = (label: string, position: string, value: string, disabled?: boolean) => {
const getMetadata = (
label: string,
position: string,
value: string,
disabled: boolean = false,
currentValue: string | null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between value and currentValue? why do we need both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value is the value of the specific radio button that is being inspected. currentValue is the value currently selected for the radio group.

) => {
const eventMetadata = {
action: 'select',
detail: {
Expand All @@ -45,13 +48,16 @@ const getMetadata = (label: string, position: string, value: string, disabled?:
},
};

let metadata: GeneratedAnalyticsMetadataFragment = {
let metadata = {
contexts: [
{
type: 'component',
detail: {
name: 'awsui.RadioGroup',
label: componentLabel,
properties: {
value: `${currentValue}`,
},
},
},
],
Expand All @@ -71,19 +77,25 @@ describe('Checkbox renders correct analytics metadata', () => {

validateComponentNameAndLabels(wrapper.findInputByValue('second')!.getElement(), labels);
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('second')!.getElement())).toEqual(
getMetadata('Second choice', '2', 'second', false)
getMetadata('Second choice', '2', 'second', false, 'second')
);
validateComponentNameAndLabels(wrapper.findInputByValue('first')!.getElement(), labels);
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('first')!.getElement())).toEqual(
getMetadata('First choice', '2', 'first', true)
getMetadata('First choice', '2', 'first', true, 'second')
);
});
test('with null value', () => {
const wrapper = renderRadioGroup({ value: null });
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('second')!.getElement())).toEqual(
getMetadata('Second choice', '2', 'second', false, null)
);
});
test('readonly', () => {
const wrapper = renderRadioGroup({ value: 'second', readOnly: true });

validateComponentNameAndLabels(wrapper.findInputByValue('second')!.getElement(), labels);
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('second')!.getElement())).toEqual(
getMetadata('Second choice', '2', 'second', true)
getMetadata('Second choice', '2', 'second', true, 'second')
);
});
describe('when rendered in a form field', () => {
Expand All @@ -101,6 +113,9 @@ describe('Checkbox renders correct analytics metadata', () => {
detail: {
name: 'awsui.RadioGroup',
label: 'form field label',
properties: {
value: '2',
},
},
},
{
Expand All @@ -127,6 +142,9 @@ describe('Checkbox renders correct analytics metadata', () => {
detail: {
name: 'awsui.RadioGroup',
label: 'aria label',
properties: {
value: '2',
},
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions src/radio-group/analytics-metadata/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ export interface GeneratedAnalyticsMetadataRadioGroupSelect {
export interface GeneratedAnalyticsMetadataRadioGroupComponent {
name: 'awsui.RadioGroup';
label: string | LabelIdentifier;
properties: {
value: string;
};
}
3 changes: 3 additions & 0 deletions src/radio-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const RadioGroup = React.forwardRef((props: RadioGroupProps, ref: React.Ref<Radi
component: {
name: 'awsui.RadioGroup',
label: { root: 'self' },
properties: {
value: `${props.value}`,
},
} as GeneratedAnalyticsMetadataRadioGroupComponent,
})}
/>
Expand Down
29 changes: 25 additions & 4 deletions src/tiles/__tests__/analytics-metadata.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ function renderTiles(props: TilesProps) {
return createWrapper(renderResult.container).findTiles()!;
}

const getMetadata = (label: string, position: string, value: string, disabled?: boolean) => {
const getMetadata = (
label: string,
position: string,
value: string,
disabled: boolean = false,
currentValue: string | null
) => {
const eventMetadata = {
action: 'select',
detail: {
Expand All @@ -54,6 +60,9 @@ const getMetadata = (label: string, position: string, value: string, disabled?:
detail: {
name: 'awsui.Tiles',
label: componentLabel,
properties: {
value: `${currentValue}`,
},
},
},
],
Expand All @@ -74,20 +83,26 @@ describe('Tiles renders correct analytics metadata', () => {
// in the whole tile
validateComponentNameAndLabels(wrapper.findItemByValue('second')!.getElement(), labels);
expect(getGeneratedAnalyticsMetadata(wrapper.findItemByValue('second')!.getElement())).toEqual(
getMetadata('Second choice', '2', 'second', false)
getMetadata('Second choice', '2', 'second', false, 'second')
);
// in the radio within the tile
validateComponentNameAndLabels(wrapper.findInputByValue('first')!.getElement(), labels);
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('first')!.getElement())).toEqual(
getMetadata('First choice', '2', 'first', true)
getMetadata('First choice', '2', 'first', true, 'second')
);
});
test('with null value', () => {
const wrapper = renderTiles({ value: null });
expect(getGeneratedAnalyticsMetadata(wrapper.findItemByValue('second')!.getElement())).toEqual(
getMetadata('Second choice', '2', 'second', false, null)
);
});
test('readonly', () => {
const wrapper = renderTiles({ value: 'second', readOnly: true });

validateComponentNameAndLabels(wrapper.findInputByValue('second')!.getElement(), labels);
expect(getGeneratedAnalyticsMetadata(wrapper.findInputByValue('second')!.getElement())).toEqual(
getMetadata('Second choice', '2', 'second', true)
getMetadata('Second choice', '2', 'second', true, 'second')
);
});
describe('when rendered in a form field', () => {
Expand All @@ -105,6 +120,9 @@ describe('Tiles renders correct analytics metadata', () => {
detail: {
name: 'awsui.Tiles',
label: 'form field label',
properties: {
value: '2',
},
},
},
{
Expand All @@ -131,6 +149,9 @@ describe('Tiles renders correct analytics metadata', () => {
detail: {
name: 'awsui.Tiles',
label: 'aria label',
properties: {
value: '2',
},
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions src/tiles/analytics-metadata/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ export interface GeneratedAnalyticsMetadataTilesSelect {
export interface GeneratedAnalyticsMetadataTilesComponent {
name: 'awsui.Tiles';
label: string | LabelIdentifier;
properties: {
value: string;
};
}
3 changes: 3 additions & 0 deletions src/tiles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const Tiles = React.forwardRef((props: TilesProps, ref: React.Ref<TilesProps.Ref
const componentAnalyticsMetadata: GeneratedAnalyticsMetadataTilesComponent = {
name: 'awsui.Tiles',
label: { root: 'self' },
properties: {
value: `${props.value}`,
},
};
return (
<InternalTiles
Expand Down
Loading