@teambit/component 0.0.1079 → 0.0.1081
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/component.ui.runtime.tsx +19 -9
- package/dist/component.graphql.d.ts +4 -1
- package/dist/component.graphql.js +4 -1
- package/dist/component.graphql.js.map +1 -1
- package/dist/component.ui.runtime.js +17 -9
- package/dist/component.ui.runtime.js.map +1 -1
- package/dist/get-component-opts.d.ts +1 -2
- package/dist/get-component-opts.js.map +1 -1
- package/dist/{preview-1686886045563.js → preview-1687058340034.js} +2 -2
- package/dist/ui/component.d.ts +1 -2
- package/dist/ui/component.js +24 -9
- package/dist/ui/component.js.map +1 -1
- package/dist/ui/index.d.ts +5 -2
- package/dist/ui/index.js +59 -9
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/menu/index.d.ts +1 -1
- package/dist/ui/menu/index.js.map +1 -1
- package/dist/ui/menu/menu.d.ts +47 -8
- package/dist/ui/menu/menu.js +172 -84
- package/dist/ui/menu/menu.js.map +1 -1
- package/dist/ui/menu/nav-plugin.d.ts +12 -3
- package/dist/ui/menu/nav-plugin.js.map +1 -1
- package/dist/ui/use-component-logs.d.ts +16 -0
- package/dist/ui/use-component-logs.js +93 -0
- package/dist/ui/use-component-logs.js.map +1 -0
- package/dist/ui/use-component-query.d.ts +2 -86
- package/dist/ui/use-component-query.js +62 -188
- package/dist/ui/use-component-query.js.map +1 -1
- package/dist/ui/use-component.d.ts +3 -18
- package/dist/ui/use-component.fragments.d.ts +10 -0
- package/dist/ui/use-component.fragments.js +183 -0
- package/dist/ui/use-component.fragments.js.map +1 -0
- package/dist/ui/use-component.js +19 -0
- package/dist/ui/use-component.js.map +1 -1
- package/dist/ui/use-component.model.d.ts +40 -0
- package/dist/ui/use-component.model.js +3 -0
- package/dist/ui/use-component.model.js.map +1 -0
- package/dist/ui/use-component.utils.d.ts +1 -0
- package/dist/ui/use-component.utils.js +17 -0
- package/dist/ui/use-component.utils.js.map +1 -0
- package/package-tar/teambit-component-0.0.1081.tgz +0 -0
- package/package.json +18 -19
- package/ui/component.tsx +11 -5
- package/ui/index.ts +21 -2
- package/ui/menu/index.ts +7 -1
- package/ui/menu/menu.tsx +196 -68
- package/ui/menu/nav-plugin.tsx +14 -6
- package/ui/use-component-logs.ts +65 -0
- package/ui/use-component-query.ts +57 -160
- package/ui/use-component.fragments.ts +169 -0
- package/ui/use-component.model.ts +45 -0
- package/ui/use-component.tsx +4 -19
- package/ui/use-component.utils.ts +9 -0
- package/package-tar/teambit-component-0.0.1079.tgz +0 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.array.sort.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useComponentLogs = useComponentLogs;
|
|
8
|
+
exports.useComponentLogsInit = useComponentLogsInit;
|
|
9
|
+
function _uiFoundationUiHooks() {
|
|
10
|
+
const data = require("@teambit/ui-foundation.ui.hooks.use-data-query");
|
|
11
|
+
_uiFoundationUiHooks = function () {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
function _useComponent() {
|
|
17
|
+
const data = require("./use-component.fragments");
|
|
18
|
+
_useComponent = function () {
|
|
19
|
+
return data;
|
|
20
|
+
};
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
function _componentError() {
|
|
24
|
+
const data = require("./component-error");
|
|
25
|
+
_componentError = function () {
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
function _useComponent2() {
|
|
31
|
+
const data = require("./use-component.utils");
|
|
32
|
+
_useComponent2 = function () {
|
|
33
|
+
return data;
|
|
34
|
+
};
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
function useComponentLogs(componentId, host, filters, skipFromProps) {
|
|
38
|
+
var _data$getHost;
|
|
39
|
+
const {
|
|
40
|
+
variables,
|
|
41
|
+
skip
|
|
42
|
+
} = useComponentLogsInit(componentId, host, filters, skipFromProps);
|
|
43
|
+
const {
|
|
44
|
+
data,
|
|
45
|
+
error,
|
|
46
|
+
loading
|
|
47
|
+
} = (0, _uiFoundationUiHooks().useDataQuery)(_useComponent().GET_COMPONENT_WITH_LOGS, {
|
|
48
|
+
variables,
|
|
49
|
+
skip,
|
|
50
|
+
errorPolicy: 'all'
|
|
51
|
+
});
|
|
52
|
+
const rawComponent = data === null || data === void 0 ? void 0 : (_data$getHost = data.getHost) === null || _data$getHost === void 0 ? void 0 : _data$getHost.get;
|
|
53
|
+
const rawCompLogs = rawComponent === null || rawComponent === void 0 ? void 0 : rawComponent.logs;
|
|
54
|
+
const componentError = error && !data ? new (_componentError().ComponentError)(500, error.message) : !rawComponent && !loading && new (_componentError().ComponentError)(404) || undefined;
|
|
55
|
+
return {
|
|
56
|
+
loading,
|
|
57
|
+
error: componentError,
|
|
58
|
+
componentLogs: {
|
|
59
|
+
logs: rawCompLogs,
|
|
60
|
+
loading
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function useComponentLogsInit(componentId, host, filters, skip) {
|
|
65
|
+
const {
|
|
66
|
+
log
|
|
67
|
+
} = filters || {};
|
|
68
|
+
const {
|
|
69
|
+
head: logHead,
|
|
70
|
+
offset: logOffset,
|
|
71
|
+
sort: logSort,
|
|
72
|
+
limit: logLimit,
|
|
73
|
+
type: logType,
|
|
74
|
+
takeHeadFromComponent: logTakeHeadFromComponent
|
|
75
|
+
} = log || {};
|
|
76
|
+
const variables = {
|
|
77
|
+
id: componentId,
|
|
78
|
+
extensionId: host,
|
|
79
|
+
logOffset: (0, _useComponent2().getOffsetValue)(logOffset, logLimit),
|
|
80
|
+
logLimit,
|
|
81
|
+
logType,
|
|
82
|
+
logHead,
|
|
83
|
+
logSort,
|
|
84
|
+
logTakeHeadFromComponent
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
logOffset,
|
|
88
|
+
variables,
|
|
89
|
+
skip
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=use-component-logs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useComponentLogs","componentId","host","filters","skipFromProps","variables","skip","useComponentLogsInit","data","error","loading","useDataQuery","GET_COMPONENT_WITH_LOGS","errorPolicy","rawComponent","getHost","get","rawCompLogs","logs","componentError","ComponentError","message","undefined","componentLogs","log","head","logHead","offset","logOffset","sort","logSort","limit","logLimit","type","logType","takeHeadFromComponent","logTakeHeadFromComponent","id","extensionId","getOffsetValue"],"sources":["use-component-logs.ts"],"sourcesContent":["import { LegacyComponentLog } from '@teambit/legacy-component-log';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentLogsResult, Filters } from './use-component.model';\nimport { GET_COMPONENT_WITH_LOGS } from './use-component.fragments';\nimport { ComponentError } from './component-error';\nimport { getOffsetValue } from './use-component.utils';\n\nexport function useComponentLogs(\n componentId: string,\n host: string,\n filters?: Filters,\n skipFromProps?: boolean\n): ComponentLogsResult {\n const { variables, skip } = useComponentLogsInit(componentId, host, filters, skipFromProps);\n\n const { data, error, loading } = useDataQuery(GET_COMPONENT_WITH_LOGS, {\n variables,\n skip,\n errorPolicy: 'all',\n });\n\n const rawComponent = data?.getHost?.get;\n const rawCompLogs: Array<LegacyComponentLog> = rawComponent?.logs;\n\n const componentError =\n error && !data\n ? new ComponentError(500, error.message)\n : (!rawComponent && !loading && new ComponentError(404)) || undefined;\n\n return {\n loading,\n error: componentError,\n componentLogs: {\n logs: rawCompLogs,\n loading,\n },\n };\n}\n\nexport function useComponentLogsInit(componentId: string, host: string, filters?: Filters, skip?: boolean) {\n const { log } = filters || {};\n const {\n head: logHead,\n offset: logOffset,\n sort: logSort,\n limit: logLimit,\n type: logType,\n takeHeadFromComponent: logTakeHeadFromComponent,\n } = log || {};\n const variables = {\n id: componentId,\n extensionId: host,\n logOffset: getOffsetValue(logOffset, logLimit),\n logLimit,\n logType,\n logHead,\n logSort,\n logTakeHeadFromComponent,\n };\n return {\n logOffset,\n variables,\n skip,\n };\n}\n"],"mappings":";;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,SAASA,gBAAgB,CAC9BC,WAAmB,EACnBC,IAAY,EACZC,OAAiB,EACjBC,aAAuB,EACF;EAAA;EACrB,MAAM;IAAEC,SAAS;IAAEC;EAAK,CAAC,GAAGC,oBAAoB,CAACN,WAAW,EAAEC,IAAI,EAAEC,OAAO,EAAEC,aAAa,CAAC;EAE3F,MAAM;IAAEI,IAAI;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAAC,mCAAY,EAACC,uCAAuB,EAAE;IACrEP,SAAS;IACTC,IAAI;IACJO,WAAW,EAAE;EACf,CAAC,CAAC;EAEF,MAAMC,YAAY,GAAGN,IAAI,aAAJA,IAAI,wCAAJA,IAAI,CAAEO,OAAO,kDAAb,cAAeC,GAAG;EACvC,MAAMC,WAAsC,GAAGH,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAEI,IAAI;EAEjE,MAAMC,cAAc,GAClBV,KAAK,IAAI,CAACD,IAAI,GACV,KAAIY,gCAAc,EAAC,GAAG,EAAEX,KAAK,CAACY,OAAO,CAAC,GACrC,CAACP,YAAY,IAAI,CAACJ,OAAO,IAAI,KAAIU,gCAAc,EAAC,GAAG,CAAC,IAAKE,SAAS;EAEzE,OAAO;IACLZ,OAAO;IACPD,KAAK,EAAEU,cAAc;IACrBI,aAAa,EAAE;MACbL,IAAI,EAAED,WAAW;MACjBP;IACF;EACF,CAAC;AACH;AAEO,SAASH,oBAAoB,CAACN,WAAmB,EAAEC,IAAY,EAAEC,OAAiB,EAAEG,IAAc,EAAE;EACzG,MAAM;IAAEkB;EAAI,CAAC,GAAGrB,OAAO,IAAI,CAAC,CAAC;EAC7B,MAAM;IACJsB,IAAI,EAAEC,OAAO;IACbC,MAAM,EAAEC,SAAS;IACjBC,IAAI,EAAEC,OAAO;IACbC,KAAK,EAAEC,QAAQ;IACfC,IAAI,EAAEC,OAAO;IACbC,qBAAqB,EAAEC;EACzB,CAAC,GAAGZ,GAAG,IAAI,CAAC,CAAC;EACb,MAAMnB,SAAS,GAAG;IAChBgC,EAAE,EAAEpC,WAAW;IACfqC,WAAW,EAAEpC,IAAI;IACjB0B,SAAS,EAAE,IAAAW,+BAAc,EAACX,SAAS,EAAEI,QAAQ,CAAC;IAC9CA,QAAQ;IACRE,OAAO;IACPR,OAAO;IACPI,OAAO;IACPM;EACF,CAAC;EACD,OAAO;IACLR,SAAS;IACTvB,SAAS;IACTC;EACF,CAAC;AACH"}
|
|
@@ -1,87 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ComponentModel } from './component-model';
|
|
3
|
-
import { ComponentError } from './component-error';
|
|
4
|
-
export declare const componentIdFields: import("@apollo/client").DocumentNode;
|
|
5
|
-
export declare const componentOverviewFields: import("@apollo/client").DocumentNode;
|
|
6
|
-
export declare const componentFields: import("@apollo/client").DocumentNode;
|
|
7
|
-
export declare type Filters = {
|
|
8
|
-
log?: {
|
|
9
|
-
logType?: string;
|
|
10
|
-
logOffset?: number;
|
|
11
|
-
logLimit?: number;
|
|
12
|
-
logHead?: string;
|
|
13
|
-
logSort?: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
1
|
+
import { ComponentQueryResult, Filters } from './use-component.model';
|
|
16
2
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
17
|
-
export declare function useComponentQuery(componentId: string, host: string, filters?: Filters, skip?: boolean):
|
|
18
|
-
client: import("@apollo/client").ApolloClient<any>;
|
|
19
|
-
observable: import("@apollo/client").ObservableQuery<any, {
|
|
20
|
-
logType?: string | undefined;
|
|
21
|
-
logOffset?: number | undefined;
|
|
22
|
-
logLimit?: number | undefined;
|
|
23
|
-
logHead?: string | undefined;
|
|
24
|
-
logSort?: string | undefined;
|
|
25
|
-
id: string;
|
|
26
|
-
extensionId: string;
|
|
27
|
-
}>;
|
|
28
|
-
previousData?: any;
|
|
29
|
-
networkStatus: import("@apollo/client").NetworkStatus;
|
|
30
|
-
called: boolean;
|
|
31
|
-
startPolling: (pollInterval: number) => void;
|
|
32
|
-
stopPolling: () => void;
|
|
33
|
-
updateQuery: <TVars = {
|
|
34
|
-
logType?: string | undefined;
|
|
35
|
-
logOffset?: number | undefined;
|
|
36
|
-
logLimit?: number | undefined;
|
|
37
|
-
logHead?: string | undefined;
|
|
38
|
-
logSort?: string | undefined;
|
|
39
|
-
id: string;
|
|
40
|
-
extensionId: string;
|
|
41
|
-
}>(mapFn: (previousQueryResult: any, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, any>, "variables">) => any) => void;
|
|
42
|
-
refetch: (variables?: Partial<{
|
|
43
|
-
logType?: string | undefined;
|
|
44
|
-
logOffset?: number | undefined;
|
|
45
|
-
logLimit?: number | undefined;
|
|
46
|
-
logHead?: string | undefined;
|
|
47
|
-
logSort?: string | undefined;
|
|
48
|
-
id: string;
|
|
49
|
-
extensionId: string;
|
|
50
|
-
}> | undefined) => Promise<import("@apollo/client").ApolloQueryResult<any>>;
|
|
51
|
-
reobserve: (newOptions?: Partial<import("@apollo/client").WatchQueryOptions<{
|
|
52
|
-
logType?: string | undefined;
|
|
53
|
-
logOffset?: number | undefined;
|
|
54
|
-
logLimit?: number | undefined;
|
|
55
|
-
logHead?: string | undefined;
|
|
56
|
-
logSort?: string | undefined;
|
|
57
|
-
id: string;
|
|
58
|
-
extensionId: string;
|
|
59
|
-
}, any>> | undefined, newNetworkStatus?: import("@apollo/client").NetworkStatus | undefined) => Promise<import("@apollo/client").ApolloQueryResult<any>>;
|
|
60
|
-
variables: {
|
|
61
|
-
logType?: string | undefined;
|
|
62
|
-
logOffset?: number | undefined;
|
|
63
|
-
logLimit?: number | undefined;
|
|
64
|
-
logHead?: string | undefined;
|
|
65
|
-
logSort?: string | undefined;
|
|
66
|
-
id: string;
|
|
67
|
-
extensionId: string;
|
|
68
|
-
} | undefined;
|
|
69
|
-
fetchMore: <TFetchData = any, TFetchVars = {
|
|
70
|
-
logType?: string | undefined;
|
|
71
|
-
logOffset?: number | undefined;
|
|
72
|
-
logLimit?: number | undefined;
|
|
73
|
-
logHead?: string | undefined;
|
|
74
|
-
logSort?: string | undefined;
|
|
75
|
-
id: string;
|
|
76
|
-
extensionId: string;
|
|
77
|
-
}>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & {
|
|
78
|
-
updateQuery?: ((previousQueryResult: any, options: {
|
|
79
|
-
fetchMoreResult: TFetchData;
|
|
80
|
-
variables: TFetchVars;
|
|
81
|
-
}) => any) | undefined;
|
|
82
|
-
}) => Promise<import("@apollo/client").ApolloQueryResult<TFetchData>>;
|
|
83
|
-
componentDescriptor: ComponentDescriptor | undefined;
|
|
84
|
-
component: ComponentModel | undefined;
|
|
85
|
-
error: ComponentError | undefined;
|
|
86
|
-
loading: boolean;
|
|
87
|
-
};
|
|
3
|
+
export declare function useComponentQuery(componentId: string, host: string, filters?: Filters, skip?: boolean): ComponentQueryResult;
|
|
@@ -4,7 +4,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.componentOverviewFields = exports.componentIdFields = exports.componentFields = void 0;
|
|
8
7
|
exports.useComponentQuery = useComponentQuery;
|
|
9
8
|
function _defineProperty2() {
|
|
10
9
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -13,13 +12,6 @@ function _defineProperty2() {
|
|
|
13
12
|
};
|
|
14
13
|
return data;
|
|
15
14
|
}
|
|
16
|
-
function _objectWithoutProperties2() {
|
|
17
|
-
const data = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
18
|
-
_objectWithoutProperties2 = function () {
|
|
19
|
-
return data;
|
|
20
|
-
};
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
15
|
function _react() {
|
|
24
16
|
const data = require("react");
|
|
25
17
|
_react = function () {
|
|
@@ -27,13 +19,6 @@ function _react() {
|
|
|
27
19
|
};
|
|
28
20
|
return data;
|
|
29
21
|
}
|
|
30
|
-
function _client() {
|
|
31
|
-
const data = require("@apollo/client");
|
|
32
|
-
_client = function () {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
22
|
function _uiFoundationUiHooks() {
|
|
38
23
|
const data = require("@teambit/ui-foundation.ui.hooks.use-data-query");
|
|
39
24
|
_uiFoundationUiHooks = function () {
|
|
@@ -62,6 +47,20 @@ function _componentModel() {
|
|
|
62
47
|
};
|
|
63
48
|
return data;
|
|
64
49
|
}
|
|
50
|
+
function _useComponent() {
|
|
51
|
+
const data = require("./use-component.fragments");
|
|
52
|
+
_useComponent = function () {
|
|
53
|
+
return data;
|
|
54
|
+
};
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
function _useComponentLogs() {
|
|
58
|
+
const data = require("./use-component-logs");
|
|
59
|
+
_useComponentLogs = function () {
|
|
60
|
+
return data;
|
|
61
|
+
};
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
65
64
|
function _componentError() {
|
|
66
65
|
const data = require("./component-error");
|
|
67
66
|
_componentError = function () {
|
|
@@ -71,173 +70,39 @@ function _componentError() {
|
|
|
71
70
|
}
|
|
72
71
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
73
72
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
74
|
-
const componentIdFields = (0, _client().gql)`
|
|
75
|
-
fragment componentIdFields on ComponentID {
|
|
76
|
-
name
|
|
77
|
-
version
|
|
78
|
-
scope
|
|
79
|
-
}
|
|
80
|
-
`;
|
|
81
|
-
exports.componentIdFields = componentIdFields;
|
|
82
|
-
const componentOverviewFields = (0, _client().gql)`
|
|
83
|
-
fragment componentOverviewFields on Component {
|
|
84
|
-
id {
|
|
85
|
-
...componentIdFields
|
|
86
|
-
}
|
|
87
|
-
aspects(include: ["teambit.preview/preview", "teambit.envs/envs"]) {
|
|
88
|
-
# 'id' property in gql refers to a *global* identifier and used for caching.
|
|
89
|
-
# this makes aspect data cache under the same key, even when they are under different components.
|
|
90
|
-
# renaming the property fixes that.
|
|
91
|
-
id
|
|
92
|
-
data
|
|
93
|
-
}
|
|
94
|
-
elementsUrl
|
|
95
|
-
description
|
|
96
|
-
deprecation {
|
|
97
|
-
isDeprecate
|
|
98
|
-
newId
|
|
99
|
-
}
|
|
100
|
-
labels
|
|
101
|
-
displayName
|
|
102
|
-
server {
|
|
103
|
-
env
|
|
104
|
-
url
|
|
105
|
-
host
|
|
106
|
-
basePath
|
|
107
|
-
}
|
|
108
|
-
buildStatus
|
|
109
|
-
env {
|
|
110
|
-
id
|
|
111
|
-
icon
|
|
112
|
-
}
|
|
113
|
-
size {
|
|
114
|
-
compressedTotal
|
|
115
|
-
}
|
|
116
|
-
preview {
|
|
117
|
-
includesEnvTemplate
|
|
118
|
-
legacyHeader
|
|
119
|
-
isScaling
|
|
120
|
-
skipIncludes
|
|
121
|
-
}
|
|
122
|
-
compositions {
|
|
123
|
-
identifier
|
|
124
|
-
displayName
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
${componentIdFields}
|
|
128
|
-
`;
|
|
129
|
-
exports.componentOverviewFields = componentOverviewFields;
|
|
130
|
-
const componentFields = (0, _client().gql)`
|
|
131
|
-
fragment componentFields on Component {
|
|
132
|
-
id {
|
|
133
|
-
...componentIdFields
|
|
134
|
-
}
|
|
135
|
-
...componentOverviewFields
|
|
136
|
-
packageName
|
|
137
|
-
latest
|
|
138
|
-
compositions {
|
|
139
|
-
identifier
|
|
140
|
-
displayName
|
|
141
|
-
}
|
|
142
|
-
tags {
|
|
143
|
-
version
|
|
144
|
-
}
|
|
145
|
-
logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead, sort: $logSort) {
|
|
146
|
-
id
|
|
147
|
-
message
|
|
148
|
-
username
|
|
149
|
-
email
|
|
150
|
-
date
|
|
151
|
-
hash
|
|
152
|
-
tag
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
${componentIdFields}
|
|
156
|
-
${componentOverviewFields}
|
|
157
|
-
`;
|
|
158
|
-
exports.componentFields = componentFields;
|
|
159
|
-
const GET_COMPONENT = (0, _client().gql)`
|
|
160
|
-
query Component(
|
|
161
|
-
$id: String!
|
|
162
|
-
$extensionId: String!
|
|
163
|
-
$logType: String
|
|
164
|
-
$logOffset: Int
|
|
165
|
-
$logLimit: Int
|
|
166
|
-
$logHead: String
|
|
167
|
-
$logSort: String
|
|
168
|
-
) {
|
|
169
|
-
getHost(id: $extensionId) {
|
|
170
|
-
id # used for GQL caching
|
|
171
|
-
get(id: $id) {
|
|
172
|
-
...componentFields
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
${componentFields}
|
|
177
|
-
`;
|
|
178
|
-
const SUB_SUBSCRIPTION_ADDED = (0, _client().gql)`
|
|
179
|
-
subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String, $logSort: String) {
|
|
180
|
-
componentAdded {
|
|
181
|
-
component {
|
|
182
|
-
...componentFields
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
${componentFields}
|
|
187
|
-
`;
|
|
188
|
-
const SUB_COMPONENT_CHANGED = (0, _client().gql)`
|
|
189
|
-
subscription OnComponentChanged(
|
|
190
|
-
$logType: String
|
|
191
|
-
$logOffset: Int
|
|
192
|
-
$logLimit: Int
|
|
193
|
-
$logHead: String
|
|
194
|
-
$logSort: String
|
|
195
|
-
) {
|
|
196
|
-
componentChanged {
|
|
197
|
-
component {
|
|
198
|
-
...componentFields
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
${componentFields}
|
|
203
|
-
`;
|
|
204
|
-
const SUB_COMPONENT_REMOVED = (0, _client().gql)`
|
|
205
|
-
subscription OnComponentRemoved {
|
|
206
|
-
componentRemoved {
|
|
207
|
-
componentIds {
|
|
208
|
-
...componentIdFields
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
${componentIdFields}
|
|
213
|
-
`;
|
|
214
73
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
215
74
|
function useComponentQuery(componentId, host, filters, skip) {
|
|
216
|
-
var _data$getHost;
|
|
75
|
+
var _data$getHost, _rawComponent$id, _rawComponent$id2, _rawComponent$id3;
|
|
217
76
|
const idRef = (0, _react().useRef)(componentId);
|
|
218
77
|
idRef.current = componentId;
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
78
|
+
const variables = {
|
|
79
|
+
id: componentId,
|
|
80
|
+
extensionId: host
|
|
81
|
+
};
|
|
82
|
+
const {
|
|
83
|
+
data,
|
|
84
|
+
error,
|
|
85
|
+
loading,
|
|
86
|
+
subscribeToMore
|
|
87
|
+
} = (0, _uiFoundationUiHooks().useDataQuery)(_useComponent().GET_COMPONENT, {
|
|
88
|
+
variables,
|
|
89
|
+
skip,
|
|
90
|
+
errorPolicy: 'all'
|
|
91
|
+
});
|
|
92
|
+
const {
|
|
93
|
+
loading: loadingLogs,
|
|
94
|
+
componentLogs: {
|
|
95
|
+
logs
|
|
96
|
+
} = {}
|
|
97
|
+
} = (0, _useComponentLogs().useComponentLogs)(componentId, host, filters, skip);
|
|
98
|
+
const rawComponent = data === null || data === void 0 ? void 0 : (_data$getHost = data.getHost) === null || _data$getHost === void 0 ? void 0 : _data$getHost.get;
|
|
234
99
|
(0, _react().useEffect)(() => {
|
|
235
100
|
// @TODO @Kutner fix subscription for scope
|
|
236
101
|
if (host !== 'teambit.workspace/workspace') {
|
|
237
102
|
return () => {};
|
|
238
103
|
}
|
|
239
104
|
const unsubAddition = subscribeToMore({
|
|
240
|
-
document: SUB_SUBSCRIPTION_ADDED,
|
|
105
|
+
document: _useComponent().SUB_SUBSCRIPTION_ADDED,
|
|
241
106
|
updateQuery: (prev, {
|
|
242
107
|
subscriptionData
|
|
243
108
|
}) => {
|
|
@@ -256,7 +121,7 @@ function useComponentQuery(componentId, host, filters, skip) {
|
|
|
256
121
|
}
|
|
257
122
|
});
|
|
258
123
|
const unsubChanges = subscribeToMore({
|
|
259
|
-
document: SUB_COMPONENT_CHANGED,
|
|
124
|
+
document: _useComponent().SUB_COMPONENT_CHANGED,
|
|
260
125
|
updateQuery: (prev, {
|
|
261
126
|
subscriptionData
|
|
262
127
|
}) => {
|
|
@@ -276,7 +141,7 @@ function useComponentQuery(componentId, host, filters, skip) {
|
|
|
276
141
|
}
|
|
277
142
|
});
|
|
278
143
|
const unsubRemoval = subscribeToMore({
|
|
279
|
-
document: SUB_COMPONENT_REMOVED,
|
|
144
|
+
document: _useComponent().SUB_COMPONENT_REMOVED,
|
|
280
145
|
updateQuery: (prev, {
|
|
281
146
|
subscriptionData
|
|
282
147
|
}) => {
|
|
@@ -302,8 +167,14 @@ function useComponentQuery(componentId, host, filters, skip) {
|
|
|
302
167
|
unsubRemoval();
|
|
303
168
|
};
|
|
304
169
|
}, []);
|
|
305
|
-
const rawComponent =
|
|
306
|
-
|
|
170
|
+
const idDepKey = rawComponent !== null && rawComponent !== void 0 && rawComponent.id ? `${rawComponent === null || rawComponent === void 0 ? void 0 : (_rawComponent$id = rawComponent.id) === null || _rawComponent$id === void 0 ? void 0 : _rawComponent$id.scope}/${rawComponent === null || rawComponent === void 0 ? void 0 : (_rawComponent$id2 = rawComponent.id) === null || _rawComponent$id2 === void 0 ? void 0 : _rawComponent$id2.name}@${rawComponent === null || rawComponent === void 0 ? void 0 : (_rawComponent$id3 = rawComponent.id) === null || _rawComponent$id3 === void 0 ? void 0 : _rawComponent$id3.version}}` : undefined;
|
|
171
|
+
const id = (0, _react().useMemo)(() => rawComponent ? _componentId().ComponentID.fromObject(rawComponent.id) : undefined, [idDepKey]);
|
|
172
|
+
const componentError = error && !data ? new (_componentError().ComponentError)(500, error.message) : !rawComponent && !loading && new (_componentError().ComponentError)(404) || undefined;
|
|
173
|
+
const component = (0, _react().useMemo)(() => rawComponent ? _componentModel().ComponentModel.from(_objectSpread(_objectSpread({}, rawComponent), {}, {
|
|
174
|
+
host,
|
|
175
|
+
logs
|
|
176
|
+
})) : undefined, [id === null || id === void 0 ? void 0 : id.toString(), logs]);
|
|
177
|
+
const componentDescriptor = (0, _react().useMemo)(() => {
|
|
307
178
|
const aspectList = {
|
|
308
179
|
entries: rawComponent === null || rawComponent === void 0 ? void 0 : rawComponent.aspects.map(aspectObject => {
|
|
309
180
|
return _objectSpread(_objectSpread({}, aspectObject), {}, {
|
|
@@ -312,20 +183,23 @@ function useComponentQuery(componentId, host, filters, skip) {
|
|
|
312
183
|
});
|
|
313
184
|
})
|
|
314
185
|
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
186
|
+
return id ? _componentDescriptor().ComponentDescriptor.fromObject({
|
|
187
|
+
id: id.toString(),
|
|
188
|
+
aspectList
|
|
189
|
+
}) : undefined;
|
|
190
|
+
}, [id === null || id === void 0 ? void 0 : id.toString()]);
|
|
191
|
+
return (0, _react().useMemo)(() => {
|
|
192
|
+
return {
|
|
193
|
+
componentDescriptor,
|
|
194
|
+
component,
|
|
195
|
+
componentLogs: {
|
|
196
|
+
loading: loadingLogs,
|
|
197
|
+
logs
|
|
198
|
+
},
|
|
325
199
|
error: componentError || undefined,
|
|
326
200
|
loading
|
|
327
|
-
}
|
|
328
|
-
}, [
|
|
201
|
+
};
|
|
202
|
+
}, [host, component, componentDescriptor, componentError]);
|
|
329
203
|
}
|
|
330
204
|
|
|
331
205
|
//# sourceMappingURL=use-component-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["componentIdFields","gql","componentOverviewFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","filters","skip","idRef","useRef","current","useDataQuery","variables","id","extensionId","log","errorPolicy","data","error","loading","subscribeToMore","rest","useEffect","unsubAddition","document","updateQuery","prev","subscriptionData","prevComponent","getHost","get","addedComponent","componentAdded","component","name","unsubChanges","updatedComponent","componentChanged","isUpdated","ComponentID","isEqualObj","unsubRemoval","removedIds","componentRemoved","componentIds","length","isRemoved","some","removedId","rawComponent","useMemo","aspectList","entries","aspects","map","aspectObject","aspectId","aspectData","fromObject","componentError","ComponentError","message","componentDescriptor","ComponentDescriptor","toString","undefined","ComponentModel","from"],"sources":["use-component-query.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react';\nimport { gql } from '@apollo/client';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\n\nexport const componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nexport const componentOverviewFields = gql`\n fragment componentOverviewFields on Component {\n id {\n ...componentIdFields\n }\n aspects(include: [\"teambit.preview/preview\", \"teambit.envs/envs\"]) {\n # 'id' property in gql refers to a *global* identifier and used for caching.\n # this makes aspect data cache under the same key, even when they are under different components.\n # renaming the property fixes that.\n id\n data\n }\n elementsUrl\n description\n deprecation {\n isDeprecate\n newId\n }\n labels\n displayName\n server {\n env\n url\n host\n basePath\n }\n buildStatus\n env {\n id\n icon\n }\n size {\n compressedTotal\n }\n preview {\n includesEnvTemplate\n legacyHeader\n isScaling\n skipIncludes\n }\n compositions {\n identifier\n displayName\n }\n }\n ${componentIdFields}\n`;\n\nexport const componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n ...componentOverviewFields\n packageName\n latest\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead, sort: $logSort) {\n id\n message\n username\n email\n date\n hash\n tag\n }\n }\n ${componentIdFields}\n ${componentOverviewFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component(\n $id: String!\n $extensionId: String!\n $logType: String\n $logOffset: Int\n $logLimit: Int\n $logHead: String\n $logSort: String\n ) {\n getHost(id: $extensionId) {\n id # used for GQL caching\n get(id: $id) {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_SUBSCRIPTION_ADDED = gql`\n subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String, $logSort: String) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged(\n $logType: String\n $logOffset: Int\n $logLimit: Int\n $logHead: String\n $logSort: String\n ) {\n componentChanged {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_REMOVED = gql`\n subscription OnComponentRemoved {\n componentRemoved {\n componentIds {\n ...componentIdFields\n }\n }\n }\n ${componentIdFields}\n`;\nexport type Filters = {\n log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string };\n};\n/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */\nexport function useComponentQuery(componentId: string, host: string, filters?: Filters, skip?: boolean) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore, ...rest } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host, ...(filters?.log || {}) },\n skip,\n errorPolicy: 'all',\n });\n\n useEffect(() => {\n // @TODO @Kutner fix subscription for scope\n if (host !== 'teambit.workspace/workspace') {\n return () => {};\n }\n\n const unsubAddition = subscribeToMore({\n document: SUB_SUBSCRIPTION_ADDED,\n updateQuery: (prev, { subscriptionData }) => {\n const prevComponent = prev?.getHost?.get;\n const addedComponent = subscriptionData?.data?.componentAdded?.component;\n\n if (!addedComponent || prevComponent) return prev;\n\n if (idRef.current === addedComponent.id.name) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: addedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubChanges = subscribeToMore({\n document: SUB_COMPONENT_CHANGED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const updatedComponent = subscriptionData?.data?.componentChanged?.component;\n\n const isUpdated = updatedComponent && ComponentID.isEqualObj(prevComponent?.id, updatedComponent?.id);\n\n if (isUpdated) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: updatedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubRemoval = subscribeToMore({\n document: SUB_COMPONENT_REMOVED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const removedIds: ComponentIdObj[] | undefined = subscriptionData?.data?.componentRemoved?.componentIds;\n if (!prevComponent || !removedIds?.length) return prev;\n\n const isRemoved = removedIds.some((removedId) => ComponentID.isEqualObj(removedId, prevComponent.id));\n\n if (isRemoved) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: null,\n },\n };\n }\n\n return prev;\n },\n });\n\n return () => {\n unsubChanges();\n unsubAddition();\n unsubRemoval();\n };\n }, []);\n\n const rawComponent = data?.getHost?.get;\n return useMemo(() => {\n const aspectList = {\n entries: rawComponent?.aspects.map((aspectObject) => {\n return {\n ...aspectObject,\n aspectId: aspectObject.id,\n aspectData: aspectObject.data,\n };\n }),\n };\n const id = rawComponent && ComponentID.fromObject(rawComponent.id);\n const componentError =\n error && !data ? new ComponentError(500, error.message) : !rawComponent && !loading && new ComponentError(404);\n return {\n componentDescriptor: id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined,\n component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,\n error: componentError || undefined,\n loading,\n ...rest,\n };\n }, [rawComponent, host, error]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAmD;AAAA;AAE5C,MAAMA,iBAAiB,GAAG,IAAAC,aAAG,CAAC;AACrC;AACA;AACA;AACA;AACA;AACA,CAAC;AAAC;AAEK,MAAMC,uBAAuB,GAAG,IAAAD,aAAG,CAAC;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,iBAAkB;AACtB,CAAC;AAAC;AAEK,MAAMG,eAAe,GAAG,IAAAF,aAAG,CAAC;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,iBAAkB;AACtB,IAAIE,uBAAwB;AAC5B,CAAC;AAAC;AAEF,MAAME,aAAa,GAAG,IAAAH,aAAG,CAAC;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIE,eAAgB;AACpB,CAAC;AAED,MAAME,sBAAsB,GAAG,IAAAJ,aAAG,CAAC;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIE,eAAgB;AACpB,CAAC;AAED,MAAMG,qBAAqB,GAAG,IAAAL,aAAG,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIE,eAAgB;AACpB,CAAC;AAED,MAAMI,qBAAqB,GAAG,IAAAN,aAAG,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,iBAAkB;AACtB,CAAC;AAID;AACO,SAASQ,iBAAiB,CAACC,WAAmB,EAAEC,IAAY,EAAEC,OAAiB,EAAEC,IAAc,EAAE;EAAA;EACtG,MAAMC,KAAK,GAAG,IAAAC,eAAM,EAACL,WAAW,CAAC;EACjCI,KAAK,CAACE,OAAO,GAAGN,WAAW;EAC3B,sBAA2D,I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B,YAAY;QAAE5C;MAAI,GAAG,GAAG4D,SAAS;MACpF/C,KAAK,EAAEyC,cAAc,IAAIM,SAAS;MAClC9C;IAAO,GACJE,IAAI;EAEX,CAAC,EAAE,CAAC4B,YAAY,EAAE5C,IAAI,EAAEa,KAAK,CAAC,CAAC;AACjC"}
|
|
1
|
+
{"version":3,"names":["useComponentQuery","componentId","host","filters","skip","idRef","useRef","current","variables","id","extensionId","data","error","loading","subscribeToMore","useDataQuery","GET_COMPONENT","errorPolicy","loadingLogs","componentLogs","logs","useComponentLogs","rawComponent","getHost","get","useEffect","unsubAddition","document","SUB_SUBSCRIPTION_ADDED","updateQuery","prev","subscriptionData","prevComponent","addedComponent","componentAdded","component","name","unsubChanges","SUB_COMPONENT_CHANGED","updatedComponent","componentChanged","isUpdated","ComponentID","isEqualObj","unsubRemoval","SUB_COMPONENT_REMOVED","removedIds","componentRemoved","componentIds","length","isRemoved","some","removedId","idDepKey","scope","version","undefined","useMemo","fromObject","componentError","ComponentError","message","ComponentModel","from","toString","componentDescriptor","aspectList","entries","aspects","map","aspectObject","aspectId","aspectData","ComponentDescriptor"],"sources":["use-component-query.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\nimport { ComponentModel } from './component-model';\nimport { ComponentQueryResult, Filters } from './use-component.model';\nimport {\n GET_COMPONENT,\n SUB_COMPONENT_CHANGED,\n SUB_COMPONENT_REMOVED,\n SUB_SUBSCRIPTION_ADDED,\n} from './use-component.fragments';\nimport { useComponentLogs } from './use-component-logs';\nimport { ComponentError } from './component-error';\n\n/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */\nexport function useComponentQuery(\n componentId: string,\n host: string,\n filters?: Filters,\n skip?: boolean\n): ComponentQueryResult {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const variables = {\n id: componentId,\n extensionId: host,\n };\n\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables,\n skip,\n errorPolicy: 'all',\n });\n\n const { loading: loadingLogs, componentLogs: { logs } = {} } = useComponentLogs(componentId, host, filters, skip);\n\n const rawComponent = data?.getHost?.get;\n\n useEffect(() => {\n // @TODO @Kutner fix subscription for scope\n if (host !== 'teambit.workspace/workspace') {\n return () => {};\n }\n\n const unsubAddition = subscribeToMore({\n document: SUB_SUBSCRIPTION_ADDED,\n updateQuery: (prev, { subscriptionData }) => {\n const prevComponent = prev?.getHost?.get;\n const addedComponent = subscriptionData?.data?.componentAdded?.component;\n\n if (!addedComponent || prevComponent) return prev;\n\n if (idRef.current === addedComponent.id.name) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: addedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubChanges = subscribeToMore({\n document: SUB_COMPONENT_CHANGED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const updatedComponent = subscriptionData?.data?.componentChanged?.component;\n\n const isUpdated = updatedComponent && ComponentID.isEqualObj(prevComponent?.id, updatedComponent?.id);\n\n if (isUpdated) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: updatedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubRemoval = subscribeToMore({\n document: SUB_COMPONENT_REMOVED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const removedIds: ComponentIdObj[] | undefined = subscriptionData?.data?.componentRemoved?.componentIds;\n if (!prevComponent || !removedIds?.length) return prev;\n\n const isRemoved = removedIds.some((removedId) => ComponentID.isEqualObj(removedId, prevComponent.id));\n\n if (isRemoved) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: null,\n },\n };\n }\n\n return prev;\n },\n });\n\n return () => {\n unsubChanges();\n unsubAddition();\n unsubRemoval();\n };\n }, []);\n\n const idDepKey = rawComponent?.id\n ? `${rawComponent?.id?.scope}/${rawComponent?.id?.name}@${rawComponent?.id?.version}}`\n : undefined;\n\n const id: ComponentID | undefined = useMemo(\n () => (rawComponent ? ComponentID.fromObject(rawComponent.id) : undefined),\n [idDepKey]\n );\n\n const componentError =\n error && !data\n ? new ComponentError(500, error.message)\n : (!rawComponent && !loading && new ComponentError(404)) || undefined;\n\n const component = useMemo(\n () => (rawComponent ? ComponentModel.from({ ...rawComponent, host, logs }) : undefined),\n [id?.toString(), logs]\n );\n\n const componentDescriptor = useMemo(() => {\n const aspectList = {\n entries: rawComponent?.aspects.map((aspectObject) => {\n return {\n ...aspectObject,\n aspectId: aspectObject.id,\n aspectData: aspectObject.data,\n };\n }),\n };\n\n return id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined;\n }, [id?.toString()]);\n\n return useMemo(() => {\n return {\n componentDescriptor,\n component,\n componentLogs: {\n loading: loadingLogs,\n logs,\n },\n error: componentError || undefined,\n loading,\n };\n }, [host, component, componentDescriptor, componentError]);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAMA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAmD;AAAA;AAEnD;AACO,SAASA,iBAAiB,CAC/BC,WAAmB,EACnBC,IAAY,EACZC,OAAiB,EACjBC,IAAc,EACQ;EAAA;EACtB,MAAMC,KAAK,GAAG,IAAAC,eAAM,EAACL,WAAW,CAAC;EACjCI,KAAK,CAACE,OAAO,GA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filters } from './use-component-query';
|
|
5
|
-
export declare type Component = {
|
|
6
|
-
component?: ComponentModel;
|
|
7
|
-
error?: ComponentError;
|
|
8
|
-
componentDescriptor?: ComponentDescriptor;
|
|
9
|
-
loading?: boolean;
|
|
10
|
-
};
|
|
11
|
-
export declare type UseComponentOptions = {
|
|
12
|
-
version?: string;
|
|
13
|
-
logFilters?: Filters;
|
|
14
|
-
customUseComponent?: UseComponentType;
|
|
15
|
-
skip?: boolean;
|
|
16
|
-
};
|
|
17
|
-
export declare type UseComponentType = (id: string, host: string, filters?: Filters, skip?: boolean) => Component;
|
|
18
|
-
export declare function useComponent(host: string, id?: string, options?: UseComponentOptions): Component;
|
|
1
|
+
import { ComponentQueryResult, UseComponentOptions, UseComponentType, Filters } from './use-component.model';
|
|
2
|
+
export { UseComponentType, Filters };
|
|
3
|
+
export declare function useComponent(host: string, id?: string, options?: UseComponentOptions): ComponentQueryResult;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const componentIdFields: import("@apollo/client").DocumentNode;
|
|
2
|
+
export declare const componentOverviewFields: import("@apollo/client").DocumentNode;
|
|
3
|
+
export declare const componentFields: import("@apollo/client").DocumentNode;
|
|
4
|
+
export declare const componentFieldsWithLogs: import("@apollo/client").DocumentNode;
|
|
5
|
+
export declare const COMPONENT_QUERY_LOG_FIELDS = "\n $logOffset: Int\n $logLimit: Int\n $logType: String\n $logHead: String\n $logSort: String\n $logTakeHeadFromComponent: Boolean\n";
|
|
6
|
+
export declare const GET_COMPONENT: import("@apollo/client").DocumentNode;
|
|
7
|
+
export declare const GET_COMPONENT_WITH_LOGS: import("@apollo/client").DocumentNode;
|
|
8
|
+
export declare const SUB_SUBSCRIPTION_ADDED: import("@apollo/client").DocumentNode;
|
|
9
|
+
export declare const SUB_COMPONENT_CHANGED: import("@apollo/client").DocumentNode;
|
|
10
|
+
export declare const SUB_COMPONENT_REMOVED: import("@apollo/client").DocumentNode;
|