@trackunit/react-core-contexts 0.0.1-alpha-5a781097d3.0 → 0.0.1-alpha-a2aba2c20d.0

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.
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from "react";
2
+ interface Props {
3
+ children: ReactNode;
4
+ }
5
+ declare const TileAssetSortingProvider: ({ children }: Props) => JSX.Element | null;
6
+ export default TileAssetSortingProvider;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ interface IProps {
3
+ children: React.ReactNode;
4
+ }
5
+ declare const TileGlobalSelectionProvider: ({ children }: IProps) => JSX.Element | null;
6
+ export default TileGlobalSelectionProvider;
package/index.js CHANGED
@@ -3,12 +3,14 @@ import { ApolloClient, InMemoryCache, from, split as split$1, ApolloProvider } f
3
3
  import { setContext } from '@apollo/client/link/context';
4
4
  import { onError } from '@apollo/client/link/error';
5
5
  import * as Sentry from '@sentry/browser';
6
- import { useEnvironment, useToken, ToastProvider, EnvironmentContextProvider, TokenProvider, CurrentUserProvider, UserSubscriptionProvider as UserSubscriptionProvider$1, useURLSynchronization } from '@trackunit/react-core-hooks';
6
+ import { useEnvironment, useToken, ToastProvider, AssetSortingProvider, EnvironmentContextProvider, GlobalSelectionProvider, TokenProvider, CurrentUserProvider, UserSubscriptionProvider as UserSubscriptionProvider$1, useURLSynchronization } from '@trackunit/react-core-hooks';
7
7
  import { createUploadLink } from 'apollo-upload-client';
8
- import { ToastRuntime, EnvironmentRuntime, TokenRuntime, CurrentUserRuntime, UserSubscriptionRuntime } from '@trackunit/iris-app-runtime-core';
8
+ import { ToastRuntime, AssetSortingRuntime, EnvironmentRuntime, GlobalSelectionRuntime, TokenRuntime, CurrentUserRuntime, UserSubscriptionRuntime } from '@trackunit/iris-app-runtime-core';
9
9
  import * as React from 'react';
10
- import { useMemo } from 'react';
10
+ import { useMemo, useState, useEffect, useCallback } from 'react';
11
11
  import { registerTranslations, initializeTranslationsForApp } from '@trackunit/i18n-library-translation';
12
+ import { Spinner } from '@trackunit/react-components';
13
+ import { SortOrder } from '@trackunit/react-core-contexts-api';
12
14
  import { BrowserRouter } from 'react-router-dom';
13
15
 
14
16
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -2445,6 +2447,40 @@ for (var COLLECTION_NAME in DOMIterables) {
2445
2447
 
2446
2448
  handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
2447
2449
 
2450
+ const TileAssetSortingProvider = ({
2451
+ children
2452
+ }) => {
2453
+ const [assetSortingState, setAssetSortingState] = useState(null);
2454
+ useEffect(() => {
2455
+ AssetSortingRuntime.getAssetSortingState().catch(() => null).then(setAssetSortingState);
2456
+ }, []);
2457
+ const setSortingState = useCallback((...args) => {
2458
+ // TODO when we can trigger a reload of the state from the host, remove this logic that updates the local state
2459
+ AssetSortingRuntime.setAssetSortingState(...args).then(() => {
2460
+ var _a;
2461
+
2462
+ setAssetSortingState({
2463
+ sortBy: args[0],
2464
+ order: (_a = args[1]) !== null && _a !== void 0 ? _a : SortOrder.Desc
2465
+ });
2466
+ });
2467
+ }, []);
2468
+ const contextValue = useMemo(() => ({
2469
+ sortingState: assetSortingState,
2470
+ setSortBy: setSortingState
2471
+ }), [assetSortingState, setSortingState]);
2472
+
2473
+ if (!assetSortingState) {
2474
+ return null;
2475
+ }
2476
+
2477
+ return jsx(AssetSortingProvider, Object.assign({
2478
+ value: contextValue
2479
+ }, {
2480
+ children: children
2481
+ }));
2482
+ };
2483
+
2448
2484
  const TileEnvironmentProvider = ({
2449
2485
  children
2450
2486
  }) => {
@@ -2474,6 +2510,25 @@ const TileEnvironmentProvider = ({
2474
2510
  }));
2475
2511
  };
2476
2512
 
2513
+ const TileGlobalSelectionProvider = ({
2514
+ children
2515
+ }) => {
2516
+ const [GlobalSelectionContext, setGlobalSelectionContext] = useState(null);
2517
+ useEffect(() => {
2518
+ GlobalSelectionRuntime.getGlobalSelection().catch(() => null).then(setGlobalSelectionContext);
2519
+ }, []);
2520
+
2521
+ if (!GlobalSelectionContext) {
2522
+ return null;
2523
+ }
2524
+
2525
+ return jsx(GlobalSelectionProvider, Object.assign({
2526
+ value: GlobalSelectionContext
2527
+ }, {
2528
+ children: children
2529
+ }));
2530
+ };
2531
+
2477
2532
  const TileTokenProvider = ({
2478
2533
  children
2479
2534
  }) => {
@@ -2545,8 +2600,12 @@ const TrackunitDataProviders = ({
2545
2600
  children: jsx(TileTokenProvider, {
2546
2601
  children: jsx(TileCurrentUserProvider, {
2547
2602
  children: jsx(UserSubscriptionProvider, {
2548
- children: jsx(ManagerApolloProvider, {
2549
- children: children
2603
+ children: jsx(TileGlobalSelectionProvider, {
2604
+ children: jsx(TileAssetSortingProvider, {
2605
+ children: jsx(ManagerApolloProvider, {
2606
+ children: children
2607
+ })
2608
+ })
2550
2609
  })
2551
2610
  })
2552
2611
  })
@@ -2592,9 +2651,15 @@ const TrackunitProviders = ({
2592
2651
 
2593
2652
  return jsx(TrackunitDataProviders, {
2594
2653
  children: jsx(ToastProviderApp, {
2595
- children: jsx(TrackunitRouter, {
2596
- children: children
2597
- })
2654
+ children: jsx(React.Suspense, Object.assign({
2655
+ fallback: jsx(Spinner, {
2656
+ centered: true
2657
+ })
2658
+ }, {
2659
+ children: jsx(TrackunitRouter, {
2660
+ children: children
2661
+ })
2662
+ }))
2598
2663
  })
2599
2664
  });
2600
2665
  };
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts",
3
- "version": "0.0.1-alpha-5a781097d3.0",
3
+ "version": "0.0.1-alpha-a2aba2c20d.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
7
7
  "graphql": "^15.8.0",
8
- "@trackunit/iris-app-runtime-core": "0.0.1-alpha-5a781097d3.0",
9
- "@trackunit/react-core-contexts-api": "0.0.1-alpha-5a781097d3.0",
10
- "@trackunit/react-core-hooks": "0.0.1-alpha-5a781097d3.0",
8
+ "@trackunit/iris-app-runtime-core": "0.0.1-alpha-a2aba2c20d.0",
9
+ "@trackunit/react-core-contexts-api": "0.0.1-alpha-a2aba2c20d.0",
10
+ "@trackunit/react-core-contexts-test": "0.0.1-alpha-a2aba2c20d.0",
11
+ "@trackunit/react-core-hooks": "0.0.1-alpha-a2aba2c20d.0",
11
12
  "react": "17.0.2",
12
- "@trackunit/react-core-contexts-test": "0.0.1-alpha-5a781097d3.0",
13
13
  "@apollo/client": "3.6.9",
14
14
  "@sentry/browser": "^7.15.0",
15
15
  "apollo-upload-client": "^14.1.3",
16
- "@trackunit/i18n-library-translation": "0.0.1-alpha-5a781097d3.0",
16
+ "@trackunit/i18n-library-translation": "0.0.1-alpha-a2aba2c20d.0",
17
+ "@trackunit/react-components": "0.0.1-alpha-a2aba2c20d.0",
17
18
  "react-router-dom": "6.4.1"
18
19
  },
19
20
  "module": "./index.js",