Skip to content

Commit

Permalink
feat: Utility for generating tooltip metadata (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
minghay authored Aug 1, 2024
1 parent 341bc9d commit 0fbf2f4
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 0 deletions.
88 changes: 88 additions & 0 deletions app/utils/pipeline/graph/tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { isActiveBuild } from 'screwdriver-ui/utils/build';
import { EXTERNAL_TRIGGER_ALL } from 'screwdriver-data-schema/config/regex';

/**
* Determines if a node can show a tooltip
* @param node
*/
export const nodeCanShowTooltip = node => {
const { name } = node;

return (
name !== '~commit' &&
name !== '~pr' &&
!name.startsWith('~commit:') &&
!name.startsWith('~pr:')
);
};

/**
* Constructs tooltip data for a given node
* @param node
* @param event Event data for the pipeline (API response from /pipelines/:id/events/:eventId)
* @param jobs Jobs for the pipeline (API response from /pipelines/:id/jobs)
* @param builds Builds for the pipeline (API response from /pipelines/:id/builds)
*/
export function getTooltipData(node, event, jobs, builds = []) {
const isTrigger = node.name.startsWith('~');

if (isTrigger) {
const externalTriggerMatch = node.name.match(EXTERNAL_TRIGGER_ALL);
const downstreamTriggerMatch = node.name.match(/^~sd-([\w-]+)-triggers$/);

// Add external trigger data if relevant
if (externalTriggerMatch) {
const externalTrigger = {
pipelineId: externalTriggerMatch[1],
jobName: externalTriggerMatch[2]
};

return {
externalTrigger
};
}

// Add downstream trigger data if relevant
if (downstreamTriggerMatch) {
const triggers = [];

node.triggers.forEach(t => {
const downstreamTrigger = t.match(EXTERNAL_TRIGGER_ALL);

triggers.push({
triggerName: t,
pipelineId: downstreamTrigger[1],
jobName: downstreamTrigger[2]
});
});

return {
triggers
};
}
}

const tooltip = {
displayStop: isActiveBuild(node.status),
selectedEvent: event
};

const job = { ...node };

if (event.prNum) {
const originalJob = jobs.find(j => j.name === job.name);

job.isDisabled = originalJob ? originalJob.state === 'DISABLED' : false;
}

const build = builds.find(b => b.jobId === node.id);

if (build) {
job.buildId = build.id;
job.status = build.status;
}

tooltip.job = job;

return tooltip;
}
155 changes: 155 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"qunit": "^2.19.1",
"qunit-dom": "^2.0.0",
"sass-embedded": "^1.77.0",
"screwdriver-data-schema": "^23.5.1",
"sinon": "^18.0.0",
"webpack": "^5.76.2"
}
Expand Down
Loading

0 comments on commit 0fbf2f4

Please sign in to comment.