@teambit/lanes.hooks.use-lanes 0.0.38 → 0.0.39

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/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { LanesContext } from './lanes-context';
1
+ export { LanesContext, LanesContextModel, useLanesContext } from './lanes-context';
2
2
  export { LanesProvider } from './lanes-provider';
3
3
  export { useLanes } from './use-lanes';
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useLanes = exports.LanesProvider = exports.LanesContext = void 0;
3
+ exports.useLanes = exports.LanesProvider = exports.useLanesContext = exports.LanesContext = void 0;
4
4
  var lanes_context_1 = require("./lanes-context");
5
5
  Object.defineProperty(exports, "LanesContext", { enumerable: true, get: function () { return lanes_context_1.LanesContext; } });
6
+ Object.defineProperty(exports, "useLanesContext", { enumerable: true, get: function () { return lanes_context_1.useLanesContext; } });
6
7
  var lanes_provider_1 = require("./lanes-provider");
7
8
  Object.defineProperty(exports, "LanesProvider", { enumerable: true, get: function () { return lanes_provider_1.LanesProvider; } });
8
9
  var use_lanes_1 = require("./use-lanes");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AACrB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,iDAAmF;AAA1E,6GAAA,YAAY,OAAA;AAAqB,gHAAA,eAAe,OAAA;AACzD,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA"}
@@ -1,4 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { LanesModel } from '@teambit/lanes.ui.models';
3
- export declare const LanesContext: React.Context<LanesModel | undefined>;
4
- export declare const useLanesContext: () => LanesModel | undefined;
2
+ import { LaneId } from '@teambit/lane-id';
3
+ import { LanesModel } from '@teambit/lanes.ui.models.lanes-model';
4
+ export declare type LanesContextModel = {
5
+ lanesModel?: LanesModel;
6
+ updateLanesModel?: (updatedLanes?: LanesModel) => void;
7
+ updateViewedLane?: (viewedLaneId?: LaneId) => void;
8
+ };
9
+ export declare const LanesContext: React.Context<LanesContextModel | undefined>;
10
+ export declare const useLanesContext: () => LanesContextModel | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"lanes-context.js","sourceRoot":"","sources":["../lanes-context.ts"],"names":[],"mappings":";;;AAAA,iCAAkD;AAGrC,QAAA,YAAY,GAA0C,IAAA,qBAAa,EAAyB,SAAS,CAAC,CAAC;AAC7G,MAAM,eAAe,GAAiC,GAAG,EAAE;IAChE,MAAM,YAAY,GAAG,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;IAC9C,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAHW,QAAA,eAAe,mBAG1B"}
1
+ {"version":3,"file":"lanes-context.js","sourceRoot":"","sources":["../lanes-context.ts"],"names":[],"mappings":";;;AAEA,iCAAkD;AAQrC,QAAA,YAAY,GAAiD,IAAA,qBAAa,EACrF,SAAS,CACV,CAAC;AAEK,MAAM,eAAe,GAAwC,GAAG,EAAE;IACvE,MAAM,YAAY,GAAG,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;IAC9C,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAHW,QAAA,eAAe,mBAG1B"}
@@ -1,6 +1,9 @@
1
1
  import { ReactNode } from 'react';
2
+ import { LanesModel } from '@teambit/lanes.ui.models.lanes-model';
3
+ import { LaneId } from '@teambit/lane-id';
2
4
  export declare type LanesProviderProps = {
3
5
  children: ReactNode;
4
- viewedLaneId?: string;
6
+ viewedLaneId?: LaneId;
7
+ targetLanes?: LanesModel;
5
8
  };
6
- export declare function LanesProvider({ children, viewedLaneId }: LanesProviderProps): JSX.Element;
9
+ export declare function LanesProvider({ children, viewedLaneId, targetLanes }: LanesProviderProps): JSX.Element;
@@ -1,15 +1,69 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
4
20
  };
5
21
  Object.defineProperty(exports, "__esModule", { value: true });
6
22
  exports.LanesProvider = void 0;
7
- const react_1 = __importDefault(require("react"));
23
+ const react_1 = __importStar(require("react"));
8
24
  const lanes_hooks_use_lanes_1 = require("@teambit/lanes.hooks.use-lanes");
25
+ const lanes_ui_models_lanes_model_1 = require("@teambit/lanes.ui.models.lanes-model");
26
+ const ui_foundation_ui_react_router_use_query_1 = require("@teambit/ui-foundation.ui.react-router.use-query");
27
+ const base_react_navigation_link_1 = require("@teambit/base-react.navigation.link");
9
28
  const lanes_context_1 = require("./lanes-context");
10
- function LanesProvider({ children, viewedLaneId }) {
11
- const { lanesModel } = (0, lanes_hooks_use_lanes_1.useLanes)(() => viewedLaneId);
12
- return react_1.default.createElement(lanes_context_1.LanesContext.Provider, { value: lanesModel }, children);
29
+ function LanesProvider({ children, viewedLaneId, targetLanes }) {
30
+ const { lanesModel, loading } = (0, lanes_hooks_use_lanes_1.useLanes)(targetLanes);
31
+ const [lanesState, setLanesState] = (0, react_1.useState)(lanesModel);
32
+ const location = (0, base_react_navigation_link_1.useLocation)();
33
+ const query = (0, ui_foundation_ui_react_router_use_query_1.useQuery)();
34
+ (0, react_1.useEffect)(() => {
35
+ var _a, _b, _c;
36
+ const onHomeRoute = (location === null || location === void 0 ? void 0 : location.pathname) === '/';
37
+ const viewedLaneFromUrl = ((location === null || location === void 0 ? void 0 : location.pathname) && lanes_ui_models_lanes_model_1.LanesModel.getLaneIdFromPathname(location === null || location === void 0 ? void 0 : location.pathname, query)) || undefined;
38
+ const viewedLaneIdToSet = viewedLaneId ||
39
+ viewedLaneFromUrl ||
40
+ ((_a = lanesState === null || lanesState === void 0 ? void 0 : lanesState.viewedLane) === null || _a === void 0 ? void 0 : _a.id) ||
41
+ (onHomeRoute && ((_b = lanesModel === null || lanesModel === void 0 ? void 0 : lanesModel.currentLane) === null || _b === void 0 ? void 0 : _b.id)) ||
42
+ ((_c = lanesModel === null || lanesModel === void 0 ? void 0 : lanesModel.lanes.find((lane) => lane.id.isDefault())) === null || _c === void 0 ? void 0 : _c.id);
43
+ lanesModel === null || lanesModel === void 0 ? void 0 : lanesModel.setViewedLane(viewedLaneIdToSet);
44
+ setLanesState(lanesModel);
45
+ }, [loading, location === null || location === void 0 ? void 0 : location.pathname, targetLanes]);
46
+ const updateLanesModel = (updatedLanes) => {
47
+ setLanesState(new lanes_ui_models_lanes_model_1.LanesModel({
48
+ lanes: updatedLanes === null || updatedLanes === void 0 ? void 0 : updatedLanes.lanes,
49
+ viewedLane: updatedLanes === null || updatedLanes === void 0 ? void 0 : updatedLanes.viewedLane,
50
+ currentLane: updatedLanes === null || updatedLanes === void 0 ? void 0 : updatedLanes.currentLane,
51
+ }));
52
+ };
53
+ const updateViewedLane = (_viewedLaneId) => {
54
+ lanesState === null || lanesState === void 0 ? void 0 : lanesState.setViewedLane(_viewedLaneId);
55
+ setLanesState(new lanes_ui_models_lanes_model_1.LanesModel({
56
+ lanes: lanesState === null || lanesState === void 0 ? void 0 : lanesState.lanes,
57
+ viewedLane: lanesState === null || lanesState === void 0 ? void 0 : lanesState.viewedLane,
58
+ currentLane: lanesState === null || lanesState === void 0 ? void 0 : lanesState.currentLane,
59
+ }));
60
+ };
61
+ const lanesContextModel = {
62
+ lanesModel: lanesState,
63
+ updateLanesModel,
64
+ updateViewedLane,
65
+ };
66
+ return react_1.default.createElement(lanes_context_1.LanesContext.Provider, { value: lanesContextModel }, children);
13
67
  }
14
68
  exports.LanesProvider = LanesProvider;
15
69
  //# sourceMappingURL=lanes-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lanes-provider.js","sourceRoot":"","sources":["../lanes-provider.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AACzC,0EAA0D;AAC1D,mDAA+C;AAO/C,SAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAsB;IAC1E,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,gCAAQ,EAAC,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC;IACpD,OAAO,8BAAC,4BAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,UAAU,IAAG,QAAQ,CAAyB,CAAC;AACtF,CAAC;AAHD,sCAGC"}
1
+ {"version":3,"file":"lanes-provider.js","sourceRoot":"","sources":["../lanes-provider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA8D;AAC9D,0EAA0D;AAC1D,sFAAkE;AAClE,8GAA4E;AAC5E,oFAAkE;AAElE,mDAAkE;AAQlE,SAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAsB;IACvF,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAQ,EAAC,WAAW,CAAC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CACX,IAAI,wCAAU,CAAC;YACb,KAAK,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK;YAC1B,UAAU,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,UAAU;YACpC,WAAW,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,WAAW;SACvC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,CAAC,aAAsB,EAAE,EAAE;QAClD,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,aAAa,CAAC,aAAa,CAAC,CAAC;QACzC,aAAa,CACX,IAAI,wCAAU,CAAC;YACb,KAAK,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK;YACxB,UAAU,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,UAAU;YAClC,WAAW,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW;SACrC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAsB;QAC3C,UAAU,EAAE,UAAU;QACtB,gBAAgB;QAChB,gBAAgB;KACjB,CAAC;IAEF,OAAO,8BAAC,4BAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,iBAAiB,IAAG,QAAQ,CAAyB,CAAC;AAC7F,CAAC;AAjDD,sCAiDC"}
@@ -1,5 +1,8 @@
1
- import { LanesModel, LanesQuery } from '@teambit/lanes.ui.models';
1
+ import { LanesModel, LanesQuery } from '@teambit/lanes.ui.models.lanes-model';
2
2
  import { QueryResult } from '@apollo/client';
3
- export declare function useLanes(getViewedLaneId?: () => string | undefined): {
4
- lanesModel?: LanesModel;
5
- } & Omit<QueryResult<LanesQuery>, 'data'>;
3
+ import { LanesContextModel } from './lanes-context';
4
+ export declare function useLanes(targetLanes?: LanesModel): LanesContextModel & Omit<QueryResult<LanesQuery & {
5
+ getHost: {
6
+ id: string;
7
+ };
8
+ }>, 'data'>;
package/dist/use-lanes.js CHANGED
@@ -12,10 +12,8 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.useLanes = void 0;
15
- const scope_ui_hooks_use_scope_1 = require("@teambit/scope.ui.hooks.use-scope");
16
- const react_1 = require("react");
17
15
  const ui_foundation_ui_hooks_use_data_query_1 = require("@teambit/ui-foundation.ui.hooks.use-data-query");
18
- const lanes_ui_models_1 = require("@teambit/lanes.ui.models");
16
+ const lanes_ui_models_lanes_model_1 = require("@teambit/lanes.ui.models.lanes-model");
19
17
  const client_1 = require("@apollo/client");
20
18
  const lanes_context_1 = require("./lanes-context");
21
19
  const GET_LANES = (0, client_1.gql) `
@@ -23,9 +21,11 @@ const GET_LANES = (0, client_1.gql) `
23
21
  lanes {
24
22
  id
25
23
  list {
26
- id
27
- remote
28
- isMerged
24
+ id {
25
+ name
26
+ scope
27
+ }
28
+ hash
29
29
  readmeComponent {
30
30
  id {
31
31
  name
@@ -42,7 +42,10 @@ const GET_LANES = (0, client_1.gql) `
42
42
  }
43
43
  }
44
44
  current {
45
- id
45
+ id {
46
+ name
47
+ scope
48
+ }
46
49
  }
47
50
  }
48
51
  getHost(id: $extensionId) {
@@ -50,24 +53,20 @@ const GET_LANES = (0, client_1.gql) `
50
53
  }
51
54
  }
52
55
  `;
53
- function useLanes(getViewedLaneId) {
56
+ function useLanes(targetLanes) {
54
57
  var _a;
55
58
  const lanesContext = (0, lanes_context_1.useLanesContext)();
56
- const skip = !!lanesContext;
57
- const _b = (0, ui_foundation_ui_hooks_use_data_query_1.useDataQuery)(GET_LANES, { skip }), { data } = _b, rest = __rest(_b, ["data"]);
58
- const { scope, loading } = (0, scope_ui_hooks_use_scope_1.useScopeQuery)(skip);
59
+ const shouldSkip = !!targetLanes || !!lanesContext;
60
+ const _b = (0, ui_foundation_ui_hooks_use_data_query_1.useDataQuery)(GET_LANES, {
61
+ skip: shouldSkip,
62
+ }), { data, loading } = _b, rest = __rest(_b, ["data", "loading"]);
59
63
  let lanesModel;
60
64
  if (lanesContext)
61
- lanesModel = lanesContext;
65
+ lanesModel = lanesContext.lanesModel;
62
66
  else
63
- lanesModel = data && lanes_ui_models_1.LanesModel.from({ data, host: (_a = data === null || data === void 0 ? void 0 : data.getHost) === null || _a === void 0 ? void 0 : _a.id, scope, viewedLaneId: getViewedLaneId === null || getViewedLaneId === void 0 ? void 0 : getViewedLaneId() });
64
- (0, react_1.useEffect)(() => {
65
- if (getViewedLaneId) {
66
- const viewedLaneId = getViewedLaneId();
67
- lanesModel === null || lanesModel === void 0 ? void 0 : lanesModel.setViewedLane(viewedLaneId);
68
- }
69
- }, [lanesModel, getViewedLaneId]);
70
- return Object.assign(Object.assign({}, rest), { loading: rest.loading || !!loading, lanesModel });
67
+ lanesModel = (data && lanes_ui_models_lanes_model_1.LanesModel.from({ data, host: (_a = data === null || data === void 0 ? void 0 : data.getHost) === null || _a === void 0 ? void 0 : _a.id })) || targetLanes;
68
+ return Object.assign(Object.assign(Object.assign({}, rest), (lanesContext || {})), { loading,
69
+ lanesModel });
71
70
  }
72
71
  exports.useLanes = useLanes;
73
72
  //# sourceMappingURL=use-lanes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-lanes.js","sourceRoot":"","sources":["../use-lanes.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gFAAkE;AAClE,iCAAkC;AAClC,0GAA8E;AAC9E,8DAAkE;AAClE,2CAAkD;AAClD,mDAAkD;AAElD,MAAM,SAAS,GAAG,IAAA,YAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BpB,CAAC;AAEF,SAAgB,QAAQ,CACtB,eAA0C;;IAE1C,MAAM,YAAY,GAAG,IAAA,+BAAe,GAAE,CAAC;IACvC,MAAM,IAAI,GAAG,CAAC,CAAC,YAAY,CAAC;IAE5B,MAAM,KAAoB,IAAA,oDAAY,EAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,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IAEnD,MAAM,KAA6B,IAAA,oDAAY,EAA2C,SAAS,EAAE;QACnG,IAAI,EAAE,UAAU;KACjB,CAAC,EAFI,EAAE,IAAI,EAAE,OAAO,OAEnB,EAFwB,IAAI,cAAxB,mBAA0B,CAE9B,CAAC;IAEH,IAAI,UAAkC,CAAC;IACvC,IAAI,YAAY;QAAE,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;;QAClD,UAAU,GAAG,CAAC,IAAI,IAAI,wCAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,0CAAE,EAAE,EAAE,CAAC,CAAC,IAAI,WAAW,CAAC;IAE9F,qDACK,IAAI,GACJ,CAAC,YAAY,IAAI,EAAE,CAAC,KACvB,OAAO;QACP,UAAU,IACV;AACJ,CAAC;AApBD,4BAoBC"}
package/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { LanesContext } from './lanes-context';
1
+ export { LanesContext, LanesContextModel, useLanesContext } from './lanes-context';
2
2
  export { LanesProvider } from './lanes-provider';
3
3
  export { useLanes } from './use-lanes';
package/lanes-context.ts CHANGED
@@ -1,8 +1,18 @@
1
+ import { LaneId } from '@teambit/lane-id';
2
+ import { LanesModel } from '@teambit/lanes.ui.models.lanes-model';
1
3
  import { createContext, useContext } from 'react';
2
- import { LanesModel } from '@teambit/lanes.ui.models';
3
4
 
4
- export const LanesContext: React.Context<LanesModel | undefined> = createContext<LanesModel | undefined>(undefined);
5
- export const useLanesContext: () => LanesModel | undefined = () => {
5
+ export type LanesContextModel = {
6
+ lanesModel?: LanesModel;
7
+ updateLanesModel?: (updatedLanes?: LanesModel) => void;
8
+ updateViewedLane?: (viewedLaneId?: LaneId) => void;
9
+ };
10
+
11
+ export const LanesContext: React.Context<LanesContextModel | undefined> = createContext<LanesContextModel | undefined>(
12
+ undefined
13
+ );
14
+
15
+ export const useLanesContext: () => LanesContextModel | undefined = () => {
6
16
  const lanesContext = useContext(LanesContext);
7
17
  return lanesContext;
8
18
  };
@@ -1,13 +1,64 @@
1
- import React, { ReactNode } from 'react';
1
+ import React, { ReactNode, useState, useEffect } from 'react';
2
2
  import { useLanes } from '@teambit/lanes.hooks.use-lanes';
3
- import { LanesContext } from './lanes-context';
3
+ import { LanesModel } from '@teambit/lanes.ui.models.lanes-model';
4
+ import { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';
5
+ import { useLocation } from '@teambit/base-react.navigation.link';
6
+ import { LaneId } from '@teambit/lane-id';
7
+ import { LanesContext, LanesContextModel } from './lanes-context';
4
8
 
5
9
  export type LanesProviderProps = {
6
10
  children: ReactNode;
7
- viewedLaneId?: string;
11
+ viewedLaneId?: LaneId;
12
+ targetLanes?: LanesModel;
8
13
  };
9
14
 
10
- export function LanesProvider({ children, viewedLaneId }: LanesProviderProps) {
11
- const { lanesModel } = useLanes(() => viewedLaneId);
12
- return <LanesContext.Provider value={lanesModel}>{children}</LanesContext.Provider>;
15
+ export function LanesProvider({ children, viewedLaneId, targetLanes }: LanesProviderProps) {
16
+ const { lanesModel, loading } = useLanes(targetLanes);
17
+ const [lanesState, setLanesState] = useState<LanesModel | undefined>(lanesModel);
18
+ const location = useLocation();
19
+ const query = useQuery();
20
+
21
+ useEffect(() => {
22
+ const onHomeRoute = location?.pathname === '/';
23
+ const viewedLaneFromUrl =
24
+ (location?.pathname && LanesModel.getLaneIdFromPathname(location?.pathname, query)) || undefined;
25
+ const viewedLaneIdToSet =
26
+ viewedLaneId ||
27
+ viewedLaneFromUrl ||
28
+ lanesState?.viewedLane?.id ||
29
+ (onHomeRoute && lanesModel?.currentLane?.id) ||
30
+ lanesModel?.lanes.find((lane) => lane.id.isDefault())?.id;
31
+
32
+ lanesModel?.setViewedLane(viewedLaneIdToSet);
33
+ setLanesState(lanesModel);
34
+ }, [loading, location?.pathname, targetLanes]);
35
+
36
+ const updateLanesModel = (updatedLanes?: LanesModel) => {
37
+ setLanesState(
38
+ new LanesModel({
39
+ lanes: updatedLanes?.lanes,
40
+ viewedLane: updatedLanes?.viewedLane,
41
+ currentLane: updatedLanes?.currentLane,
42
+ })
43
+ );
44
+ };
45
+
46
+ const updateViewedLane = (_viewedLaneId?: LaneId) => {
47
+ lanesState?.setViewedLane(_viewedLaneId);
48
+ setLanesState(
49
+ new LanesModel({
50
+ lanes: lanesState?.lanes,
51
+ viewedLane: lanesState?.viewedLane,
52
+ currentLane: lanesState?.currentLane,
53
+ })
54
+ );
55
+ };
56
+
57
+ const lanesContextModel: LanesContextModel = {
58
+ lanesModel: lanesState,
59
+ updateLanesModel,
60
+ updateViewedLane,
61
+ };
62
+
63
+ return <LanesContext.Provider value={lanesContextModel}>{children}</LanesContext.Provider>;
13
64
  }
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@teambit/lanes.hooks.use-lanes",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "homepage": "https://bit.dev/teambit/lanes/hooks/use-lanes",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.lanes",
8
8
  "name": "hooks/use-lanes",
9
- "version": "0.0.38"
9
+ "version": "0.0.39"
10
10
  },
11
11
  "dependencies": {
12
12
  "core-js": "^3.0.0",
13
- "@teambit/lanes.ui.models": "0.0.36",
14
- "@teambit/scope.ui.hooks.use-scope": "0.0.240",
13
+ "@teambit/base-react.navigation.link": "2.0.27",
14
+ "@teambit/lane-id": "0.0.97",
15
+ "@teambit/lanes.ui.models.lanes-model": "0.0.1",
16
+ "@teambit/ui-foundation.ui.react-router.use-query": "0.0.493",
15
17
  "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.496"
16
18
  },
17
19
  "devDependencies": {
package/use-lanes.tsx CHANGED
@@ -1,18 +1,18 @@
1
- import { useScopeQuery } from '@teambit/scope.ui.hooks.use-scope';
2
- import { useEffect } from 'react';
3
1
  import { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';
4
- import { LanesModel, LanesQuery } from '@teambit/lanes.ui.models';
2
+ import { LanesModel, LanesQuery } from '@teambit/lanes.ui.models.lanes-model';
5
3
  import { gql, QueryResult } from '@apollo/client';
6
- import { useLanesContext } from './lanes-context';
4
+ import { LanesContextModel, useLanesContext } from './lanes-context';
7
5
 
8
6
  const GET_LANES = gql`
9
7
  query Lanes($extensionId: String) {
10
8
  lanes {
11
9
  id
12
10
  list {
13
- id
14
- remote
15
- isMerged
11
+ id {
12
+ name
13
+ scope
14
+ }
15
+ hash
16
16
  readmeComponent {
17
17
  id {
18
18
  name
@@ -29,7 +29,10 @@ const GET_LANES = gql`
29
29
  }
30
30
  }
31
31
  current {
32
- id
32
+ id {
33
+ name
34
+ scope
35
+ }
33
36
  }
34
37
  }
35
38
  getHost(id: $extensionId) {
@@ -39,29 +42,23 @@ const GET_LANES = gql`
39
42
  `;
40
43
 
41
44
  export function useLanes(
42
- getViewedLaneId?: () => string | undefined
43
- ): { lanesModel?: LanesModel } & Omit<QueryResult<LanesQuery>, 'data'> {
45
+ targetLanes?: LanesModel
46
+ ): LanesContextModel & Omit<QueryResult<LanesQuery & { getHost: { id: string } }>, 'data'> {
44
47
  const lanesContext = useLanesContext();
45
- const skip = !!lanesContext;
48
+ const shouldSkip = !!targetLanes || !!lanesContext;
46
49
 
47
- const { data, ...rest } = useDataQuery(GET_LANES, { skip });
48
- const { scope, loading } = useScopeQuery(skip);
50
+ const { data, loading, ...rest } = useDataQuery<LanesQuery & { getHost: { id: string } }>(GET_LANES, {
51
+ skip: shouldSkip,
52
+ });
49
53
 
50
- let lanesModel: LanesModel;
51
- if (lanesContext) lanesModel = lanesContext;
52
- else
53
- lanesModel = data && LanesModel.from({ data, host: data?.getHost?.id, scope, viewedLaneId: getViewedLaneId?.() });
54
-
55
- useEffect(() => {
56
- if (getViewedLaneId) {
57
- const viewedLaneId = getViewedLaneId();
58
- lanesModel?.setViewedLane(viewedLaneId);
59
- }
60
- }, [lanesModel, getViewedLaneId]);
54
+ let lanesModel: LanesModel | undefined;
55
+ if (lanesContext) lanesModel = lanesContext.lanesModel;
56
+ else lanesModel = (data && LanesModel.from({ data, host: data?.getHost?.id })) || targetLanes;
61
57
 
62
58
  return {
63
59
  ...rest,
64
- loading: rest.loading || !!loading,
60
+ ...(lanesContext || {}),
61
+ loading,
65
62
  lanesModel,
66
63
  };
67
64
  }