Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Utility for generating tooltip metadata #1095

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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