@trackunit/react-core-hooks 0.2.208 → 0.2.210
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 +55 -9
- package/index.esm.js +56 -11
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
package/index.cjs.js
CHANGED
|
@@ -294,6 +294,60 @@ const useImageUploader = () => {
|
|
|
294
294
|
};
|
|
295
295
|
};
|
|
296
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Returns the query string to be appended to the URL when the app is served from a Feature Branch.
|
|
299
|
+
*/
|
|
300
|
+
const useFeatureBranchQueryString = () => {
|
|
301
|
+
const { publicUrl, buildVersion } = useEnvironment();
|
|
302
|
+
const featureBranchQueryParam = React.useMemo(() => !publicUrl || publicUrl === "/" ? "" : `?fb_url=${encodeURIComponent(publicUrl)}&fb_version=${buildVersion}`, [publicUrl, buildVersion]);
|
|
303
|
+
return { featureBranchQueryParam };
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const IRIS_APP_ASSET_PATH = "assets/";
|
|
307
|
+
/**
|
|
308
|
+
* Provides functions to get the Iris App URL and logo image.
|
|
309
|
+
*
|
|
310
|
+
* @requires EnvironmentContextProvider, TokenProvider
|
|
311
|
+
* @returns {getAppUrl, getAppImage}
|
|
312
|
+
* @example
|
|
313
|
+
* const { getAppUrl, getAppImage } = useIrisAppImage();
|
|
314
|
+
* const irisAppUrl = getAppUrl({ irisAppId, version });
|
|
315
|
+
* const { logo } = await getAppImage({ irisAppUrl, logoPath });
|
|
316
|
+
*/
|
|
317
|
+
const useIrisAppImage = () => {
|
|
318
|
+
const { irisAppSdkServerUrl, tracingHeaders } = useEnvironment();
|
|
319
|
+
const { featureBranchQueryParam } = useFeatureBranchQueryString();
|
|
320
|
+
const { token } = useToken();
|
|
321
|
+
// Add Auth headers to all fetch requests
|
|
322
|
+
const headers = React.useMemo(() => (Object.assign(Object.assign({}, tracingHeaders), { "commit-number": `${tracingHeaders["commit-number"]}`, "Content-Type": "application/json", Authorization: `Bearer ${token}` })), [token, tracingHeaders]);
|
|
323
|
+
/**
|
|
324
|
+
* Returns the URL to the Iris App SDK server for the given Iris App ID and version.
|
|
325
|
+
* If the APP is served from localhost or a Feature Branch, the URL will be part of the App Entry.
|
|
326
|
+
* In that case, do not use this function, but use the url from the App Entry instead.
|
|
327
|
+
*/
|
|
328
|
+
const getAppUrl = React.useCallback(({ irisAppId, version }) => {
|
|
329
|
+
return `${irisAppSdkServerUrl}app/${irisAppId}@${version}/`;
|
|
330
|
+
}, [irisAppSdkServerUrl]);
|
|
331
|
+
/**
|
|
332
|
+
* Given the Iris App URL and logo path, returns the URLs to the logo.
|
|
333
|
+
* The returned URLs are blob URLs, which can be used as src for <img> tags.
|
|
334
|
+
* If the APP is served from localhost or a Feature Branch, the URLs will be part of the App Entry.
|
|
335
|
+
* If the url does not exist in the App Entry, use the getIrisAppUrl function to get the URL.
|
|
336
|
+
*/
|
|
337
|
+
const getAppImage = React.useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ irisAppUrl, logoPath }) {
|
|
338
|
+
if (!logoPath) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
const logoFetchUrl = `${irisAppUrl}${IRIS_APP_ASSET_PATH}${logoPath}${featureBranchQueryParam}`;
|
|
342
|
+
const logoImageUrl = yield fetchAssetBlobUrl(logoFetchUrl, headers);
|
|
343
|
+
return logoImageUrl;
|
|
344
|
+
}), [featureBranchQueryParam, headers]);
|
|
345
|
+
return {
|
|
346
|
+
getAppUrl,
|
|
347
|
+
getAppImage,
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
|
|
297
351
|
const OemBrandingContext = React.createContext(null);
|
|
298
352
|
/**
|
|
299
353
|
* This is a hook to use the IOemBrandingContext.
|
|
@@ -680,15 +734,6 @@ const useToast = () => {
|
|
|
680
734
|
return toastContext;
|
|
681
735
|
};
|
|
682
736
|
|
|
683
|
-
/**
|
|
684
|
-
* Returns the query string to be appended to the URL when the app is served from a Feature Branch.
|
|
685
|
-
*/
|
|
686
|
-
const useFeatureBranchQueryString = () => {
|
|
687
|
-
const { publicUrl, buildVersion } = useEnvironment();
|
|
688
|
-
const featureBranchQueryParam = React.useMemo(() => !publicUrl || publicUrl === "/" ? "" : `?fb_url=${encodeURIComponent(publicUrl)}&fb_version=${buildVersion}`, [publicUrl, buildVersion]);
|
|
689
|
-
return { featureBranchQueryParam };
|
|
690
|
-
};
|
|
691
|
-
|
|
692
737
|
/**
|
|
693
738
|
* Hook for filtering a list of items by text search, client side search in a list.
|
|
694
739
|
*
|
|
@@ -851,6 +896,7 @@ exports.useFilterBarContext = useFilterBarContext;
|
|
|
851
896
|
exports.useHasAccessTo = useHasAccessTo;
|
|
852
897
|
exports.useImageUploader = useImageUploader;
|
|
853
898
|
exports.useIrisAppId = useIrisAppId;
|
|
899
|
+
exports.useIrisAppImage = useIrisAppImage;
|
|
854
900
|
exports.useIrisAppName = useIrisAppName;
|
|
855
901
|
exports.useModalDialogContext = useModalDialogContext;
|
|
856
902
|
exports.useNavigateInHost = useNavigateInHost;
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { createContext, useContext, useState, useCallback,
|
|
2
|
+
import { createContext, useContext, useState, useCallback, useMemo, useEffect } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
import { AssetRuntime, CustomerRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
|
|
5
5
|
import { filterByMultiple } from '@trackunit/shared-utils';
|
|
@@ -271,6 +271,60 @@ const useImageUploader = () => {
|
|
|
271
271
|
};
|
|
272
272
|
};
|
|
273
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Returns the query string to be appended to the URL when the app is served from a Feature Branch.
|
|
276
|
+
*/
|
|
277
|
+
const useFeatureBranchQueryString = () => {
|
|
278
|
+
const { publicUrl, buildVersion } = useEnvironment();
|
|
279
|
+
const featureBranchQueryParam = useMemo(() => !publicUrl || publicUrl === "/" ? "" : `?fb_url=${encodeURIComponent(publicUrl)}&fb_version=${buildVersion}`, [publicUrl, buildVersion]);
|
|
280
|
+
return { featureBranchQueryParam };
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const IRIS_APP_ASSET_PATH = "assets/";
|
|
284
|
+
/**
|
|
285
|
+
* Provides functions to get the Iris App URL and logo image.
|
|
286
|
+
*
|
|
287
|
+
* @requires EnvironmentContextProvider, TokenProvider
|
|
288
|
+
* @returns {getAppUrl, getAppImage}
|
|
289
|
+
* @example
|
|
290
|
+
* const { getAppUrl, getAppImage } = useIrisAppImage();
|
|
291
|
+
* const irisAppUrl = getAppUrl({ irisAppId, version });
|
|
292
|
+
* const { logo } = await getAppImage({ irisAppUrl, logoPath });
|
|
293
|
+
*/
|
|
294
|
+
const useIrisAppImage = () => {
|
|
295
|
+
const { irisAppSdkServerUrl, tracingHeaders } = useEnvironment();
|
|
296
|
+
const { featureBranchQueryParam } = useFeatureBranchQueryString();
|
|
297
|
+
const { token } = useToken();
|
|
298
|
+
// Add Auth headers to all fetch requests
|
|
299
|
+
const headers = useMemo(() => (Object.assign(Object.assign({}, tracingHeaders), { "commit-number": `${tracingHeaders["commit-number"]}`, "Content-Type": "application/json", Authorization: `Bearer ${token}` })), [token, tracingHeaders]);
|
|
300
|
+
/**
|
|
301
|
+
* Returns the URL to the Iris App SDK server for the given Iris App ID and version.
|
|
302
|
+
* If the APP is served from localhost or a Feature Branch, the URL will be part of the App Entry.
|
|
303
|
+
* In that case, do not use this function, but use the url from the App Entry instead.
|
|
304
|
+
*/
|
|
305
|
+
const getAppUrl = useCallback(({ irisAppId, version }) => {
|
|
306
|
+
return `${irisAppSdkServerUrl}app/${irisAppId}@${version}/`;
|
|
307
|
+
}, [irisAppSdkServerUrl]);
|
|
308
|
+
/**
|
|
309
|
+
* Given the Iris App URL and logo path, returns the URLs to the logo.
|
|
310
|
+
* The returned URLs are blob URLs, which can be used as src for <img> tags.
|
|
311
|
+
* If the APP is served from localhost or a Feature Branch, the URLs will be part of the App Entry.
|
|
312
|
+
* If the url does not exist in the App Entry, use the getIrisAppUrl function to get the URL.
|
|
313
|
+
*/
|
|
314
|
+
const getAppImage = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ irisAppUrl, logoPath }) {
|
|
315
|
+
if (!logoPath) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
const logoFetchUrl = `${irisAppUrl}${IRIS_APP_ASSET_PATH}${logoPath}${featureBranchQueryParam}`;
|
|
319
|
+
const logoImageUrl = yield fetchAssetBlobUrl(logoFetchUrl, headers);
|
|
320
|
+
return logoImageUrl;
|
|
321
|
+
}), [featureBranchQueryParam, headers]);
|
|
322
|
+
return {
|
|
323
|
+
getAppUrl,
|
|
324
|
+
getAppImage,
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
|
|
274
328
|
const OemBrandingContext = createContext(null);
|
|
275
329
|
/**
|
|
276
330
|
* This is a hook to use the IOemBrandingContext.
|
|
@@ -657,15 +711,6 @@ const useToast = () => {
|
|
|
657
711
|
return toastContext;
|
|
658
712
|
};
|
|
659
713
|
|
|
660
|
-
/**
|
|
661
|
-
* Returns the query string to be appended to the URL when the app is served from a Feature Branch.
|
|
662
|
-
*/
|
|
663
|
-
const useFeatureBranchQueryString = () => {
|
|
664
|
-
const { publicUrl, buildVersion } = useEnvironment();
|
|
665
|
-
const featureBranchQueryParam = useMemo(() => !publicUrl || publicUrl === "/" ? "" : `?fb_url=${encodeURIComponent(publicUrl)}&fb_version=${buildVersion}`, [publicUrl, buildVersion]);
|
|
666
|
-
return { featureBranchQueryParam };
|
|
667
|
-
};
|
|
668
|
-
|
|
669
714
|
/**
|
|
670
715
|
* Hook for filtering a list of items by text search, client side search in a list.
|
|
671
716
|
*
|
|
@@ -797,4 +842,4 @@ const useCurrentUser = () => {
|
|
|
797
842
|
return context;
|
|
798
843
|
};
|
|
799
844
|
|
|
800
|
-
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, fetchAssetBlobUrl, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomerRuntime, useEnvironment, useEventRuntime, useFeatureBranchQueryString, useFilterBarContext, useHasAccessTo, useImageUploader, useIrisAppId, useIrisAppName, useModalDialogContext, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useUserSubscription };
|
|
845
|
+
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, fetchAssetBlobUrl, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomerRuntime, useEnvironment, useEventRuntime, useFeatureBranchQueryString, useFilterBarContext, useHasAccessTo, useImageUploader, useIrisAppId, useIrisAppImage, useIrisAppName, useModalDialogContext, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useUserSubscription };
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./environment/EnvironmentContextProvider";
|
|
|
5
5
|
export * from "./fetchAssetBlobUrl";
|
|
6
6
|
export * from "./filter-bar/FilterBarProvider";
|
|
7
7
|
export * from "./images/useImageUploader";
|
|
8
|
+
export * from "./images/useIrisAppImage";
|
|
8
9
|
export * from "./irisOemApp/IrisOemAppContextProvider";
|
|
9
10
|
export * from "./modalDialog/ModalDialogProvider";
|
|
10
11
|
export * from "./navigation/NavigationContextProvider";
|