@trackunit/react-core-contexts 0.1.3 → 0.3.1

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;
package/index.js CHANGED
@@ -3,13 +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, GlobalSelectionProvider, 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, GlobalSelectionRuntime, 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, useState, useEffect } from 'react';
10
+ import { useMemo, useState, useEffect, useCallback } from 'react';
11
11
  import { registerTranslations, initializeTranslationsForApp } from '@trackunit/i18n-library-translation';
12
12
  import { Spinner } from '@trackunit/react-components';
13
+ import { SortOrder } from '@trackunit/react-core-contexts-api';
13
14
  import { BrowserRouter } from 'react-router-dom';
14
15
 
15
16
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -2446,6 +2447,40 @@ for (var COLLECTION_NAME in DOMIterables) {
2446
2447
 
2447
2448
  handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
2448
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
+
2449
2484
  const TileEnvironmentProvider = ({
2450
2485
  children
2451
2486
  }) => {
@@ -2566,8 +2601,10 @@ const TrackunitDataProviders = ({
2566
2601
  children: jsx(TileCurrentUserProvider, {
2567
2602
  children: jsx(UserSubscriptionProvider, {
2568
2603
  children: jsx(TileGlobalSelectionProvider, {
2569
- children: jsx(ManagerApolloProvider, {
2570
- children: children
2604
+ children: jsx(TileAssetSortingProvider, {
2605
+ children: jsx(ManagerApolloProvider, {
2606
+ children: children
2607
+ })
2571
2608
  })
2572
2609
  })
2573
2610
  })
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts",
3
- "version": "0.1.3",
3
+ "version": "0.3.1",
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.1.2",
9
- "@trackunit/react-core-contexts-api": "0.1.1",
10
- "@trackunit/react-core-hooks": "0.1.2",
8
+ "@trackunit/iris-app-runtime-core": "0.2.0",
9
+ "@trackunit/react-core-contexts-api": "0.2.0",
10
+ "@trackunit/react-core-contexts-test": "0.1.1",
11
+ "@trackunit/react-core-hooks": "0.2.1",
11
12
  "react": "17.0.2",
12
- "@trackunit/react-core-contexts-test": "0.0.55",
13
13
  "@apollo/client": "3.6.9",
14
14
  "@sentry/browser": "^7.15.0",
15
15
  "apollo-upload-client": "^14.1.3",
16
16
  "@trackunit/i18n-library-translation": "0.0.6",
17
- "@trackunit/react-components": "0.0.187",
17
+ "@trackunit/react-components": "0.0.188",
18
18
  "react-router-dom": "6.4.1"
19
19
  },
20
20
  "module": "./index.js",