Skip to content

Commit

Permalink
change componentConfiguration to object
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldowseza committed Oct 18, 2024
1 parent d29e88e commit 95914eb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/internal/analytics/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,15 @@ export interface IPerformanceMetrics {
taskCompletionData: TaskCompletionDataMethod;
}

type JSONValue = string | number | boolean | null | undefined;
export interface JSONObject {
[key: string]: JSONObject | JSONValue;
}

export interface ComponentMountedProps {
componentName: string;
taskInteractionId?: string;
componentConfiguration: string | undefined;
componentConfiguration: JSONObject;
}

export interface ComponentUpdatedProps extends ComponentMountedProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { mockPerformanceMetrics } from '../../../analytics/__tests__/mocks';
type RenderProps = Partial<UseTableInteractionMetricsProps>;

const defaultProps = {
getComponentConfiguration: () => '',
getComponentConfiguration: () => ({}),
getComponentIdentifier: () => 'My resources',
itemCount: 10,
loading: undefined,
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('useTableInteractionMetrics', () => {
expect(componentMounted).toHaveBeenCalledWith({
taskInteractionId: expect.any(String),
componentName: 'table',
componentConfiguration: '',
componentConfiguration: {},
});
});

Expand Down Expand Up @@ -138,7 +138,7 @@ describe('useTableInteractionMetrics', () => {
taskInteractionId: expect.any(String),
componentName: 'table',
actionType: 'filter',
componentConfiguration: '',
componentConfiguration: {},
});
});

Expand Down Expand Up @@ -227,19 +227,19 @@ describe('useTableInteractionMetrics', () => {

test('componentConfiguration is added to the component updated metrics', () => {
const { setLastUserAction, rerender } = renderUseTableInteractionMetricsHook({});
const componentConfigurationValue = '{filterText = test}';
const componentConfiguration = { filterText: 'test' };
setLastUserAction('filter');
rerender({ loading: true });
rerender({
loading: false,
getComponentConfiguration: () => componentConfigurationValue,
getComponentConfiguration: () => componentConfiguration,
});

expect(ComponentMetrics.componentUpdated).toHaveBeenCalledTimes(1);
expect(ComponentMetrics.componentUpdated).toHaveBeenCalledWith(
expect.objectContaining({
actionType: 'filter',
componentConfiguration: componentConfigurationValue,
componentConfiguration,
})
);
});
Expand Down
3 changes: 2 additions & 1 deletion src/internal/hooks/use-table-interaction-metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useEffect, useRef } from 'react';

import { ComponentMetrics, PerformanceMetrics } from '../../analytics';
import { JSONObject } from '../../analytics/interfaces';
import { useEffectOnUpdate } from '../use-effect-on-update';
import { useRandomId } from '../use-unique-id';

Expand Down Expand Up @@ -35,7 +36,7 @@ export interface UseTableInteractionMetricsProps {
loading: boolean | undefined;
itemCount: number;
getComponentIdentifier: () => string | undefined;
getComponentConfiguration: () => string | undefined;
getComponentConfiguration: () => JSONObject;
interactionMetadata: () => string;
}

Expand Down
4 changes: 2 additions & 2 deletions src/table/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const InternalTable = React.forwardRef(
const filterData = filterRef.current;
const paginationData = paginationRef.current;

return JSON.stringify({
return {
variant,
flowType: rest.analyticsMetadata?.flowType,
instanceIdentifier: analyticsMetadata?.instanceIdentifier,
Expand All @@ -238,7 +238,7 @@ const InternalTable = React.forwardRef(
totalNumberOfResources: paginationData.totalPageCount,
resourcesPerPage: allRows?.length || 0,
resourcesSelected: selectedItems?.length > 0,
});
};
};

const { setLastUserAction, tableInteractionAttributes } = useTableInteractionMetrics({
Expand Down

0 comments on commit 95914eb

Please sign in to comment.