@teambit/component 0.0.669 → 0.0.670
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/component.d.ts +1 -0
- package/dist/component.graphql.d.ts +1 -0
- package/dist/component.graphql.js +1 -1
- package/dist/component.graphql.js.map +1 -1
- package/dist/component.js +20 -1
- package/dist/component.js.map +1 -1
- package/dist/ui/context/component-context.js.map +1 -1
- package/dist/ui/use-component-query.d.ts +8 -1
- package/dist/ui/use-component-query.js +16 -8
- package/dist/ui/use-component-query.js.map +1 -1
- package/dist/ui/use-component.js +22 -1
- package/dist/ui/use-component.js.map +1 -1
- package/package-tar/teambit-component-0.0.670.tgz +0 -0
- package/package.json +20 -20
- package/{preview-1646796119196.js → preview-1646882648682.js} +1 -1
- package/ui/context/component-context.ts +1 -1
- package/ui/use-component-query.ts +19 -7
- package/ui/use-component.tsx +15 -2
- package/package-tar/teambit-component-0.0.669.tgz +0 -0
package/dist/component.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export declare function componentSchema(componentExtension: ComponentMain): {
|
|
|
32
32
|
type?: string | undefined;
|
|
33
33
|
offset?: number | undefined;
|
|
34
34
|
limit?: number | undefined;
|
|
35
|
+
head?: string | undefined;
|
|
35
36
|
} | undefined) => Promise<import("@teambit/legacy/scopes/component/legacy-component-log").LegacyComponentLog[]>;
|
|
36
37
|
};
|
|
37
38
|
ComponentHost: {
|
|
@@ -136,7 +136,7 @@ function componentSchema(componentExtension) {
|
|
|
136
136
|
tags: [Tag]!
|
|
137
137
|
|
|
138
138
|
# component logs
|
|
139
|
-
logs(type: String, offset: Int, limit: Int): [LogEntry]!
|
|
139
|
+
logs(type: String, offset: Int, limit: Int, head: String): [LogEntry]!
|
|
140
140
|
|
|
141
141
|
aspects(include: [String]): [Aspect]
|
|
142
142
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["component.graphql.ts"],"names":["componentSchema","componentExtension","typeDefs","resolvers","JSONObject","GraphQLJSONObject","Component","id","component","toObject","displayName","fs","state","filesystem","files","map","file","relative","getFile","path","maybeFile","find","undefined","contents","toString","mainFile","_consumer","headTag","latest","tags","toArray","tag","aspects","include","filter","serialize","logs","getLogs","ComponentHost","get","host","componentId","resolveComponentId","error","snaps","list","listInvalid","invalidComps","err","errorName","name","errorMessage","message","Query","getHost","componentExt"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKO,SAASA,eAAT,CAAyBC,kBAAzB,EAA4D;AACjE,SAAO;AACLC,IAAAA,QAAQ,EAAE,0BAAI;AAClB;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;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;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,KA5HS;AA6HLC,IAAAA,SAAS,EAAE;AACTC,MAAAA,UAAU,EAAEC,oCADH;AAETC,MAAAA,SAAS,EAAE;AACTC,QAAAA,EAAE,EAAGC,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AA,SAAS,EAAED,GAAG,CAACE,IAFyB;AAGxCC,YAAAA,YAAY,EAAEH,GAAG,CAACI,OAAJ,GAAc,0BAAUJ,GAAG,CAACI,OAAd,CAAd,GAAuCJ,GAAG,CAACE;AAHjB,WAAlB,CAAjB,CAAP;AAKD,SAzBY;AA0Bb3C,QAAAA,EAAE,EAAE,MAAOiC,IAAP,IAAkC;AACpC,iBAAOA,IAAI,CAACU,IAAZ;AACD,SA5BY;AA6BbA,QAAAA,IAAI,EAAE,MAAOV,IAAP,IAAkC;AACtC,iBAAOA,IAAI,CAACU,IAAZ;AACD;AA/BY,OA/BN;AAgETG,MAAAA,KAAK,EAAE;AACLC,QAAAA,OAAO,EAAE,CAACC,YAAD,EAA8B;AAAEhD,UAAAA;AAAF,SAA9B,KAAyD;AAChE,iBAAON,kBAAkB,CAACqD,OAAnB,CAA2B/C,EAA3B,CAAP;AACD;AAHI;AAhEE;AA7HN,GAAP;AAoMD","sourcesContent":["import stripAnsi from 'strip-ansi';\nimport gql from 'graphql-tag';\nimport { GraphQLJSONObject } from 'graphql-type-json';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport { Component } from './component';\nimport { ComponentFactory } from './component-factory';\nimport { ComponentMain } from './component.main.runtime';\n\nexport function componentSchema(componentExtension: ComponentMain) {\n return {\n typeDefs: gql`\n scalar JSON\n scalar JSONObject\n\n type ComponentID {\n name: String!\n version: String\n scope: String\n }\n\n type Tag {\n # semver assigned to the tag.\n version: String!\n\n # tag hash.\n hash: String!\n }\n\n type Snap {\n # hash of the snapshot.\n hash: String!\n\n # time of the snapshot.\n timestamp: String!\n\n # parents of the snap\n parents: [Snap]!\n\n # snapper\n author: Author!\n\n # snapshot message\n message: String\n }\n\n type LogEntry {\n message: String!\n username: String\n email: String\n date: String\n hash: String!\n tag: String\n # id: String!\n }\n\n type Author {\n # display name of the snapper.\n displayName: String!\n\n # author of the snapper.\n email: String!\n }\n\n type Component {\n # id of the component.\n id: ComponentID!\n\n # head snap of the component.\n head: Snap\n\n # head tag of the component.\n headTag: Tag\n\n # list of all relative component paths.\n fs: [String]\n\n # relative path to the main file of the component\n mainFile: String\n\n # return specific file contents by relative file path.\n getFile(path: String): String\n\n # latest version of the component.\n latest: String\n\n # display name of the component\n displayName: String!\n\n # component buildStatus\n buildStatus: String\n\n # list of component releases.\n tags: [Tag]!\n\n # component logs\n logs(type: String, offset: Int, limit: Int): [LogEntry]!\n\n aspects(include: [String]): [Aspect]\n }\n\n type Aspect {\n id: String!\n icon: String\n config: JSONObject\n data: JSONObject\n }\n\n type InvalidComponent {\n id: ComponentID!\n errorName: String!\n errorMessage: String!\n }\n\n type ComponentHost {\n id: ID!\n name: String!\n\n # load a component.\n get(id: String!, withState: Boolean): Component\n\n # list components\n list(offset: Int, limit: Int): [Component]!\n\n # list invalid components and their errors\n listInvalid: [InvalidComponent]!\n\n # get component logs(snaps) by component id\n snaps(id: String!): [LogEntry]! @deprecated(reason: \"Use the logs field on Component\")\n }\n\n type Query {\n getHost(id: String): ComponentHost\n }\n `,\n resolvers: {\n JSONObject: GraphQLJSONObject,\n Component: {\n id: (component: Component) => component.id.toObject(),\n displayName: (component: Component) => component.displayName,\n fs: (component: Component) => {\n return component.state.filesystem.files.map((file) => file.relative);\n },\n getFile: (component: Component, { path }: { path: string }) => {\n const maybeFile = component.state.filesystem.files.find(\n (file) => pathNormalizeToLinux(file.relative) === path\n );\n if (!maybeFile) return undefined;\n return maybeFile.contents.toString('utf-8');\n },\n mainFile: (component: Component) => {\n return component.state._consumer.mainFile;\n },\n headTag: (component: Component) => component.headTag?.toObject(),\n latest: (component: Component) => component.latest,\n tags: (component) => {\n // graphql doesn't support map types\n return component.tags.toArray().map((tag) => tag.toObject());\n },\n aspects: (component: Component, { include }: { include?: string[] }) => {\n return component.state.aspects.filter(include).serialize();\n },\n logs: async (component: Component, filter?: { type?: string; offset?: number; limit?: number }) => {\n return component.getLogs(filter);\n },\n },\n ComponentHost: {\n get: async (host: ComponentFactory, { id }: { id: string }) => {\n try {\n const componentId = await host.resolveComponentId(id);\n const component = await host.get(componentId);\n return component;\n } catch (error: any) {\n return null;\n }\n },\n snaps: async (host: ComponentFactory, { id }: { id: string }) => {\n const componentId = await host.resolveComponentId(id);\n // return (await host.getLogs(componentId)).map(log => ({...log, id: log.hash}))\n return host.getLogs(componentId);\n },\n list: async (host: ComponentFactory, filter?: { offset: number; limit: number }) => {\n return host.list(filter);\n },\n listInvalid: async (host: ComponentFactory) => {\n const invalidComps = await host.listInvalid();\n return invalidComps.map(({ id, err }) => ({\n id,\n errorName: err.name,\n errorMessage: err.message ? stripAnsi(err.message) : err.name,\n }));\n },\n id: async (host: ComponentFactory) => {\n return host.name;\n },\n name: async (host: ComponentFactory) => {\n return host.name;\n },\n },\n Query: {\n getHost: (componentExt: ComponentMain, { id }: { id: string }) => {\n return componentExtension.getHost(id);\n },\n },\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["component.graphql.ts"],"names":["componentSchema","componentExtension","typeDefs","resolvers","JSONObject","GraphQLJSONObject","Component","id","component","toObject","displayName","fs","state","filesystem","files","map","file","relative","getFile","path","maybeFile","find","undefined","contents","toString","mainFile","_consumer","headTag","latest","tags","toArray","tag","aspects","include","filter","serialize","logs","getLogs","ComponentHost","get","host","componentId","resolveComponentId","error","snaps","list","listInvalid","invalidComps","err","errorName","name","errorMessage","message","Query","getHost","componentExt"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKO,SAASA,eAAT,CAAyBC,kBAAzB,EAA4D;AACjE,SAAO;AACLC,IAAAA,QAAQ,EAAE,0BAAI;AAClB;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;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;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,KA5HS;AA6HLC,IAAAA,SAAS,EAAE;AACTC,MAAAA,UAAU,EAAEC,oCADH;AAETC,MAAAA,SAAS,EAAE;AACTC,QAAAA,EAAE,EAAGC,SAAD,IAA0BA,SAAS,CAACD,EAAV,CAAaE,QAAb,EADrB;AAETC,QAAAA,WAAW,EAAGF,SAAD,IAA0BA,SAAS,CAACE,WAFxC;AAGTC,QAAAA,EAAE,EAAGH,SAAD,IAA0B;AAC5B,iBAAOA,SAAS,CAACI,KAAV,CAAgBC,UAAhB,CAA2BC,KAA3B,CAAiCC,GAAjC,CAAsCC,IAAD,IAAUA,IAAI,CAACC,QAApD,CAAP;AACD,SALQ;AAMTC,QAAAA,OAAO,EAAE,CAACV,SAAD,EAAuB;AAAEW,UAAAA;AAAF,SAAvB,KAAsD;AAC7D,gBAAMC,SAAS,GAAGZ,SAAS,CAACI,KAAV,CAAgBC,UAAhB,CAA2BC,KAA3B,CAAiCO,IAAjC,CACfL,IAAD,IAAU,mCAAqBA,IAAI,CAACC,QAA1B,MAAwCE,IADlC,CAAlB;AAGA,cAAI,CAACC,SAAL,EAAgB,OAAOE,SAAP;AAChB,iBAAOF,SAAS,C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i from 'strip-ansi';\nimport gql from 'graphql-tag';\nimport { GraphQLJSONObject } from 'graphql-type-json';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport { Component } from './component';\nimport { ComponentFactory } from './component-factory';\nimport { ComponentMain } from './component.main.runtime';\n\nexport function componentSchema(componentExtension: ComponentMain) {\n return {\n typeDefs: gql`\n scalar JSON\n scalar JSONObject\n\n type ComponentID {\n name: String!\n version: String\n scope: String\n }\n\n type Tag {\n # semver assigned to the tag.\n version: String!\n\n # tag hash.\n hash: String!\n }\n\n type Snap {\n # hash of the snapshot.\n hash: String!\n\n # time of the snapshot.\n timestamp: String!\n\n # parents of the snap\n parents: [Snap]!\n\n # snapper\n author: Author!\n\n # snapshot message\n message: String\n }\n\n type LogEntry {\n message: String!\n username: String\n email: String\n date: String\n hash: String!\n tag: String\n # id: String!\n }\n\n type Author {\n # display name of the snapper.\n displayName: String!\n\n # author of the snapper.\n email: String!\n }\n\n type Component {\n # id of the component.\n id: ComponentID!\n\n # head snap of the component.\n head: Snap\n\n # head tag of the component.\n headTag: Tag\n\n # list of all relative component paths.\n fs: [String]\n\n # relative path to the main file of the component\n mainFile: String\n\n # return specific file contents by relative file path.\n getFile(path: String): String\n\n # latest version of the component.\n latest: String\n\n # display name of the component\n displayName: String!\n\n # component buildStatus\n buildStatus: String\n\n # list of component releases.\n tags: [Tag]!\n\n # component logs\n logs(type: String, offset: Int, limit: Int, head: String): [LogEntry]!\n\n aspects(include: [String]): [Aspect]\n }\n\n type Aspect {\n id: String!\n icon: String\n config: JSONObject\n data: JSONObject\n }\n\n type InvalidComponent {\n id: ComponentID!\n errorName: String!\n errorMessage: String!\n }\n\n type ComponentHost {\n id: ID!\n name: String!\n\n # load a component.\n get(id: String!, withState: Boolean): Component\n\n # list components\n list(offset: Int, limit: Int): [Component]!\n\n # list invalid components and their errors\n listInvalid: [InvalidComponent]!\n\n # get component logs(snaps) by component id\n snaps(id: String!): [LogEntry]! @deprecated(reason: \"Use the logs field on Component\")\n }\n\n type Query {\n getHost(id: String): ComponentHost\n }\n `,\n resolvers: {\n JSONObject: GraphQLJSONObject,\n Component: {\n id: (component: Component) => component.id.toObject(),\n displayName: (component: Component) => component.displayName,\n fs: (component: Component) => {\n return component.state.filesystem.files.map((file) => file.relative);\n },\n getFile: (component: Component, { path }: { path: string }) => {\n const maybeFile = component.state.filesystem.files.find(\n (file) => pathNormalizeToLinux(file.relative) === path\n );\n if (!maybeFile) return undefined;\n return maybeFile.contents.toString('utf-8');\n },\n mainFile: (component: Component) => {\n return component.state._consumer.mainFile;\n },\n headTag: (component: Component) => component.headTag?.toObject(),\n latest: (component: Component) => component.latest,\n tags: (component) => {\n // graphql doesn't support map types\n return component.tags.toArray().map((tag) => tag.toObject());\n },\n aspects: (component: Component, { include }: { include?: string[] }) => {\n return component.state.aspects.filter(include).serialize();\n },\n logs: async (\n component: Component,\n filter?: { type?: string; offset?: number; limit?: number; head?: string }\n ) => {\n return component.getLogs(filter);\n },\n },\n ComponentHost: {\n get: async (host: ComponentFactory, { id }: { id: string }) => {\n try {\n const componentId = await host.resolveComponentId(id);\n const component = await host.get(componentId);\n return component;\n } catch (error: any) {\n return null;\n }\n },\n snaps: async (host: ComponentFactory, { id }: { id: string }) => {\n const componentId = await host.resolveComponentId(id);\n // return (await host.getLogs(componentId)).map(log => ({...log, id: log.hash}))\n return host.getLogs(componentId);\n },\n list: async (host: ComponentFactory, filter?: { offset: number; limit: number }) => {\n return host.list(filter);\n },\n listInvalid: async (host: ComponentFactory) => {\n const invalidComps = await host.listInvalid();\n return invalidComps.map(({ id, err }) => ({\n id,\n errorName: err.name,\n errorMessage: err.message ? stripAnsi(err.message) : err.name,\n }));\n },\n id: async (host: ComponentFactory) => {\n return host.name;\n },\n name: async (host: ComponentFactory) => {\n return host.name;\n },\n },\n Query: {\n getHost: (componentExt: ComponentMain, { id }: { id: string }) => {\n return componentExtension.getHost(id);\n },\n },\n },\n };\n}\n"]}
|
package/dist/component.js
CHANGED
|
@@ -25,6 +25,16 @@ function _toolboxString() {
|
|
|
25
25
|
return data;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
function _componentId() {
|
|
29
|
+
const data = require("@teambit/component-id");
|
|
30
|
+
|
|
31
|
+
_componentId = function () {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
function _bitError() {
|
|
29
39
|
const data = require("@teambit/bit-error");
|
|
30
40
|
|
|
@@ -157,7 +167,16 @@ class Component {
|
|
|
157
167
|
}
|
|
158
168
|
|
|
159
169
|
async getLogs(filter) {
|
|
160
|
-
const
|
|
170
|
+
const id = !(filter !== null && filter !== void 0 && filter.head) ? _componentId().ComponentID.fromObject({
|
|
171
|
+
name: this.id.name,
|
|
172
|
+
scope: this.id.scope,
|
|
173
|
+
version: undefined
|
|
174
|
+
}) : _componentId().ComponentID.fromObject({
|
|
175
|
+
name: this.id.name,
|
|
176
|
+
scope: this.id.scope,
|
|
177
|
+
version: filter.head
|
|
178
|
+
});
|
|
179
|
+
const allLogs = await this.factory.getLogs(id);
|
|
161
180
|
if (!filter) return allLogs;
|
|
162
181
|
const {
|
|
163
182
|
type,
|
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["component.ts"],"names":["Component","constructor","id","head","_state","tags","TagMap","factory","mainFile","state","config","filesystem","buildStatus","_consumer","headTag","undefined","byHash","hash","latest","getLatest","err","CouldNotFindLatest","getLogs","filter","allLogs","type","limit","offset","typeFilter","snap","tag","filteredLogs","stringify","JSON","displayName","tokens","name","split","map","token","join","version","isModified","Promise","resolve","isOutdated","latestTag","byVersion","isNew","loadState","snapId","getState","loadSnap","snapToGet","BitError","getSnap","snapsIterable","options","snapToStart","nextSnaps","done","iterator","next","value","currSnapId","shift","parents","length","firstParentOnly","push","concat","stopFn","Symbol","asyncIterator","getClosestTag","snapToStartFrom","tagsHashMap","getHashMap","has","iterable","snaps","hashOfLastSnap","get","checkout","write","path","fs","equals","component","toString"],"mappings":";;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAQA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAUA;AACA;AACA;AACO,MAAMA,SAAN,CAAgB;AACrBC,EAAAA,WAAW;AACT;AACJ;AACA;AACaC,EAAAA,EAJA;AAMT;AACJ;AACA;AACaC,EAAAA,IAAiB,GAAG,IATpB;AAWT;AACJ;AACA;AACYC,EAAAA,MAdC;AAgBT;AACJ;AACA;AACaC,EAAAA,IAAY,GAAG,KAAIC,gBAAJ,GAnBf;AAqBT;AACJ;AACA;AACYC,EAAAA,OAxBC,EAyBT;AAAA,SArBSL,EAqBT,GArBSA,EAqBT;AAAA,SAhBSC,IAgBT,GAhBSA,IAgBT;AAAA,SAXQC,MAWR,GAXQA,MAWR;AAAA,SANSC,IAMT,GANSA,IAMT;AAAA,SADQE,OACR,GADQA,OACR;AAAE;;AAEQ,MAARC,QAAQ,GAAG;AACb,WAAO,KAAKC,KAAL,CAAWD,QAAlB;AACD;;AAEQ,MAALC,KAAK,GAAU;AACjB,WAAO,KAAKL,MAAZ;AACD;;AAEQ,MAALK,KAAK,CAACA,KAAD,EAAe;AACtB,SAAKL,MAAL,GAAcK,KAAd;AACD;AAED;AACF;AACA;;;AACY,MAANC,MAAM,GAAoB;AAC5B,WAAO,KAAKD,KAAL,CAAWC,MAAlB;AACD;AAED;AACF;AACA;;;AACgB,MAAVC,UAAU,GAAgB;AAC5B,WAAO,KAAKF,KAAL,CAAWE,UAAlB;AACD;AAED;AACF;AACA;;;AACiB,MAAXC,WAAW,GAAgB;AAC7B,WAAO,KAAKR,MAAL,CAAYS,SAAZ,C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AChB,YAAMc,cAAc,GAAGD,KAAK,CAACA,KAAK,CAACb,MAAN,GAAe,CAAhB,CAAL,CAAwBlD,IAA/C;AACA,aAAO2D,WAAW,CAACM,GAAZ,CAAgBD,cAAhB,CAAP;AACD;;AACD,WAAOlE,SAAP;AACD;AAED;AACF;AACA;AACE;;;AACAoE,EAAAA,QAAQ,CAAC1C,OAAD,EAAkB,CAAE;AAE5B;AACF;AACA;AACE;;AAEA;AACF;AACA;AACE;;AAEA;AACF;AACA;AACA;AACA;AACE;;;AACA2C,EAAAA,KAAK,CAACC,IAAD,EAAeC,EAAf,EAA2B,CAAE;AAElC;AACF;AACA;AACA;AACA;AACA;AACA;AACE;;;AACAC,EAAAA,MAAM,CAACC,SAAD,EAAgC;AACpC,WAAOA,SAAS,CAACtF,EAAV,CAAauF,QAAb,OAA4B,KAAKvF,EAAL,CAAQuF,QAAR,EAAnC;AACD;;AA3QoB","sourcesContent":["import { AnyFS } from '@teambit/any-fs';\nimport { capitalize } from '@teambit/toolbox.string.capitalize';\nimport { SemVer } from 'semver';\nimport { ComponentID } from '@teambit/component-id';\nimport { BitError } from '@teambit/bit-error';\nimport { BuildStatus } from '@teambit/legacy/dist/constants';\n\nimport { slice } from 'lodash';\nimport { ComponentFactory } from './component-factory';\nimport ComponentFS from './component-fs';\n// import { NothingToSnap } from './exceptions';\nimport ComponentConfig from './config';\n// eslint-disable-next-line import/no-cycle\nimport { Snap } from './snap';\nimport { State } from './state';\nimport { TagMap } from './tag-map';\nimport { Tag } from './tag';\nimport { CouldNotFindLatest } from './exceptions';\n// import { Author } from './types';\n\ntype SnapsIterableOpts = {\n firstParentOnly?: boolean;\n stopFn?: (snap: Snap) => Promise<boolean>;\n};\n\nexport type InvalidComponent = { id: ComponentID; err: Error };\n\n/**\n * in-memory representation of a component.\n */\nexport class Component {\n constructor(\n /**\n * component ID represented by the `ComponentId` type.\n */\n readonly id: ComponentID,\n\n /**\n * head version of the component. can be `null` for new components.\n */\n readonly head: Snap | null = null,\n\n /**\n * state of the component.\n */\n private _state: State,\n\n /**\n * tags of the component.\n */\n readonly tags: TagMap = new TagMap(),\n\n /**\n * the component factory\n */\n private factory: ComponentFactory\n ) {}\n\n get mainFile() {\n return this.state.mainFile;\n }\n\n get state(): State {\n return this._state;\n }\n\n set state(state: State) {\n this._state = state;\n }\n\n /**\n * component configuration which is later generated to a component `package.json` and `bit.json`.\n */\n get config(): ComponentConfig {\n return this.state.config;\n }\n\n /**\n * in-memory representation of the component current filesystem.\n */\n get filesystem(): ComponentFS {\n return this.state.filesystem;\n }\n\n /**\n * build status of the component\n */\n get buildStatus(): BuildStatus {\n return this._state._consumer.buildStatus;\n }\n\n get headTag() {\n if (!this.head) return undefined;\n return this.tags.byHash(this.head.hash);\n }\n\n get latest(): string | undefined {\n if (!this.head) return undefined;\n try {\n return this.tags.getLatest();\n } catch (err: any) {\n if (err instanceof CouldNotFindLatest) {\n return this.head.hash;\n }\n throw err;\n }\n }\n\n async getLogs(filter?: { type?: string; offset?: number; limit?: number }) {\n const allLogs = await this.factory.getLogs(this.id);\n if (!filter) return allLogs;\n const { type, limit, offset } = filter;\n const typeFilter = (snap) => {\n if (type === 'tag') return snap.tag;\n if (type === 'snap') return !snap.tag;\n return true;\n };\n let filteredLogs = (type && allLogs.filter(typeFilter)) || allLogs;\n if (limit) {\n filteredLogs = slice(filteredLogs, offset, limit + (offset || 0));\n }\n return filteredLogs;\n }\n\n stringify(): string {\n return JSON.stringify({\n id: this.id,\n head: this.head,\n });\n }\n\n /**\n * record component changes in the `Scope`.\n */\n // snap(author: Author, message = '') {\n // if (!this.isModified()) throw new NothingToSnap();\n // const snap = new Snap(this, author, message);\n\n // return new Component(this.id, snap, snap.state);\n // }\n\n /**\n * display name of the component.\n */\n get displayName() {\n const tokens = this.id.name.split('-').map((token) => capitalize(token));\n return tokens.join(' ');\n }\n\n /**\n * tag a component `Snap` with a semantic version. we follow SemVer specs as defined [here](https://semver.org/)).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n tag(version: SemVer) {\n // const snap = this.snap();\n // const tag = new Tag(version, snap);\n // this.tags.set(tag);\n }\n\n /**\n * determines whether this component is modified in the workspace.\n */\n isModified(): Promise<boolean> {\n if (!this.head) return Promise.resolve(true);\n return Promise.resolve(this.state.isModified);\n // return Promise.resolve(this.state.hash !== this.head.hash);\n }\n\n /**\n * is component isOutdated\n */\n isOutdated(): boolean {\n if (!this.latest) return false;\n const latestTag = this.tags.byVersion(this.latest);\n if (!latestTag) return false;\n if (this.head?.hash !== latestTag?.hash) return true;\n return false;\n }\n\n /**\n * determines whether this component is new.\n */\n isNew(): Promise<boolean> {\n return Promise.resolve(this.head === null);\n }\n\n // TODO: @david after snap we need to make sure to refactor here.\n loadState(snapId: string): Promise<State> {\n return this.factory.getState(this.id, snapId);\n }\n\n loadSnap(snapId?: string): Promise<Snap> {\n const snapToGet = snapId || this.head?.hash;\n if (!snapToGet) {\n throw new BitError('could not load snap for new components');\n }\n return this.factory.getSnap(this.id, snapToGet);\n }\n\n /**\n * Get iterable which iterate over snap parents lazily\n * @param snapId\n * @param options\n */\n snapsIterable(snapId?: string, options: SnapsIterableOpts = {}): AsyncIterable<Snap> {\n const snapToStart = snapId || this.head?.hash;\n let nextSnaps = [snapToStart];\n let done;\n if (!snapToStart) {\n done = true;\n }\n\n const iterator: AsyncIterator<Snap> = {\n next: async () => {\n if (done) {\n return { value: undefined, done };\n }\n const currSnapId = nextSnaps.shift();\n const snap = await this.loadSnap(currSnapId);\n if (snap.parents && snap.parents.length) {\n if (options.firstParentOnly) {\n nextSnaps.push(snap.parents[0]);\n } else {\n nextSnaps = nextSnaps.concat(snap.parents);\n }\n }\n if (!nextSnaps.length) {\n done = true;\n } else if (options.stopFn) {\n done = await options.stopFn(snap);\n }\n return { value: snap, done: undefined };\n },\n };\n return {\n [Symbol.asyncIterator]: () => iterator,\n };\n }\n\n /**\n * traverse recursively from the provided snap (or head) upwards until it finds a tag\n * @param snapToStartFrom\n */\n async getClosestTag(snapToStartFrom?: string): Promise<Tag | undefined> {\n const tagsHashMap = this.tags.getHashMap();\n const stopFn = async (snap: Snap) => {\n if (tagsHashMap.has(snap.hash)) {\n return true;\n }\n return false;\n };\n const iterable = this.snapsIterable(snapToStartFrom, { firstParentOnly: true, stopFn });\n const snaps: Snap[] = [];\n for await (const snap of iterable) {\n snaps.push(snap);\n }\n if (snaps.length) {\n const hashOfLastSnap = snaps[snaps.length - 1].hash;\n return tagsHashMap.get(hashOfLastSnap);\n }\n return undefined;\n }\n\n /**\n * checkout the component to a different version in its working tree.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n checkout(version: SemVer) {}\n\n /**\n * examine difference between two components.\n */\n // diff(other: Component): Difference {}\n\n /**\n * merge two different components\n */\n // merge(other: Component): Component {}\n\n /**\n * write a component to a given file system.\n * @param path root path to write the component\n * @param fs instance of any fs to use.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n write(path: string, fs?: AnyFS) {}\n\n /**\n *\n * Check if 2 components are equal\n * @param {Component} component\n * @returns {boolean}\n * @memberof Component\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n equals(component: Component): boolean {\n return component.id.toString() === this.id.toString();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["component.ts"],"names":["Component","constructor","id","head","_state","tags","TagMap","factory","mainFile","state","config","filesystem","buildStatus","_consumer","headTag","undefined","byHash","hash","latest","getLatest","err","CouldNotFindLatest","getLogs","filter","ComponentID","fromObject","name","scope","version","allLogs","type","limit","offset","typeFilter","snap","tag","filteredLogs","stringify","JSON","displayName","tokens","split","map","token","join","isModified","Promise","resolve","isOutdated","latestTag","byVersion","isNew","loadState","snapId","getState","loadSnap","snapToGet","BitError","getSnap","snapsIterable","options","snapToStart","nextSnaps","done","iterator","next","value","currSnapId","shift","parents","length","firstParentOnly","push","concat","stopFn","Symbol","asyncIterator","getClosestTag","snapToStartFrom","tagsHashMap","getHashMap","has","iterable","snaps","hashOfLastSnap","get","checkout","write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AgC;AAC9B,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AACD,KALD;;AAMA,UAAMiE,QAAQ,GAAG,KAAKvB,aAAL,CAAmBmB,eAAnB,EAAoC;AAAEP,MAAAA,eAAe,EAAE,IAAnB;AAAyBG,MAAAA;AAAzB,KAApC,CAAjB;AACA,UAAMS,KAAa,GAAG,EAAtB;AATsE;AAAA;;AAAA;;AAAA;AAUtE,0CAAyBD,QAAzB,iHAAmC;AAAA,cAAlBhD,IAAkB;AACjCiD,QAAAA,KAAK,CAACX,IAAN,CAAWtC,IAAX;AACD;AAZqE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAatE,QAAIiD,KAAK,CAACb,MAAV,EAAkB;AAChB,YAAMc,cAAc,GAAGD,KAAK,CAACA,KAAK,CAACb,MAAN,GAAe,CAAhB,CAAL,CAAwBrD,IAA/C;AACA,aAAO8D,WAAW,CAACM,GAAZ,CAAgBD,cAAhB,CAAP;AACD;;AACD,WAAOrE,SAAP;AACD;AAED;AACF;AACA;AACE;;;AACAuE,EAAAA,QAAQ,CAAC1D,OAAD,EAAkB,CAAE;AAE5B;AACF;AACA;AACE;;AAEA;AACF;AACA;AACE;;AAEA;AACF;AACA;AACA;AACA;AACE;;;AACA2D,EAAAA,KAAK,CAACC,IAAD,EAAeC,EAAf,EAA2B,CAAE;AAElC;AACF;AACA;AACA;AACA;AACA;AACA;AACE;;;AACAC,EAAAA,MAAM,CAACC,SAAD,EAAgC;AACpC,WAAOA,SAAS,CAACzF,EAAV,CAAa0F,QAAb,OAA4B,KAAK1F,EAAL,CAAQ0F,QAAR,EAAnC;AACD;;AA/QoB","sourcesContent":["import { AnyFS } from '@teambit/any-fs';\nimport { capitalize } from '@teambit/toolbox.string.capitalize';\nimport { SemVer } from 'semver';\nimport { ComponentID } from '@teambit/component-id';\nimport { BitError } from '@teambit/bit-error';\nimport { BuildStatus } from '@teambit/legacy/dist/constants';\n\nimport { slice } from 'lodash';\nimport { ComponentFactory } from './component-factory';\nimport ComponentFS from './component-fs';\n// import { NothingToSnap } from './exceptions';\nimport ComponentConfig from './config';\n// eslint-disable-next-line import/no-cycle\nimport { Snap } from './snap';\nimport { State } from './state';\nimport { TagMap } from './tag-map';\nimport { Tag } from './tag';\nimport { CouldNotFindLatest } from './exceptions';\n// import { Author } from './types';\n\ntype SnapsIterableOpts = {\n firstParentOnly?: boolean;\n stopFn?: (snap: Snap) => Promise<boolean>;\n};\n\nexport type InvalidComponent = { id: ComponentID; err: Error };\n\n/**\n * in-memory representation of a component.\n */\nexport class Component {\n constructor(\n /**\n * component ID represented by the `ComponentId` type.\n */\n readonly id: ComponentID,\n\n /**\n * head version of the component. can be `null` for new components.\n */\n readonly head: Snap | null = null,\n\n /**\n * state of the component.\n */\n private _state: State,\n\n /**\n * tags of the component.\n */\n readonly tags: TagMap = new TagMap(),\n\n /**\n * the component factory\n */\n private factory: ComponentFactory\n ) {}\n\n get mainFile() {\n return this.state.mainFile;\n }\n\n get state(): State {\n return this._state;\n }\n\n set state(state: State) {\n this._state = state;\n }\n\n /**\n * component configuration which is later generated to a component `package.json` and `bit.json`.\n */\n get config(): ComponentConfig {\n return this.state.config;\n }\n\n /**\n * in-memory representation of the component current filesystem.\n */\n get filesystem(): ComponentFS {\n return this.state.filesystem;\n }\n\n /**\n * build status of the component\n */\n get buildStatus(): BuildStatus {\n return this._state._consumer.buildStatus;\n }\n\n get headTag() {\n if (!this.head) return undefined;\n return this.tags.byHash(this.head.hash);\n }\n\n get latest(): string | undefined {\n if (!this.head) return undefined;\n try {\n return this.tags.getLatest();\n } catch (err: any) {\n if (err instanceof CouldNotFindLatest) {\n return this.head.hash;\n }\n throw err;\n }\n }\n\n async getLogs(filter?: { type?: string; offset?: number; limit?: number; head?: string }) {\n const id = !filter?.head\n ? ComponentID.fromObject({ name: this.id.name, scope: this.id.scope, version: undefined })\n : ComponentID.fromObject({ name: this.id.name, scope: this.id.scope, version: filter.head });\n\n const allLogs = await this.factory.getLogs(id);\n if (!filter) return allLogs;\n const { type, limit, offset } = filter;\n const typeFilter = (snap) => {\n if (type === 'tag') return snap.tag;\n if (type === 'snap') return !snap.tag;\n return true;\n };\n let filteredLogs = (type && allLogs.filter(typeFilter)) || allLogs;\n if (limit) {\n filteredLogs = slice(filteredLogs, offset, limit + (offset || 0));\n }\n return filteredLogs;\n }\n\n stringify(): string {\n return JSON.stringify({\n id: this.id,\n head: this.head,\n });\n }\n\n /**\n * record component changes in the `Scope`.\n */\n // snap(author: Author, message = '') {\n // if (!this.isModified()) throw new NothingToSnap();\n // const snap = new Snap(this, author, message);\n\n // return new Component(this.id, snap, snap.state);\n // }\n\n /**\n * display name of the component.\n */\n get displayName() {\n const tokens = this.id.name.split('-').map((token) => capitalize(token));\n return tokens.join(' ');\n }\n\n /**\n * tag a component `Snap` with a semantic version. we follow SemVer specs as defined [here](https://semver.org/)).\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n tag(version: SemVer) {\n // const snap = this.snap();\n // const tag = new Tag(version, snap);\n // this.tags.set(tag);\n }\n\n /**\n * determines whether this component is modified in the workspace.\n */\n isModified(): Promise<boolean> {\n if (!this.head) return Promise.resolve(true);\n return Promise.resolve(this.state.isModified);\n // return Promise.resolve(this.state.hash !== this.head.hash);\n }\n\n /**\n * is component isOutdated\n */\n isOutdated(): boolean {\n if (!this.latest) return false;\n const latestTag = this.tags.byVersion(this.latest);\n if (!latestTag) return false;\n if (this.head?.hash !== latestTag?.hash) return true;\n return false;\n }\n\n /**\n * determines whether this component is new.\n */\n isNew(): Promise<boolean> {\n return Promise.resolve(this.head === null);\n }\n\n // TODO: @david after snap we need to make sure to refactor here.\n loadState(snapId: string): Promise<State> {\n return this.factory.getState(this.id, snapId);\n }\n\n loadSnap(snapId?: string): Promise<Snap> {\n const snapToGet = snapId || this.head?.hash;\n if (!snapToGet) {\n throw new BitError('could not load snap for new components');\n }\n return this.factory.getSnap(this.id, snapToGet);\n }\n\n /**\n * Get iterable which iterate over snap parents lazily\n * @param snapId\n * @param options\n */\n snapsIterable(snapId?: string, options: SnapsIterableOpts = {}): AsyncIterable<Snap> {\n const snapToStart = snapId || this.head?.hash;\n let nextSnaps = [snapToStart];\n let done;\n if (!snapToStart) {\n done = true;\n }\n\n const iterator: AsyncIterator<Snap> = {\n next: async () => {\n if (done) {\n return { value: undefined, done };\n }\n const currSnapId = nextSnaps.shift();\n const snap = await this.loadSnap(currSnapId);\n if (snap.parents && snap.parents.length) {\n if (options.firstParentOnly) {\n nextSnaps.push(snap.parents[0]);\n } else {\n nextSnaps = nextSnaps.concat(snap.parents);\n }\n }\n if (!nextSnaps.length) {\n done = true;\n } else if (options.stopFn) {\n done = await options.stopFn(snap);\n }\n return { value: snap, done: undefined };\n },\n };\n return {\n [Symbol.asyncIterator]: () => iterator,\n };\n }\n\n /**\n * traverse recursively from the provided snap (or head) upwards until it finds a tag\n * @param snapToStartFrom\n */\n async getClosestTag(snapToStartFrom?: string): Promise<Tag | undefined> {\n const tagsHashMap = this.tags.getHashMap();\n const stopFn = async (snap: Snap) => {\n if (tagsHashMap.has(snap.hash)) {\n return true;\n }\n return false;\n };\n const iterable = this.snapsIterable(snapToStartFrom, { firstParentOnly: true, stopFn });\n const snaps: Snap[] = [];\n for await (const snap of iterable) {\n snaps.push(snap);\n }\n if (snaps.length) {\n const hashOfLastSnap = snaps[snaps.length - 1].hash;\n return tagsHashMap.get(hashOfLastSnap);\n }\n return undefined;\n }\n\n /**\n * checkout the component to a different version in its working tree.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n checkout(version: SemVer) {}\n\n /**\n * examine difference between two components.\n */\n // diff(other: Component): Difference {}\n\n /**\n * merge two different components\n */\n // merge(other: Component): Component {}\n\n /**\n * write a component to a given file system.\n * @param path root path to write the component\n * @param fs instance of any fs to use.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n write(path: string, fs?: AnyFS) {}\n\n /**\n *\n * Check if 2 components are equal\n * @param {Component} component\n * @returns {boolean}\n * @memberof Component\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n equals(component: Component): boolean {\n return component.id.toString() === this.id.toString();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["component-context.ts"],"names":["ComponentContext","ComponentModel","empty","ComponentDescriptorContext","undefined","useComponentDescriptor"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,gBAA+C,gBAAG,4BAA8BC,iCAAeC,KAAf,EAA9B,CAAxD;;AACA,MAAMC,0BAA0E,gBAAG,4BAExFC,SAFwF,CAAnF;;;AAIA,MAAMC,sBAAsB,GAAG,MAAM,yBAAWF,0BAAX,CAArC","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from '../component-model';\n\nexport const ComponentContext: React.Context<ComponentModel> = createContext<ComponentModel>(ComponentModel.empty());\nexport const ComponentDescriptorContext: React.Context<ComponentDescriptor | undefined> = createContext<\n ComponentDescriptor | undefined\n>(undefined);\n\nexport const useComponentDescriptor = () => useContext(ComponentDescriptorContext)"]}
|
|
1
|
+
{"version":3,"sources":["component-context.ts"],"names":["ComponentContext","ComponentModel","empty","ComponentDescriptorContext","undefined","useComponentDescriptor"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,gBAA+C,gBAAG,4BAA8BC,iCAAeC,KAAf,EAA9B,CAAxD;;AACA,MAAMC,0BAA0E,gBAAG,4BAExFC,SAFwF,CAAnF;;;AAIA,MAAMC,sBAAsB,GAAG,MAAM,yBAAWF,0BAAX,CAArC","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from '../component-model';\n\nexport const ComponentContext: React.Context<ComponentModel> = createContext<ComponentModel>(ComponentModel.empty());\nexport const ComponentDescriptorContext: React.Context<ComponentDescriptor | undefined> = createContext<\n ComponentDescriptor | undefined\n>(undefined);\n\nexport const useComponentDescriptor = () => useContext(ComponentDescriptorContext);\n"]}
|
|
@@ -2,7 +2,14 @@ import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
|
2
2
|
import { ComponentModel } from './component-model';
|
|
3
3
|
import { ComponentError } from './component-error';
|
|
4
4
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
5
|
-
export declare function useComponentQuery(componentId: string, host: string
|
|
5
|
+
export declare function useComponentQuery(componentId: string, host: string, filters?: {
|
|
6
|
+
log?: {
|
|
7
|
+
logType?: string;
|
|
8
|
+
logOffset?: number;
|
|
9
|
+
logLimit?: number;
|
|
10
|
+
logHead?: string;
|
|
11
|
+
};
|
|
12
|
+
}): {
|
|
6
13
|
componentDescriptor: ComponentDescriptor | undefined;
|
|
7
14
|
component: ComponentModel | undefined;
|
|
8
15
|
error: ComponentError | undefined;
|
|
@@ -103,7 +103,7 @@ const componentFields = (0, _client().gql)`
|
|
|
103
103
|
id {
|
|
104
104
|
...componentIdFields
|
|
105
105
|
}
|
|
106
|
-
aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder"]) {
|
|
106
|
+
aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder", "teambit.envs/envs"]) {
|
|
107
107
|
# 'id' property in gql refers to a *global* identifier and used for caching.
|
|
108
108
|
# this makes aspect data cache under the same key, even when they are under different components.
|
|
109
109
|
# renaming the property fixes that.
|
|
@@ -132,13 +132,14 @@ const componentFields = (0, _client().gql)`
|
|
|
132
132
|
id
|
|
133
133
|
icon
|
|
134
134
|
}
|
|
135
|
-
logs(type: $logType, offset: $logOffset, limit: $logLimit) {
|
|
135
|
+
logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead) {
|
|
136
136
|
message
|
|
137
137
|
username
|
|
138
138
|
email
|
|
139
139
|
date
|
|
140
140
|
hash
|
|
141
141
|
tag
|
|
142
|
+
onLane
|
|
142
143
|
}
|
|
143
144
|
preview {
|
|
144
145
|
includesEnvTemplate
|
|
@@ -147,7 +148,14 @@ const componentFields = (0, _client().gql)`
|
|
|
147
148
|
${componentIdFields}
|
|
148
149
|
`;
|
|
149
150
|
const GET_COMPONENT = (0, _client().gql)`
|
|
150
|
-
query Component(
|
|
151
|
+
query Component(
|
|
152
|
+
$id: String!
|
|
153
|
+
$extensionId: String!
|
|
154
|
+
$logType: String
|
|
155
|
+
$logOffset: Int
|
|
156
|
+
$logLimit: Int
|
|
157
|
+
$logHead: String
|
|
158
|
+
) {
|
|
151
159
|
getHost(id: $extensionId) {
|
|
152
160
|
id # used for GQL caching
|
|
153
161
|
get(id: $id) {
|
|
@@ -158,7 +166,7 @@ const GET_COMPONENT = (0, _client().gql)`
|
|
|
158
166
|
${componentFields}
|
|
159
167
|
`;
|
|
160
168
|
const SUB_SUBSCRIPTION_ADDED = (0, _client().gql)`
|
|
161
|
-
subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int) {
|
|
169
|
+
subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String) {
|
|
162
170
|
componentAdded {
|
|
163
171
|
component {
|
|
164
172
|
...componentFields
|
|
@@ -168,7 +176,7 @@ const SUB_SUBSCRIPTION_ADDED = (0, _client().gql)`
|
|
|
168
176
|
${componentFields}
|
|
169
177
|
`;
|
|
170
178
|
const SUB_COMPONENT_CHANGED = (0, _client().gql)`
|
|
171
|
-
subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int) {
|
|
179
|
+
subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String) {
|
|
172
180
|
componentChanged {
|
|
173
181
|
component {
|
|
174
182
|
...componentFields
|
|
@@ -189,7 +197,7 @@ const SUB_COMPONENT_REMOVED = (0, _client().gql)`
|
|
|
189
197
|
`;
|
|
190
198
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
191
199
|
|
|
192
|
-
function useComponentQuery(componentId, host) {
|
|
200
|
+
function useComponentQuery(componentId, host, filters) {
|
|
193
201
|
var _data$getHost;
|
|
194
202
|
|
|
195
203
|
const idRef = (0, _react().useRef)(componentId);
|
|
@@ -200,10 +208,10 @@ function useComponentQuery(componentId, host) {
|
|
|
200
208
|
loading,
|
|
201
209
|
subscribeToMore
|
|
202
210
|
} = (0, _uiFoundationUiHooks().useDataQuery)(GET_COMPONENT, {
|
|
203
|
-
variables: {
|
|
211
|
+
variables: _objectSpread({
|
|
204
212
|
id: componentId,
|
|
205
213
|
extensionId: host
|
|
206
|
-
}
|
|
214
|
+
}, (filters === null || filters === void 0 ? void 0 : filters.log) || {})
|
|
207
215
|
});
|
|
208
216
|
(0, _react().useEffect)(() => {
|
|
209
217
|
// @TODO @Kutner fix subscription for scope
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["use-component-query.ts"],"names":["componentIdFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","idRef","current","data","error","loading","subscribeToMore","variables","id","extensionId","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","aspectList","entries","aspects","fromObject","componentDescriptor","ComponentDescriptor","toString","undefined","ComponentModel","from","ComponentError","message"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AA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,OAAO,kCACFH,IAAI,CAACG,OADH;AAELC,cAAAA,GAAG,EAAE;AAFA;AAFT;AAOD;;AAED,eAAOJ,IAAP;AACD;AAtBkC,KAAD,CAApC;AAyBA,WAAO,MAAM;AACXS,MAAAA,YAAY;AACZZ,MAAAA,aAAa;AACbkB,MAAAA,YAAY;AACb,KAJD;AAKD,GAlFD,EAkFG,EAlFH;AAoFA,QAAMQ,YAAY,GAAGjC,IAAH,aAAGA,IAAH,wCAAGA,IAAI,CAAEa,OAAT,kDAAG,cAAeC,GAApC;AACA,SAAO,sBAAQ,MAAM;AACnB,UAAMoB,UAAU,GAAG;AACjBC,MAAAA,OAAO,EAAEF,YAAF,aAAEA,YAAF,uBAAEA,YAAY,CAAEG;AADN,KAAnB;;AAGA,UAAM/B,EAAE,GAAG4B,YAAY,IAAIV,2BAAYc,UAAZ,CAAuBJ,YAAY,CAAC5B,EAApC,CAA3B;;AACA,WAAO;AACLiC,MAAAA,mBAAmB,EAAEjC,EAAE,GAAGkC,2CAAoBF,UAApB,CAA+B;AAAEhC,QAAAA,EAAE,EAAEA,EAAE,CAACmC,QAAH,EAAN;AAAqBN,QAAAA;AAArB,OAA/B,CAAH,GAAuEO,SADzF;AAELxB,MAAAA,SAAS,EAAEgB,YAAY,GAAGS,iCAAeC,IAAf,iCAAyBV,YAAzB;AAAuCpC,QAAAA;AAAvC,SAAH,GAAoD4C,SAFtE;AAGL;AACAxC,MAAAA,KAAK,EAAEA,KAAK,GACR,KAAI2C,gCAAJ,EAAmB,GAAnB,EAAwB3C,KAAK,CAAC4C,OAA9B,CADQ,GAER,CAACZ,YAAD,IAAiB,CAAC/B,OAAlB,GACA,KAAI0C,gCAAJ,EAAmB,GAAnB,CADA,GAEAH;AARC,KAAP;AAUD,GAfM,EAeJ,CAACR,YAAD,EAAepC,IAAf,EAAqBI,KAArB,CAfI,CAAP;AAgBD","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\nconst componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nconst componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n aspects(include: [\"teambit.preview/preview\", \"teambit.pipelines/builder\"]) {\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 aspectId: id\n aspectData: data\n }\n packageName\n elementsUrl\n description\n labels\n displayName\n latest\n server {\n env\n url\n }\n buildStatus\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n env {\n id\n icon\n }\n logs(type: $logType, offset: $logOffset, limit: $logLimit) {\n message\n username\n email\n date\n hash\n tag\n }\n preview {\n includesEnvTemplate\n }\n }\n ${componentIdFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component($id: String!, $extensionId: String!, $logType: String, $logOffset: Int, $logLimit: Int) {\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) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int) {\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`;\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) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host },\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,\n };\n const id = rawComponent && ComponentID.fromObject(rawComponent.id);\n return {\n componentDescriptor: id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined,\n component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,\n // eslint-disable-next-line\n error: error\n ? new ComponentError(500, error.message)\n : !rawComponent && !loading\n ? new ComponentError(404)\n : undefined,\n };\n }, [rawComponent, host, error]);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["use-component-query.ts"],"names":["componentIdFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","filters","idRef","current","data","error","loading","subscribeToMore","variables","id","extensionId","log","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","aspectList","entries","aspects","fromObject","componentDescriptor","ComponentDescriptor","toString","undefined","ComponentModel","from","ComponentError","message"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEA,MAAMA,iBAAiB,GAAG,kBAAI;AAC9B;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,eAAe,GAAG,kBAAI;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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,GAlFD,EAkFG,EAlFH;AAoFA,QAAMQ,YAAY,GAAGlC,IAAH,aAAGA,IAAH,wCAAGA,IAAI,CAAEc,OAAT,kDAAG,cAAeC,GAApC;AACA,SAAO,sBAAQ,MAAM;AACnB,UAAMoB,UAAU,GAAG;AACjBC,MAAAA,OAAO,EAAEF,YAAF,aAAEA,YAAF,uBAAEA,YAAY,CAAEG;AADN,KAAnB;;AAGA,UAAMhC,EAAE,GAAG6B,YAAY,IAAIV,2BAAYc,UAAZ,CAAuBJ,YAAY,CAAC7B,EAApC,CAA3B;;AACA,WAAO;AACLkC,MAAAA,mBAAmB,EAAElC,EAAE,GAAGmC,2CAAoBF,UAApB,CAA+B;AAAEjC,QAAAA,EAAE,EAAEA,EAAE,CAACoC,QAAH,EAAN;AAAqBN,QAAAA;AAArB,OAA/B,CAAH,GAAuEO,SADzF;AAELxB,MAAAA,SAAS,EAAEgB,YAAY,GAAGS,iCAAeC,IAAf,iCAAyBV,YAAzB;AAAuCtC,QAAAA;AAAvC,SAAH,GAAoD8C,SAFtE;AAGL;AACAzC,MAAAA,KAAK,EAAEA,KAAK,GACR,KAAI4C,gCAAJ,EAAmB,GAAnB,EAAwB5C,KAAK,CAAC6C,OAA9B,CADQ,GAER,CAACZ,YAAD,IAAiB,CAAChC,OAAlB,GACA,KAAI2C,gCAAJ,EAAmB,GAAnB,CADA,GAEAH;AARC,KAAP;AAUD,GAfM,EAeJ,CAACR,YAAD,EAAetC,IAAf,EAAqBK,KAArB,CAfI,CAAP;AAgBD","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\nconst componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nconst componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n aspects(include: [\"teambit.preview/preview\", \"teambit.pipelines/builder\", \"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 aspectId: id\n aspectData: data\n }\n packageName\n elementsUrl\n description\n labels\n displayName\n latest\n server {\n env\n url\n }\n buildStatus\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n env {\n id\n icon\n }\n logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead) {\n message\n username\n email\n date\n hash\n tag\n onLane\n }\n preview {\n includesEnvTemplate\n }\n }\n ${componentIdFields}\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 ) {\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) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String) {\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`;\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?: { log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string } }\n) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host, ...(filters?.log || {}) },\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,\n };\n const id = rawComponent && ComponentID.fromObject(rawComponent.id);\n return {\n componentDescriptor: id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined,\n component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,\n // eslint-disable-next-line\n error: error\n ? new ComponentError(500, error.message)\n : !rawComponent && !loading\n ? new ComponentError(404)\n : undefined,\n };\n }, [rawComponent, host, error]);\n}\n"]}
|
package/dist/ui/use-component.js
CHANGED
|
@@ -25,6 +25,16 @@ function _uiFoundationUiReactRouter() {
|
|
|
25
25
|
return data;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
function _lanesUi() {
|
|
29
|
+
const data = require("@teambit/lanes.ui.lanes");
|
|
30
|
+
|
|
31
|
+
_lanesUi = function () {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
function _useComponentQuery() {
|
|
29
39
|
const data = require("./use-component-query");
|
|
30
40
|
|
|
@@ -36,6 +46,8 @@ function _useComponentQuery() {
|
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
function useComponent(host, id) {
|
|
49
|
+
var _lanesContext$current, _lanesContext$current2;
|
|
50
|
+
|
|
39
51
|
const {
|
|
40
52
|
params: {
|
|
41
53
|
componentId
|
|
@@ -43,11 +55,20 @@ function useComponent(host, id) {
|
|
|
43
55
|
} = (0, _reactRouterDom().useRouteMatch)();
|
|
44
56
|
const query = (0, _uiFoundationUiReactRouter().useQuery)();
|
|
45
57
|
const version = query.get('version') || undefined;
|
|
58
|
+
const lanesContext = (0, _lanesUi().useLanesContext)();
|
|
46
59
|
const targetId = (id === null || id === void 0 ? void 0 : id.toString({
|
|
47
60
|
ignoreVersion: true
|
|
48
61
|
})) || componentId;
|
|
49
62
|
if (!targetId) throw new TypeError('useComponent received no component id');
|
|
50
|
-
|
|
63
|
+
const currentLane = lanesContext === null || lanesContext === void 0 ? void 0 : lanesContext.currentLane; // when on a lane, always fetch all the logs starting from the 'head' version
|
|
64
|
+
|
|
65
|
+
const logHead = lanesContext === null || lanesContext === void 0 ? void 0 : (_lanesContext$current = lanesContext.currentLane) === null || _lanesContext$current === void 0 ? void 0 : (_lanesContext$current2 = _lanesContext$current.components.find(component => component.model.id.fullName === targetId)) === null || _lanesContext$current2 === void 0 ? void 0 : _lanesContext$current2.model.id.version;
|
|
66
|
+
const logFilters = currentLane ? {
|
|
67
|
+
log: {
|
|
68
|
+
logHead
|
|
69
|
+
}
|
|
70
|
+
} : undefined;
|
|
71
|
+
return (0, _useComponentQuery().useComponentQuery)(withVersion(targetId, version), host, logFilters);
|
|
51
72
|
}
|
|
52
73
|
|
|
53
74
|
function withVersion(id, version) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["use-component.tsx"],"names":["useComponent","host","id","params","componentId","query","version","get","undefined","targetId","toString","ignoreVersion","TypeError","withVersion","includes"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;
|
|
1
|
+
{"version":3,"sources":["use-component.tsx"],"names":["useComponent","host","id","params","componentId","query","version","get","undefined","lanesContext","targetId","toString","ignoreVersion","TypeError","currentLane","logHead","components","find","component","model","fullName","logFilters","log","withVersion","includes"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAYO,SAASA,YAAT,CAAsBC,IAAtB,EAAoCC,EAApC,EAAiE;AAAA;;AACtE,QAAM;AACJC,IAAAA,MAAM,EAAE;AAAEC,MAAAA;AAAF;AADJ,MAEF,sCAFJ;AAGA,QAAMC,KAAK,GAAG,4CAAd;AACA,QAAMC,OAAO,GAAGD,KAAK,CAACE,GAAN,CAAU,SAAV,KAAwBC,SAAxC;AACA,QAAMC,YAAY,GAAG,iCAArB;AACA,QAAMC,QAAQ,GAAG,CAAAR,EAAE,SAAF,IAAAA,EAAE,WAAF,YAAAA,EAAE,CAAES,QAAJ,CAAa;AAAEC,IAAAA,aAAa,EAAE;AAAjB,GAAb,MAAyCR,WAA1D;AACA,MAAI,CAACM,QAAL,EAAe,MAAM,IAAIG,SAAJ,CAAc,uCAAd,CAAN;AACf,QAAMC,WAAW,GAAGL,YAAH,aAAGA,YAAH,uBAAGA,YAAY,CAAEK,WAAlC,CATsE,CAUtE;;AACA,QAAMC,OAAO,GAAGN,YAAH,aAAGA,YAAH,gDAAGA,YAAY,CAAEK,WAAjB,oFAAG,sBAA2BE,UAA3B,CAAsCC,IAAtC,CAA4CC,SAAD,IAAeA,SAAS,CAACC,KAAV,CAAgBjB,EAAhB,CAAmBkB,QAAnB,KAAgCV,QAA1F,CAAH,2DAAG,uBACZS,KADY,CACNjB,EADM,CACHI,OADb;AAEA,QAAMe,UAAU,GAAGP,WAAW,GAC1B;AACEQ,IAAAA,GAAG,EAAE;AACHP,MAAAA;AADG;AADP,GAD0B,GAM1BP,SANJ;AAQA,SAAO,4CAAkBe,WAAW,CAACb,QAAD,EAAWJ,OAAX,CAA7B,EAAkDL,IAAlD,EAAwDoB,UAAxD,CAAP;AACD;;AAED,SAASE,WAAT,CAAqBrB,EAArB,EAAiCI,OAAjC,EAAmD;AACjD,MAAI,CAACA,OAAL,EAAc,OAAOJ,EAAP;AACd,MAAIA,EAAE,CAACsB,QAAH,CAAY,GAAZ,CAAJ,EAAsB,OAAOtB,EAAP;AACtB,SAAQ,GAAEA,EAAG,IAAGI,OAAQ,EAAxB;AACD","sourcesContent":["import { useRouteMatch } from 'react-router-dom';\nimport { ComponentID } from '@teambit/component-id';\nimport { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\nimport { useLanesContext } from '@teambit/lanes.ui.lanes';\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\nimport { useComponentQuery } from './use-component-query';\n\nexport type Component = {\n component?: ComponentModel;\n error?: ComponentError;\n componentDescriptor?: ComponentDescriptor;\n};\n\ntype ComponentRoute = {\n componentId?: string;\n};\n\nexport function useComponent(host: string, id?: ComponentID): Component {\n const {\n params: { componentId },\n } = useRouteMatch<ComponentRoute>();\n const query = useQuery();\n const version = query.get('version') || undefined;\n const lanesContext = useLanesContext();\n const targetId = id?.toString({ ignoreVersion: true }) || componentId;\n if (!targetId) throw new TypeError('useComponent received no component id');\n const currentLane = lanesContext?.currentLane;\n // when on a lane, always fetch all the logs starting from the 'head' version\n const logHead = lanesContext?.currentLane?.components.find((component) => component.model.id.fullName === targetId)\n ?.model.id.version;\n const logFilters = currentLane\n ? {\n log: {\n logHead,\n },\n }\n : undefined;\n\n return useComponentQuery(withVersion(targetId, version), host, logFilters);\n}\n\nfunction withVersion(id: string, version?: string) {\n if (!version) return id;\n if (id.includes('@')) return id;\n return `${id}@${version}`;\n}\n"]}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/component",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.670",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/component/component",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.component",
|
|
8
8
|
"name": "component",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.670"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/any-fs": "0.0.5",
|
|
@@ -29,37 +29,37 @@
|
|
|
29
29
|
"@teambit/base-ui.routing.routing-provider": "1.0.0",
|
|
30
30
|
"@teambit/component-id": "0.0.401",
|
|
31
31
|
"@teambit/ui-foundation.ui.menu-widget-icon": "0.0.488",
|
|
32
|
-
"@teambit/aspect-loader": "0.0.
|
|
32
|
+
"@teambit/aspect-loader": "0.0.670",
|
|
33
33
|
"@teambit/legacy-bit-id": "0.0.398",
|
|
34
34
|
"@teambit/toolbox.string.capitalize": "0.0.483",
|
|
35
|
-
"@teambit/cli": "0.0.
|
|
36
|
-
"@teambit/config": "0.0.
|
|
37
|
-
"@teambit/express": "0.0.
|
|
38
|
-
"@teambit/graphql": "0.0.
|
|
35
|
+
"@teambit/cli": "0.0.452",
|
|
36
|
+
"@teambit/config": "0.0.465",
|
|
37
|
+
"@teambit/express": "0.0.546",
|
|
38
|
+
"@teambit/graphql": "0.0.670",
|
|
39
39
|
"@teambit/bit-error": "0.0.394",
|
|
40
|
-
"@teambit/command-bar": "0.0.
|
|
41
|
-
"@teambit/preview": "0.0.
|
|
42
|
-
"@teambit/pubsub": "0.0.
|
|
40
|
+
"@teambit/command-bar": "0.0.670",
|
|
41
|
+
"@teambit/preview": "0.0.670",
|
|
42
|
+
"@teambit/pubsub": "0.0.670",
|
|
43
43
|
"@teambit/ui-foundation.ui.is-browser": "0.0.486",
|
|
44
44
|
"@teambit/ui-foundation.ui.main-dropdown": "0.0.486",
|
|
45
45
|
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.488",
|
|
46
46
|
"@teambit/ui-foundation.ui.use-box.menu": "0.0.111",
|
|
47
|
-
"@teambit/ui": "0.0.
|
|
47
|
+
"@teambit/ui": "0.0.670",
|
|
48
48
|
"@teambit/component-issues": "0.0.46",
|
|
49
49
|
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.487",
|
|
50
50
|
"@teambit/cli-table": "0.0.33",
|
|
51
|
-
"@teambit/component-descriptor": "0.0.
|
|
51
|
+
"@teambit/component-descriptor": "0.0.13",
|
|
52
|
+
"@teambit/lanes.ui.lanes": "0.0.12",
|
|
52
53
|
"@teambit/ui-foundation.ui.react-router.use-query": "0.0.486",
|
|
53
54
|
"@teambit/design.ui.empty-box": "0.0.353",
|
|
54
55
|
"@teambit/harmony.ui.aspect-box": "0.0.486",
|
|
55
56
|
"@teambit/design.ui.pages.not-found": "0.0.353",
|
|
56
57
|
"@teambit/design.ui.pages.server-error": "0.0.353",
|
|
57
|
-
"@teambit/compositions": "0.0.
|
|
58
|
-
"@teambit/deprecation": "0.0.
|
|
59
|
-
"@teambit/envs": "0.0.
|
|
60
|
-
"@teambit/legacy-component-log": "0.0.
|
|
61
|
-
"@teambit/component.ui.version-dropdown": "0.0.
|
|
62
|
-
"@teambit/lanes.ui.lanes": "0.0.11",
|
|
58
|
+
"@teambit/compositions": "0.0.670",
|
|
59
|
+
"@teambit/deprecation": "0.0.670",
|
|
60
|
+
"@teambit/envs": "0.0.670",
|
|
61
|
+
"@teambit/legacy-component-log": "0.0.392",
|
|
62
|
+
"@teambit/component.ui.version-dropdown": "0.0.496",
|
|
63
63
|
"@teambit/ui-foundation.ui.full-loader": "0.0.486",
|
|
64
64
|
"@teambit/ui-foundation.ui.use-box.dropdown": "0.0.111",
|
|
65
65
|
"@teambit/ui-foundation.ui.react-router.extend-path": "0.0.486"
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"@apollo/client": "^3.0.0",
|
|
84
|
-
"@teambit/legacy": "1.0.
|
|
84
|
+
"@teambit/legacy": "1.0.231",
|
|
85
85
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
86
86
|
"react": "^16.8.0 || ^17.0.0"
|
|
87
87
|
},
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"react": "-"
|
|
110
110
|
},
|
|
111
111
|
"peerDependencies": {
|
|
112
|
-
"@teambit/legacy": "1.0.
|
|
112
|
+
"@teambit/legacy": "1.0.231",
|
|
113
113
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
114
114
|
"react": "^16.8.0 || ^17.0.0"
|
|
115
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.
|
|
1
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.670/dist/component.docs.mdx')]
|
|
@@ -8,4 +8,4 @@ export const ComponentDescriptorContext: React.Context<ComponentDescriptor | und
|
|
|
8
8
|
ComponentDescriptor | undefined
|
|
9
9
|
>(undefined);
|
|
10
10
|
|
|
11
|
-
export const useComponentDescriptor = () => useContext(ComponentDescriptorContext)
|
|
11
|
+
export const useComponentDescriptor = () => useContext(ComponentDescriptorContext);
|
|
@@ -20,7 +20,7 @@ const componentFields = gql`
|
|
|
20
20
|
id {
|
|
21
21
|
...componentIdFields
|
|
22
22
|
}
|
|
23
|
-
aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder"]) {
|
|
23
|
+
aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder", "teambit.envs/envs"]) {
|
|
24
24
|
# 'id' property in gql refers to a *global* identifier and used for caching.
|
|
25
25
|
# this makes aspect data cache under the same key, even when they are under different components.
|
|
26
26
|
# renaming the property fixes that.
|
|
@@ -49,13 +49,14 @@ const componentFields = gql`
|
|
|
49
49
|
id
|
|
50
50
|
icon
|
|
51
51
|
}
|
|
52
|
-
logs(type: $logType, offset: $logOffset, limit: $logLimit) {
|
|
52
|
+
logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead) {
|
|
53
53
|
message
|
|
54
54
|
username
|
|
55
55
|
email
|
|
56
56
|
date
|
|
57
57
|
hash
|
|
58
58
|
tag
|
|
59
|
+
onLane
|
|
59
60
|
}
|
|
60
61
|
preview {
|
|
61
62
|
includesEnvTemplate
|
|
@@ -65,7 +66,14 @@ const componentFields = gql`
|
|
|
65
66
|
`;
|
|
66
67
|
|
|
67
68
|
const GET_COMPONENT = gql`
|
|
68
|
-
query Component(
|
|
69
|
+
query Component(
|
|
70
|
+
$id: String!
|
|
71
|
+
$extensionId: String!
|
|
72
|
+
$logType: String
|
|
73
|
+
$logOffset: Int
|
|
74
|
+
$logLimit: Int
|
|
75
|
+
$logHead: String
|
|
76
|
+
) {
|
|
69
77
|
getHost(id: $extensionId) {
|
|
70
78
|
id # used for GQL caching
|
|
71
79
|
get(id: $id) {
|
|
@@ -77,7 +85,7 @@ const GET_COMPONENT = gql`
|
|
|
77
85
|
`;
|
|
78
86
|
|
|
79
87
|
const SUB_SUBSCRIPTION_ADDED = gql`
|
|
80
|
-
subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int) {
|
|
88
|
+
subscription OnComponentAdded($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String) {
|
|
81
89
|
componentAdded {
|
|
82
90
|
component {
|
|
83
91
|
...componentFields
|
|
@@ -88,7 +96,7 @@ const SUB_SUBSCRIPTION_ADDED = gql`
|
|
|
88
96
|
`;
|
|
89
97
|
|
|
90
98
|
const SUB_COMPONENT_CHANGED = gql`
|
|
91
|
-
subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int) {
|
|
99
|
+
subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int, $logHead: String) {
|
|
92
100
|
componentChanged {
|
|
93
101
|
component {
|
|
94
102
|
...componentFields
|
|
@@ -110,11 +118,15 @@ const SUB_COMPONENT_REMOVED = gql`
|
|
|
110
118
|
`;
|
|
111
119
|
|
|
112
120
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
113
|
-
export function useComponentQuery(
|
|
121
|
+
export function useComponentQuery(
|
|
122
|
+
componentId: string,
|
|
123
|
+
host: string,
|
|
124
|
+
filters?: { log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string } }
|
|
125
|
+
) {
|
|
114
126
|
const idRef = useRef(componentId);
|
|
115
127
|
idRef.current = componentId;
|
|
116
128
|
const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {
|
|
117
|
-
variables: { id: componentId, extensionId: host },
|
|
129
|
+
variables: { id: componentId, extensionId: host, ...(filters?.log || {}) },
|
|
118
130
|
});
|
|
119
131
|
|
|
120
132
|
useEffect(() => {
|
package/ui/use-component.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { useRouteMatch } from 'react-router-dom';
|
|
|
2
2
|
import { ComponentID } from '@teambit/component-id';
|
|
3
3
|
import { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';
|
|
4
4
|
import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
5
|
+
import { useLanesContext } from '@teambit/lanes.ui.lanes';
|
|
5
6
|
import { ComponentModel } from './component-model';
|
|
6
7
|
import { ComponentError } from './component-error';
|
|
7
8
|
import { useComponentQuery } from './use-component-query';
|
|
@@ -22,10 +23,22 @@ export function useComponent(host: string, id?: ComponentID): Component {
|
|
|
22
23
|
} = useRouteMatch<ComponentRoute>();
|
|
23
24
|
const query = useQuery();
|
|
24
25
|
const version = query.get('version') || undefined;
|
|
25
|
-
|
|
26
|
+
const lanesContext = useLanesContext();
|
|
26
27
|
const targetId = id?.toString({ ignoreVersion: true }) || componentId;
|
|
27
28
|
if (!targetId) throw new TypeError('useComponent received no component id');
|
|
28
|
-
|
|
29
|
+
const currentLane = lanesContext?.currentLane;
|
|
30
|
+
// when on a lane, always fetch all the logs starting from the 'head' version
|
|
31
|
+
const logHead = lanesContext?.currentLane?.components.find((component) => component.model.id.fullName === targetId)
|
|
32
|
+
?.model.id.version;
|
|
33
|
+
const logFilters = currentLane
|
|
34
|
+
? {
|
|
35
|
+
log: {
|
|
36
|
+
logHead,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
: undefined;
|
|
40
|
+
|
|
41
|
+
return useComponentQuery(withVersion(targetId, version), host, logFilters);
|
|
29
42
|
}
|
|
30
43
|
|
|
31
44
|
function withVersion(id: string, version?: string) {
|
|
Binary file
|