Skip to content

Commit 1475f73

Browse files
authored
Component Types View structure and naming improvements (#2004)
This PR fixes #2003. Signed-off-by: Denis Golovin dgolovin@redhat.com
1 parent 3ac01b9 commit 1475f73

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,12 @@
754754
},
755755
{
756756
"command": "openshift.componentType.openStarterProjectRepository",
757-
"title": "Open Sample Project repository",
757+
"title": "Open in Browser",
758758
"category": "OpenShift"
759759
},
760760
{
761761
"command": "openshift.componentType.cloneStarterProjectRepository",
762-
"title": "Clone Sample Project repository to workspace",
762+
"title": "Clone to Workspace",
763763
"category": "OpenShift"
764764
},
765765
{
@@ -1314,12 +1314,12 @@
13141314
},
13151315
{
13161316
"command": "openshift.componentType.openStarterProjectRepository",
1317-
"when": "view == openshiftComponentTypesView && viewItem == s2iImageStreamTag || viewItem == devfileStarterProject",
1317+
"when": "view == openshiftComponentTypesView && viewItem == s2iSampleProject || viewItem == devfileStarterProject",
13181318
"group": "1@0"
13191319
},
13201320
{
13211321
"command": "openshift.componentType.cloneStarterProjectRepository",
1322-
"when": "view == openshiftComponentTypesView && viewItem == s2iImageStreamTag || viewItem == devfileStarterProject",
1322+
"when": "view == openshiftComponentTypesView && viewItem == s2iSampleProject || viewItem == devfileStarterProject",
13231323
"group": "1@1"
13241324
},
13251325
{

src/component.ts

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import {
3131
isImageStreamTag,
3232
isRegistry,
3333
isS2iComponent,
34+
isSampleProject,
3435
Registry,
35-
S2iComponentType
36+
S2iComponentType,
37+
SampleProject
3638
} from './odo/componentType';
3739
import {
3840
isStarterProject,
@@ -42,12 +44,15 @@ import { vsCommand, VsCommandError } from './vscommand';
4244
import { Cluster } from '@kubernetes/client-node/dist/config_types';
4345
import { KubeConfig } from '@kubernetes/client-node';
4446

45-
type ComponentType = S2iComponentType | DevfileComponentType | ImageStreamTag | StarterProject | Cluster | Registry;
47+
type ExampleProject = SampleProject | StarterProject;
48+
type ComponentType = DevfileComponentType | ImageStreamTag | ExampleProject | Cluster | Registry;
49+
4650

4751
export enum ContextType {
4852
S2I_COMPONENT_TYPE = 's2iComponentType',
4953
DEVFILE_COMPONENT_TYPE = 'devfileComponentType',
5054
S2I_IMAGE_STREAM_TAG = 's2iImageStreamTag',
55+
S2I_SAMPLE_PROJECT = 's2iSampleProject',
5156
DEVFILE_STARTER_PROJECT = 'devfileStarterProject',
5257
DEVFILE_REGISTRY = 'devfileRegistry',
5358
OFFLINE_CLUSTER = 'clusterOffline',
@@ -93,12 +98,13 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
9398
return {
9499
label: `${element.server}`,
95100
collapsibleState: TreeItemCollapsibleState.Collapsed,
101+
tooltip: `Current Cluster\n Server: ${element.server}`,
96102
}
97103
}
98104
if (isRegistry(element)) {
99105
return {
100106
label: element.Name,
101-
description: element.URL,
107+
tooltip: `Devfile Registry\nName: ${element.Name}\nURL: ${element.URL}`,
102108
collapsibleState: TreeItemCollapsibleState.Collapsed,
103109
}
104110
}
@@ -113,23 +119,38 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
113119
collapsibleState: TreeItemCollapsibleState.Collapsed,
114120
};
115121
}
122+
if (isSampleProject(element)) {
123+
const to = element.sampleRepo.lastIndexOf('.git');
124+
const from = element.sampleRepo.lastIndexOf('/');
125+
const projectName = element.sampleRepo.substring(from+1,to >0? to : undefined);
126+
return {
127+
label: projectName,
128+
contextValue: ContextType.S2I_SAMPLE_PROJECT,
129+
tooltip: `Sample Project\nName: ${projectName}\nRepository: ${element.sampleRepo}`,
130+
iconPath: {
131+
dark: Uri.file(path.join(__dirname, '..','..','images', 'component', 'start-project-dark.png')),
132+
light: Uri.file(path.join(__dirname, '..','..','images', 'component', 'start-project-light.png'))
133+
},
134+
}
135+
}
116136
if(isImageStreamTag(element)) {
117137
return {
118138
label: element.annotations['openshift.io/display-name']? element.annotations['openshift.io/display-name'] : element.name,
119139
contextValue: ContextType.S2I_IMAGE_STREAM_TAG,
120-
tooltip: element.annotations.description,
140+
tooltip: `Component Type\nName: ${element.name}\nKind: S2I\nDescription: ${element?.annotations.description?element.annotations.description:'n/a'}`,
121141
description: element.annotations.description,
122142
iconPath: {
123-
dark: Uri.file(path.join(__dirname, '..','..','images', 'component', 'start-project-dark.png')),
124-
light: Uri.file(path.join(__dirname, '..','..','images', 'component', 'start-project-light.png'))
143+
dark: Uri.file(path.join(__dirname, '..','..','images', 'component', 'component-type-dark.png')),
144+
light: Uri.file(path.join(__dirname, '..','..','images', 'component', 'component-type-light.png'))
125145
},
146+
collapsibleState: isSampleProject(element)? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.Collapsed,
126147
}
127148
}
128149
if(isStarterProject(element)) {
129150
return {
130151
label: element.name,
131152
contextValue: ContextType.DEVFILE_STARTER_PROJECT,
132-
tooltip: element.description,
153+
tooltip: `Starter Project\nName: ${element.name}\nDescription: ${element.description?element.description:'n/a'}`,
133154
description: element.description,
134155
iconPath: {
135156
dark: Uri.file(path.join(__dirname, '..','..','images', 'component', 'start-project-dark.png')),
@@ -138,13 +159,14 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
138159
}
139160
}
140161
return {
141-
label: `${element.DisplayName} (devfile)`,
162+
label: `${element.DisplayName}`,
142163
contextValue: ContextType.DEVFILE_COMPONENT_TYPE,
143164
iconPath: {
144165
dark: Uri.file(path.join(__dirname, '..','..','images', 'component', 'component-type-dark.png')),
145166
light: Uri.file(path.join(__dirname, '..','..','images', 'component', 'component-type-light.png'))
146167
},
147-
tooltip: element.Description,
168+
tooltip: `Component Type\nName: ${element.Name}\nKind: devfile\nDescription: ${element.Description ? element.Description : 'n/a'}`,
169+
description: element.Description,
148170
collapsibleState: this.registries.length > 1? TreeItemCollapsibleState.None : TreeItemCollapsibleState.Collapsed,
149171
};
150172
}
@@ -179,7 +201,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
179201
children = [cluster,...this.registries];
180202
} else if (isCluster(parent)) {
181203
const result: CliExitData = await this.odo.execute(Command.listCatalogComponentsJson());
182-
const builders = this.loadItems<ComponentTypesJson, ComponentType>(result, (data) => {
204+
const builders = this.loadItems<ComponentTypesJson, S2iComponentType>(result, (data) => {
183205
if (data.s2iItems) { // filter hidden tags
184206
data.s2iItems.forEach((s2iItem) => s2iItem.spec.imageStreamTags = s2iItem.spec.imageStreamTags.filter(tag => s2iItem.spec.nonHiddenTags.includes(tag.name)));
185207
} else { // when not logged or disconnected form cluster s2i items are not available
@@ -193,7 +215,6 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
193215
const result: CliExitData = await this.odo.execute(Command.listCatalogComponentsJson());
194216
children = this.loadItems<ComponentTypesJson, DevfileComponentType>(result, (data) => data.devfileItems);
195217
children = children.filter((element:DevfileComponentType) => element.Registry.Name === parent.Name);
196-
197218
} else if (isS2iComponent(parent)) {
198219
children = parent.spec.imageStreamTags.map((tag:ImageStreamTag) => {
199220
tag.typeName = parent.metadata.name;
@@ -202,11 +223,12 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
202223
} else if (isDevfileComponent(parent)){
203224
const result: CliExitData = await this.odo.execute(Command.describeCatalogComponent(parent.Name));
204225
children = this.loadItems<ComponentTypeDescription, StarterProject>(result, (data) => data.Data.starterProjects);
205-
206226
children = children.map((starter:StarterProject) => {
207227
starter.typeName = parent.Name;;
208228
return starter;
209229
});
230+
} else if (isImageStreamTag(parent)) {
231+
children = [parent.annotations];
210232
}
211233
return children;
212234
}
@@ -226,18 +248,18 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
226248
ComponentTypesView.instance.refresh();
227249
}
228250

229-
public static getSampleRepositoryUrl(element): string {
251+
public static getSampleRepositoryUrl(element: ExampleProject): string {
230252
let url: string;
231-
if(isImageStreamTag(element)) {
232-
url = element.annotations.sampleRepo;
253+
if(isSampleProject(element)) {
254+
url = element.sampleRepo;
233255
} else if(isStarterProject(element)) {
234256
url = Object.values(element.git.remotes).find((prop) => typeof prop === 'string');
235257
}
236258
return url;
237259
}
238260

239261
@vsCommand('openshift.componentType.openStarterProjectRepository')
240-
public static async openRepositoryURL(element: ComponentType): Promise<void | string> {
262+
public static async openRepositoryURL(element: ExampleProject): Promise<void | string> {
241263
const url: string = ComponentTypesView.getSampleRepositoryUrl(element);
242264
if (url) {
243265
try {
@@ -252,7 +274,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
252274
}
253275

254276
@vsCommand('openshift.componentType.cloneStarterProjectRepository')
255-
public static async cloneRepository(element: ComponentType): Promise<void | string> {
277+
public static async cloneRepository(element: ExampleProject): Promise<void | string> {
256278
const url: string = ComponentTypesView.getSampleRepositoryUrl(element);
257279
if (url) {
258280
try {

src/odo/componentType.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export function isImageStreamTag(tag: any): tag is ImageStreamTag {
4747
return tag.name && tag.annotations;
4848
}
4949

50+
export function isSampleProject(repo: any): repo is SampleProject {
51+
return repo?.sampleRepo;
52+
}
53+
5054
export function isCluster(cluster: any): cluster is Cluster {
5155
return cluster.name && cluster.server && cluster.skipTLSVerify !== undefined;
5256
}
@@ -67,6 +71,10 @@ export interface S2iComponentType {
6771
},
6872
}
6973

74+
export interface SampleProject {
75+
sampleRepo: string;
76+
}
77+
7078
export interface RegistryRef {
7179
Name: string;
7280
URL: Url;

0 commit comments

Comments
 (0)