Merge pull request #22482 from backstage/camilaibs/fix-analytics-context
[DI] Add analytics api backward compatibility
This commit is contained in:
@@ -35,8 +35,8 @@ describe('AnalyticsContext', () => {
|
||||
it('returns default values', () => {
|
||||
const { result } = renderHook(() => useAnalyticsContext());
|
||||
expect(result.current).toEqual({
|
||||
extensionId: 'App',
|
||||
pluginId: 'root',
|
||||
extensionId: 'app',
|
||||
pluginId: 'app',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -49,8 +49,8 @@ describe('AnalyticsContext', () => {
|
||||
</AnalyticsContext>,
|
||||
);
|
||||
|
||||
expect(result.getByTestId('extension-id')).toHaveTextContent('App');
|
||||
expect(result.getByTestId('plugin-id')).toHaveTextContent('root');
|
||||
expect(result.getByTestId('extension-id')).toHaveTextContent('app');
|
||||
expect(result.getByTestId('plugin-id')).toHaveTextContent('app');
|
||||
});
|
||||
|
||||
it('uses provided analytics context', () => {
|
||||
@@ -60,7 +60,7 @@ describe('AnalyticsContext', () => {
|
||||
</AnalyticsContext>,
|
||||
);
|
||||
|
||||
expect(result.getByTestId('extension-id')).toHaveTextContent('App');
|
||||
expect(result.getByTestId('extension-id')).toHaveTextContent('app');
|
||||
expect(result.getByTestId('plugin-id')).toHaveTextContent('custom');
|
||||
});
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ export const useAnalyticsContext = (): AnalyticsContextValue => {
|
||||
// Provide a default value if no value exists.
|
||||
if (theContext === undefined) {
|
||||
return {
|
||||
pluginId: 'root',
|
||||
extensionId: 'App',
|
||||
pluginId: 'app',
|
||||
extensionId: 'app',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,6 @@ export type CommonAnalyticsContext = {
|
||||
*/
|
||||
pluginId: string;
|
||||
|
||||
/**
|
||||
* The nearest known parent extension where the event was captured.
|
||||
*/
|
||||
/**
|
||||
* The nearest known parent extension where the event was captured.
|
||||
*/
|
||||
|
||||
@@ -53,8 +53,8 @@ describe('useAnalytics', () => {
|
||||
some: 'value',
|
||||
},
|
||||
context: {
|
||||
extensionId: 'App',
|
||||
pluginId: 'root',
|
||||
extensionId: 'app',
|
||||
pluginId: 'app',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,8 +23,11 @@ import { Tracker } from './Tracker';
|
||||
function useAnalyticsApi(): AnalyticsApi {
|
||||
try {
|
||||
return useApi(analyticsApiRef);
|
||||
} catch {
|
||||
return { captureEvent: () => {} };
|
||||
} catch (error) {
|
||||
if (error.name === 'NotImplementedError') {
|
||||
return { captureEvent: () => {} };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ export function ExtensionBoundary(props: ExtensionBoundaryProps) {
|
||||
// Skipping "routeRef" attribute in the new system, the extension "id" should provide more insight
|
||||
const attributes = {
|
||||
extensionId: node.spec.id,
|
||||
pluginId: node.spec.source?.id,
|
||||
pluginId: node.spec.source?.id ?? 'app',
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user