Skip to content

Commit

Permalink
#484 highlight task connections on mous hover
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Jan 22, 2021
1 parent 4399ae7 commit 8f8d4da
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/webview/pipeline-preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ if (previousState) {
restore(previousState);
}

let highlightedSourceEdges: cytoscape.Collection;
let highlightedTargetEdges: cytoscape.Collection;

window.addEventListener('message', event => {

Expand Down Expand Up @@ -79,6 +81,36 @@ function startUpdatingState(): void {
});
}
});

cy.on('mouseover', 'node', (e) => {
const node = e.target;
const sourceEdges = node.connectedEdges(`edge[source = "${node.data().id}"]`);
const targetEdges = node.connectedEdges(`edge[target = "${node.data().id}"]`);
const theme = getTheme();
sourceEdges.select();
highlightedSourceEdges = sourceEdges;
highlightedTargetEdges = targetEdges;
sourceEdges.style('line-color', theme.sourceEdgesColor);
sourceEdges.style('target-arrow-color', theme.sourceEdgesColor);
sourceEdges.style('z-index', '100');

targetEdges.style('line-color', theme.targetEdgesColor);
targetEdges.style('target-arrow-color', theme.targetEdgesColor);
targetEdges.style('z-index', '100');
});

cy.on('mouseout', 'node', () => {
if (highlightedSourceEdges) {
highlightedSourceEdges.removeStyle('line-color');
highlightedSourceEdges.removeStyle('z-index');
highlightedSourceEdges.removeStyle('target-arrow-color');
}
if (highlightedTargetEdges) {
highlightedTargetEdges.removeStyle('line-color');
highlightedTargetEdges.removeStyle('z-index');
highlightedTargetEdges.removeStyle('target-arrow-color');
}
});
}

function restore(state: object): void {
Expand Down Expand Up @@ -124,7 +156,8 @@ function getTheme(): CyTheme {
result.fontSize = getComputedStyle(document.body).getPropertyValue('font-size');
result.fontFamily = getComputedStyle(document.body).getPropertyValue('font-family');
result.arrowColor = getComputedStyle(document.documentElement).getPropertyValue('--vscode-editor-selectionBackground');

result.targetEdgesColor = getComputedStyle(document.body).getPropertyValue('--vscode-charts-yellow');
result.sourceEdgesColor = getComputedStyle(document.body).getPropertyValue('--vscode-charts-green');
return result;
}

Expand All @@ -139,9 +172,13 @@ function getStyle(style: CyTheme): cytoscape.Stylesheet[] {
'font-family': style.fontFamily,
'font-size': style.fontSize,
'curve-style': 'taxi',
'taxi-direction': 'downward',
'taxi-turn': '50px',
'taxi-turn-min-distance': 1,
'edge-distances': 'node-position',
'target-arrow-shape': 'triangle',
'target-arrow-color': style.arrowColor,
}
} as unknown,
},
{
selector: 'edge[state = "Cancelled"]',
Expand Down
2 changes: 2 additions & 0 deletions src/webview/pipeline-preview/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ export interface CyTheme {
fontSize: string;
labelColor: string;
fontFamily: string;
targetEdgesColor: string;
sourceEdgesColor: string;
}
15 changes: 15 additions & 0 deletions src/yaml-support/tkn-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,21 @@ function collectRunAfter(taskNode: YamlMap, name: string): string[] {
}
}

const params = findNodeByKey<YamlSequence>('params', taskNode);
if (params) {
for (const param of params.items){
const val = findNodeByKey<YamlNode>('value', param as YamlMap);
if (val){
const inputVal = _.trim(val.raw, '"');
const task = extractTaskName(inputVal);
if (task){
result.push(...task.map( v => v[0]));
}

}
}
}

if (!conditions && !whens) {
const runAfter = getTaskRunAfter(taskNode);
result.push(...runAfter);
Expand Down
27 changes: 27 additions & 0 deletions test/yaml-support/tkn-yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,33 @@ suite('Tekton yaml', () => {
expect(result).equal('file-exists');
});

test('task should have other task in runAfter if task use output value from other task', async ()=> {
const yaml = `
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: pipeline-with-parameters
spec:
tasks:
- name: foo-task
taskRef:
name: build
- name: build-skaffold-web
taskRef:
name: build-push
params:
- name: pathToDockerFile
value: Dockerfile
- name: pathToContext
value: "$(tasks.foo-task.results.product)"
`
const docs = tektonYaml.getTektonDocuments({ getText: () => yaml, version: 1, uri: vscode.Uri.parse('file:///tasks/with/variables/pipeline.yaml') } as vscode.TextDocument, TektonYamlType.Pipeline);
const tasks = pipelineYaml.getPipelineTasks(docs[0]);
expect(tasks).is.not.empty;
const task = tasks.find(t => t.name === 'build-skaffold-web');
expect(task.runAfter).to.be.deep.equal(['foo-task']);
});

});

suite('PipelineRun', () => {
Expand Down

0 comments on commit 8f8d4da

Please sign in to comment.