@trackunit/react-widgets 2.18.7 → 2.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +36 -1
- package/index.esm.js +36 -3
- package/package.json +8 -7
- package/src/hooks/useWidgetListItemClickAnalytics.d.ts +32 -0
- package/src/index.d.ts +1 -0
package/index.cjs.js
CHANGED
|
@@ -4,8 +4,9 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
5
5
|
var reactComponents = require('@trackunit/react-components');
|
|
6
6
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
7
|
-
var
|
|
7
|
+
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
8
8
|
var react = require('react');
|
|
9
|
+
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
9
10
|
var tailwindMerge = require('tailwind-merge');
|
|
10
11
|
|
|
11
12
|
var defaultTranslations = {
|
|
@@ -162,6 +163,38 @@ const WidgetNoData = ({ type = "Neutral", description, ref }) => {
|
|
|
162
163
|
return (jsxRuntime.jsx("div", { className: "flex h-full w-full flex-col items-center justify-center", ref: ref, children: jsxRuntime.jsx(reactComponents.EmptyState, { customImageSrc: type === "Good" ? img$1 : img, description: description }) }));
|
|
163
164
|
};
|
|
164
165
|
|
|
166
|
+
const MY_HOME_PAGE_NAME = "My Home";
|
|
167
|
+
const widgetListItemClickEvents = {
|
|
168
|
+
"Widget - List item clicked": irisAppRuntimeCore.createEvent({
|
|
169
|
+
description: "List item inside a widget is clicked",
|
|
170
|
+
}),
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Track widget list item interactions with page and widget metadata.
|
|
174
|
+
*
|
|
175
|
+
* Fires the `Widget - List item clicked` Amplitude event with the page name
|
|
176
|
+
* and the widget's `irisAppExtensionId`.
|
|
177
|
+
*/
|
|
178
|
+
const useWidgetListItemClickAnalytics = ({ pageName, }) => {
|
|
179
|
+
const { logEvent } = reactCoreHooks.useAnalytics(widgetListItemClickEvents);
|
|
180
|
+
const widgetIrisAppExtensionId = react.useMemo(() => {
|
|
181
|
+
const rawHash = globalThis.location.hash;
|
|
182
|
+
const hash = rawHash.startsWith("#") ? rawHash.slice(1) : rawHash;
|
|
183
|
+
return new URLSearchParams(hash).get("irisAppExtensionId") ?? undefined;
|
|
184
|
+
}, []);
|
|
185
|
+
const trackWidgetListItemClick = react.useCallback((context) => {
|
|
186
|
+
if (!pageName || !widgetIrisAppExtensionId) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
logEvent("Widget - List item clicked", {
|
|
190
|
+
pageName,
|
|
191
|
+
widgetName: widgetIrisAppExtensionId,
|
|
192
|
+
...context,
|
|
193
|
+
});
|
|
194
|
+
}, [logEvent, pageName, widgetIrisAppExtensionId]);
|
|
195
|
+
return react.useMemo(() => ({ trackWidgetListItemClick }), [trackWidgetListItemClick]);
|
|
196
|
+
};
|
|
197
|
+
|
|
165
198
|
const cvaWidgetContent = cssClassVarianceUtilities.cvaMerge(["@container", "overflow-hidden", "h-full", "w-full", "bg-white", "grid"], {
|
|
166
199
|
variants: {
|
|
167
200
|
layout: {
|
|
@@ -402,9 +435,11 @@ const WidgetKPI = ({ title, value, loading = false, unit, className, "data-testi
|
|
|
402
435
|
*/
|
|
403
436
|
setupLibraryTranslations();
|
|
404
437
|
|
|
438
|
+
exports.MY_HOME_PAGE_NAME = MY_HOME_PAGE_NAME;
|
|
405
439
|
exports.WidgetContent = WidgetContent;
|
|
406
440
|
exports.WidgetEditBody = WidgetEditBody;
|
|
407
441
|
exports.WidgetError = WidgetError;
|
|
408
442
|
exports.WidgetKPI = WidgetKPI;
|
|
409
443
|
exports.WidgetMissingConfiguration = WidgetMissingConfiguration;
|
|
410
444
|
exports.WidgetNoData = WidgetNoData;
|
|
445
|
+
exports.useWidgetListItemClickAnalytics = useWidgetListItemClickAnalytics;
|
package/index.esm.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { EmptyState, Card, CardHeader, CardBody, CardFooter, Button, cvaInteractableItem, SkeletonLines, Icon, Tooltip, Text, TrendIndicators, Notice } from '@trackunit/react-components';
|
|
4
|
-
import { WidgetConfigRuntime } from '@trackunit/iris-app-runtime-core';
|
|
4
|
+
import { WidgetConfigRuntime, createEvent } from '@trackunit/iris-app-runtime-core';
|
|
5
|
+
import { useAnalytics } from '@trackunit/react-core-hooks';
|
|
6
|
+
import { useMemo, useCallback, useState } from 'react';
|
|
5
7
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
6
|
-
import { useState, useCallback } from 'react';
|
|
7
8
|
import { twMerge } from 'tailwind-merge';
|
|
8
9
|
|
|
9
10
|
var defaultTranslations = {
|
|
@@ -160,6 +161,38 @@ const WidgetNoData = ({ type = "Neutral", description, ref }) => {
|
|
|
160
161
|
return (jsx("div", { className: "flex h-full w-full flex-col items-center justify-center", ref: ref, children: jsx(EmptyState, { customImageSrc: type === "Good" ? img$1 : img, description: description }) }));
|
|
161
162
|
};
|
|
162
163
|
|
|
164
|
+
const MY_HOME_PAGE_NAME = "My Home";
|
|
165
|
+
const widgetListItemClickEvents = {
|
|
166
|
+
"Widget - List item clicked": createEvent({
|
|
167
|
+
description: "List item inside a widget is clicked",
|
|
168
|
+
}),
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Track widget list item interactions with page and widget metadata.
|
|
172
|
+
*
|
|
173
|
+
* Fires the `Widget - List item clicked` Amplitude event with the page name
|
|
174
|
+
* and the widget's `irisAppExtensionId`.
|
|
175
|
+
*/
|
|
176
|
+
const useWidgetListItemClickAnalytics = ({ pageName, }) => {
|
|
177
|
+
const { logEvent } = useAnalytics(widgetListItemClickEvents);
|
|
178
|
+
const widgetIrisAppExtensionId = useMemo(() => {
|
|
179
|
+
const rawHash = globalThis.location.hash;
|
|
180
|
+
const hash = rawHash.startsWith("#") ? rawHash.slice(1) : rawHash;
|
|
181
|
+
return new URLSearchParams(hash).get("irisAppExtensionId") ?? undefined;
|
|
182
|
+
}, []);
|
|
183
|
+
const trackWidgetListItemClick = useCallback((context) => {
|
|
184
|
+
if (!pageName || !widgetIrisAppExtensionId) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
logEvent("Widget - List item clicked", {
|
|
188
|
+
pageName,
|
|
189
|
+
widgetName: widgetIrisAppExtensionId,
|
|
190
|
+
...context,
|
|
191
|
+
});
|
|
192
|
+
}, [logEvent, pageName, widgetIrisAppExtensionId]);
|
|
193
|
+
return useMemo(() => ({ trackWidgetListItemClick }), [trackWidgetListItemClick]);
|
|
194
|
+
};
|
|
195
|
+
|
|
163
196
|
const cvaWidgetContent = cvaMerge(["@container", "overflow-hidden", "h-full", "w-full", "bg-white", "grid"], {
|
|
164
197
|
variants: {
|
|
165
198
|
layout: {
|
|
@@ -400,4 +433,4 @@ const WidgetKPI = ({ title, value, loading = false, unit, className, "data-testi
|
|
|
400
433
|
*/
|
|
401
434
|
setupLibraryTranslations();
|
|
402
435
|
|
|
403
|
-
export { WidgetContent, WidgetEditBody, WidgetError, WidgetKPI, WidgetMissingConfiguration, WidgetNoData };
|
|
436
|
+
export { MY_HOME_PAGE_NAME, WidgetContent, WidgetEditBody, WidgetError, WidgetKPI, WidgetMissingConfiguration, WidgetNoData, useWidgetListItemClickAnalytics };
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-widgets",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.3",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/react-components": "1.
|
|
11
|
-
"@trackunit/
|
|
12
|
-
"@trackunit/
|
|
13
|
-
"@trackunit/
|
|
14
|
-
"@trackunit/ui-
|
|
15
|
-
"@trackunit/
|
|
10
|
+
"@trackunit/react-components": "1.23.2",
|
|
11
|
+
"@trackunit/react-core-hooks": "1.16.3",
|
|
12
|
+
"@trackunit/iris-app-runtime-core": "1.16.2",
|
|
13
|
+
"@trackunit/css-class-variance-utilities": "1.12.1",
|
|
14
|
+
"@trackunit/ui-design-tokens": "1.12.1",
|
|
15
|
+
"@trackunit/ui-icons": "1.12.2",
|
|
16
|
+
"@trackunit/i18n-library-translation": "1.20.3",
|
|
16
17
|
"tailwind-merge": "^2.0.0"
|
|
17
18
|
},
|
|
18
19
|
"peerDependencies": {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseEvent } from "@trackunit/iris-app-runtime-core";
|
|
2
|
+
interface WidgetListItemClickedEvent extends BaseEvent {
|
|
3
|
+
pageName: string;
|
|
4
|
+
widgetName: string;
|
|
5
|
+
/**
|
|
6
|
+
* The clicked row's primary identifier — its meaning is determined by the
|
|
7
|
+
* widget (e.g. asset ID for asset/attention/inspection/service lists, site
|
|
8
|
+
* ID for the site list, customer ID for the excessive-usage list). Use
|
|
9
|
+
* `widgetName` to disambiguate the entity type when querying in Amplitude.
|
|
10
|
+
*/
|
|
11
|
+
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* Optional per-row category for widgets whose rows are typed (e.g. alert
|
|
14
|
+
* subtype for the attention list, site type for the site list). Omit for
|
|
15
|
+
* widgets without a natural per-row classification.
|
|
16
|
+
*/
|
|
17
|
+
type?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const MY_HOME_PAGE_NAME = "My Home";
|
|
20
|
+
type UseWidgetListItemClickAnalyticsResult = {
|
|
21
|
+
trackWidgetListItemClick: (context: Pick<WidgetListItemClickedEvent, "id" | "type">) => void;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Track widget list item interactions with page and widget metadata.
|
|
25
|
+
*
|
|
26
|
+
* Fires the `Widget - List item clicked` Amplitude event with the page name
|
|
27
|
+
* and the widget's `irisAppExtensionId`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const useWidgetListItemClickAnalytics: ({ pageName, }: {
|
|
30
|
+
pageName?: string;
|
|
31
|
+
}) => UseWidgetListItemClickAnalyticsResult;
|
|
32
|
+
export {};
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./EmptyStates/Error/WidgetError";
|
|
2
2
|
export * from "./EmptyStates/MissingConfiguration/WidgetMissingConfiguration";
|
|
3
3
|
export * from "./EmptyStates/NoData/WidgetNoData";
|
|
4
|
+
export * from "./hooks/useWidgetListItemClickAnalytics";
|
|
4
5
|
export * from "./Widget/WidgetContent";
|
|
5
6
|
export * from "./Widget/WidgetEditBody";
|
|
6
7
|
export * from "./WidgetKPI/WidgetKPI";
|