-
Notifications
You must be signed in to change notification settings - Fork 227
extract issues summary widget into edition partials, rework chart legend #1638
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
Open
MattBudz
wants to merge
27
commits into
develop
Choose a base branch
from
dashboard/extract-issues-summary-edition-partial
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
404efd5
extract issues summary widget into edition partials
MattBudz c3c449e
merge develop to pick up crass 1.0.7 security update
MattBudz 1fa82a2
extract shared tags accordion into a sub-partial
MattBudz f3ed086
move chart data to controller; set attributes on #issue-chart
MattBudz 9635184
fix RuboCop ExtraSpacing violations in projects_controller
MattBudz 2b8d3b8
use each over for..in for tag iteration
MattBudz 52eac9f
extract tag grouping into a shared IssuesGrouping concern
MattBudz 498db39
Merge remote-tracking branch 'origin/develop' into dashboard/extract-…
MattBudz fa855c9
rename IssuesGrouping to IssuesDimensionGrouping
MattBudz 26abf01
add issues_summary route and controller
MattBudz e02447e
lazy-load the issues-summary widget via a turbo frame
MattBudz 7f05c34
stop eagerly computing issue grouping in ProjectsController#show
MattBudz d7dde6d
add request spec for Projects::IssuesSummaryController
MattBudz 67a9606
fix pre-existing RuboCop spacing offenses in routes.rb
MattBudz bc1ee96
initialize the issues chart on turbo:frame-load, not turbo:load
MattBudz df2b89b
add feature spec covering the lazy-loaded issues chart
MattBudz 5f13e76
break out of the issues-summary frame when opening an issue
MattBudz d180a34
simplify build_all_tags_grouping with Hash.new(0)
MattBudz d4bab36
extract a colors array in initIssuesChart
MattBudz 605e6ee
fix stray double space in colored_icon_for_model
MattBudz 80ab8ed
drop manual alignment padding in initIssuesChart data variables
MattBudz 4bec4b1
Merge branch 'develop' into dashboard/extract-issues-summary-edition-…
MattBudz 3dbb787
match combobox options by attribute value instead of a raw selector
MattBudz adaa6c1
Merge remote-tracking branch 'origin/dashboard/extract-issues-summary…
MattBudz 9f88530
Merge branch 'develop' into dashboard/extract-issues-summary-edition-…
MattBudz 0fe97cd
move issues chart legend below chart, wrap horizontally
MattBudz 51446af
Merge branch 'develop' into dashboard/extract-issues-summary-edition-…
MattBudz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
185 changes: 90 additions & 95 deletions
185
app/assets/javascripts/hera/pages/projects/issues_chart.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,95 +1,90 @@ | ||
| document.addEventListener('turbo:load', function(){ | ||
| var $dataElement = $('#issues-summary-data'), | ||
| $chartElement = $('#issue-chart'); | ||
|
|
||
| if ($dataElement.length && $chartElement.find('svg').length == 0) { | ||
| var margin = {top: 20, bottom: 30}, | ||
| width = 354; | ||
| height = 180 - margin.top - margin.bottom; | ||
|
|
||
| var x = d3.scaleBand().rangeRound([0, width]); | ||
|
|
||
| var y = d3.scaleLinear() | ||
| .range([height, 0]); | ||
|
|
||
| var xAxis = d3.axisBottom(x) | ||
| .tickSize(0); | ||
|
|
||
| var svg = d3.select('#issue-chart').append('svg') | ||
| .attr('width', width) | ||
| .attr('height', height + margin.top + margin.bottom) | ||
| .append('g') | ||
| .attr('transform', 'translate(0,' + margin.top + ')'); | ||
|
|
||
| // --------------------------------------------------------- Data variables | ||
| var tags = $dataElement.data('tags'); | ||
| var issuesByTag = $dataElement.data('issues-count'); | ||
| var highest = 0; | ||
| var data = []; | ||
| var x_domain = []; | ||
|
|
||
| for (var key in tags){ | ||
| issuesCount = issuesByTag[key]; | ||
| highest = issuesCount > highest ? issuesCount : highest | ||
| data.push({letter: tags[key][0], frequency: issuesCount}); | ||
| x_domain.push(tags[key][0]); | ||
| } | ||
| data.push({letter: 'N/A', frequency: issuesByTag['unassigned']}) | ||
| x_domain.push('N/A'); | ||
|
|
||
| var highest_y = Math.max(highest, issuesByTag['unassigned']); | ||
| // -------------------------------------------------------- /Data variables | ||
|
|
||
| x.domain(x_domain); | ||
|
|
||
| y.domain([0, highest_y]); | ||
|
|
||
| d3.selection.prototype.last = function() { | ||
| return d3.select( | ||
| this.nodes()[this.size() - 1] | ||
| ); | ||
| }; | ||
|
|
||
| x_axis = svg.append('g') | ||
| .attr('class', 'x axis') | ||
| .attr('transform', 'translate(0,' + height + ')') | ||
| .call(xAxis); | ||
| x_axis.selectAll("text").style("fill", "inherit"); | ||
| x_axis.selectAll("path").style("stroke", "none"); | ||
| x_axis.selectAll("text").last().classed("untagged", true); | ||
|
|
||
| var bars = svg.append('g'); | ||
|
|
||
| bars.selectAll('rect') | ||
| .data(data) | ||
| .enter().append('rect') | ||
| .attr('class', 'bar' ) | ||
| .attr('x', function(d) { return x(d.letter); }) | ||
| .attr('width', x.bandwidth()) | ||
| .attr('y', function(d) { return y(d.frequency); }) | ||
| .attr('height', function(d) { return height - y(d.frequency); }); | ||
|
|
||
|
|
||
| bars.selectAll('text') | ||
| .data(data) | ||
| .enter().append('text') | ||
| .attr('x', function(d, i) { return x(d.letter) + x.bandwidth()/2; }) | ||
| .attr('y', function(d) { return y(d.frequency);}) | ||
| .attr('dy', -5) | ||
| .attr('text-anchor', 'middle') | ||
| .attr('class', 'counter' ) | ||
| .text(function(d) {return d.frequency;}); | ||
|
|
||
| var i = 0; | ||
| for( var key in tags ){ | ||
| $($('.tick')[i]).attr('fill', tags[key][1]); | ||
| $($('.bar')[i]).attr('fill', tags[key][1]); | ||
| $($('.counter')[i]).attr('fill', tags[key][1]); | ||
| i++; | ||
| } | ||
|
|
||
| $($('.tick')[i]).addClass('untagged'); | ||
| $($('.bar')[i]).addClass('untagged'); | ||
| $($('.counter')[i]).addClass('untagged'); | ||
| } | ||
| }); | ||
| function initIssuesChart() { | ||
| const $chartElement = $('#issue-chart'); | ||
|
|
||
| if (!$chartElement.length || $chartElement.find('svg').length > 0) { return; } | ||
|
|
||
| const margin = { top: 20, bottom: 30 }; | ||
| const width = 354; | ||
| const height = 180 - margin.top - margin.bottom; | ||
|
|
||
| const x = d3.scaleBand().rangeRound([0, width]); | ||
| const y = d3.scaleLinear().range([height, 0]); | ||
|
|
||
| const xAxis = d3.axisBottom(x).tickSize(0); | ||
|
|
||
| const svg = d3.select('#issue-chart').append('svg') | ||
| .attr('width', width) | ||
| .attr('height', height + margin.top + margin.bottom) | ||
| .append('g') | ||
| .attr('transform', `translate(0,${margin.top})`); | ||
|
|
||
| // --------------------------------------------------------- Data variables | ||
| const tags = $chartElement.data('tags') || {}; | ||
| const issuesByTag = $chartElement.data('issues-count') || {}; | ||
| let highest = 0; | ||
| const data = []; | ||
| const x_domain = []; | ||
|
|
||
| Object.keys(tags).forEach(key => { | ||
| const count = issuesByTag[key] || 0; | ||
| highest = count > highest ? count : highest; | ||
| data.push({ letter: tags[key][0], frequency: count }); | ||
| x_domain.push(tags[key][0]); | ||
| }); | ||
|
|
||
| const unassignedCount = issuesByTag['unassigned'] || 0; | ||
| data.push({ letter: 'N/A', frequency: unassignedCount }); | ||
| x_domain.push('N/A'); | ||
|
|
||
| const highest_y = Math.max(highest, unassignedCount); | ||
| // -------------------------------------------------------- /Data variables | ||
|
|
||
| x.domain(x_domain); | ||
| y.domain([0, highest_y]); | ||
|
|
||
| d3.selection.prototype.last = function() { | ||
| return d3.select(this.nodes()[this.size() - 1]); | ||
| }; | ||
|
|
||
| const x_axis = svg.append('g') | ||
| .attr('class', 'x axis') | ||
| .attr('transform', `translate(0,${height})`) | ||
| .call(xAxis); | ||
| x_axis.selectAll('text').style('fill', 'inherit'); | ||
| x_axis.selectAll('path').style('stroke', 'none'); | ||
| x_axis.selectAll('text').last().classed('untagged', true); | ||
|
|
||
| const bars = svg.append('g'); | ||
|
|
||
| bars.selectAll('rect') | ||
| .data(data) | ||
| .enter().append('rect') | ||
| .attr('class', 'bar') | ||
| .attr('x', d => x(d.letter)) | ||
| .attr('width', x.bandwidth()) | ||
| .attr('y', d => y(d.frequency)) | ||
| .attr('height', d => height - y(d.frequency)); | ||
|
|
||
| bars.selectAll('text') | ||
| .data(data) | ||
| .enter().append('text') | ||
| .attr('x', d => x(d.letter) + x.bandwidth() / 2) | ||
| .attr('y', d => y(d.frequency)) | ||
| .attr('dy', -5) | ||
| .attr('text-anchor', 'middle') | ||
| .attr('class', 'counter') | ||
| .text(d => d.frequency); | ||
|
|
||
| const tagCount = Object.keys(tags).length; | ||
| Object.keys(tags).forEach((key, i) => { | ||
| $($('.tick')[i]).attr('fill', tags[key][1]); | ||
| $($('.bar')[i]).attr('fill', tags[key][1]); | ||
| $($('.counter')[i]).attr('fill', tags[key][1]); | ||
| }); | ||
|
|
||
| $($('.tick')[tagCount]).addClass('untagged'); | ||
| $($('.bar')[tagCount]).addClass('untagged'); | ||
| $($('.counter')[tagCount]).addClass('untagged'); | ||
| } | ||
|
|
||
| document.addEventListener('turbo:load', initIssuesChart); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1 @@ | ||
| <section class="summary-panel"> | ||
| <% if @issues.any? %> | ||
| <h4 class="header-underline">Issues so far</h4> | ||
| <div id="issue-chart"></div> | ||
|
|
||
| <div id="issues-accordion" role="tablist"> | ||
| <% for tag in @tags do %> | ||
| <% if @issues_by_tag[tag.name].any? %> | ||
| <div class="card" style="border-color: <%= tag.color %>"> | ||
| <a data-bs-toggle="collapse" href="#collape<%= tag.display_name %>" class="card-header" style="background: <%= tag.color %>" data-behavior="card-header"> | ||
| <h5><%= tag.display_name %><span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5> | ||
| </a> | ||
|
|
||
| <div id="collape<%= tag.display_name %>" class="collapse show"> | ||
| <div class="card-body p-0"> | ||
| <ul class="list-group"> | ||
| <% @issues_by_tag[tag.name].each do |issue| %> | ||
| <%= link_to [current_project, issue], class: 'list-group-item' do %> | ||
| <li><i class="fa-solid fa-bug me-2" style="color: <%= tag.color %>"></i><%= issue.title %></li> | ||
| <% end %> | ||
| <% end %> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <% end %> | ||
| <% end %> | ||
|
|
||
| <%# unassigned %> | ||
| <% if @issues_by_tag[:unassigned].any? %> | ||
| <div class="card untagged"> | ||
| <a data-bs-toggle="collapse" href="#collapeUnassigned" class="card-header" data-behavior="card-header"> | ||
| <h5>Unassigned<span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5> | ||
| </a> | ||
|
|
||
| <div id="collapeUnassigned" class="collapse show"> | ||
| <div class="card-body p-0"> | ||
| <ul class="list-group"> | ||
| <% @issues_by_tag[:unassigned].each do |issue| %> | ||
| <%= link_to [current_project, issue], class: 'list-group-item' do %> | ||
| <li><i class="fa-solid fa-bug me-2"></i><%= issue.title %></li> | ||
| <% end %> | ||
| <% end %> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
|
|
||
| <% else %> | ||
| <%= render 'shared/empty_state', | ||
| actions_partial: 'projects/issues/empty_state_actions', | ||
| name: 'issue', | ||
| docs_link: 'https://dradis.com/support/guides/projects/issues.html', | ||
| text: 'Use issues to represent vulnerabilities or findings.' | ||
| %> | ||
| <% end %> | ||
| </section> | ||
|
|
||
| <% if @issues.any? %> | ||
| <div id='issues-summary-data' data-tags='<%= @tag_names.to_json %>' data-issues-count='<%= @count_by_tag.to_json %>'></div> | ||
| <% end %> | ||
| <%= render "projects/issues/summary/#{Dradis.edition}" %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <section class="summary-panel"> | ||
| <% if @issues.any? %> | ||
| <h4 class="header-underline">Issues so far</h4> | ||
| <%= tag.div id: 'issue-chart', data: @chart_data %> | ||
|
|
||
| <div id="issues-accordion" role="tablist"> | ||
| <%= render 'projects/issues/summary/tags_accordion' %> | ||
| </div> | ||
|
|
||
| <% else %> | ||
| <%= render 'shared/empty_state', | ||
| actions_partial: 'projects/issues/empty_state_actions', | ||
| name: 'issue', | ||
| docs_link: 'https://dradis.com/support/guides/projects/issues.html', | ||
| text: 'Use issues to represent vulnerabilities or findings.' | ||
| %> | ||
| <% end %> | ||
| </section> |
39 changes: 39 additions & 0 deletions
39
app/views/projects/issues/summary/_tags_accordion.html.erb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <% for tag in @tags do %> | ||
|
MattBudz marked this conversation as resolved.
Outdated
|
||
| <% if @issues_by_tag[tag.name].any? %> | ||
| <div class="card" style="border-color: <%= tag.color %>"> | ||
| <a data-bs-toggle="collapse" href="#collapse<%= tag.display_name %>" class="card-header" style="background: <%= tag.color %>" data-behavior="card-header"> | ||
| <h5><%= tag.display_name %><span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5> | ||
| </a> | ||
| <div id="collapse<%= tag.display_name %>" class="collapse show"> | ||
| <div class="card-body p-0"> | ||
| <ul class="list-group"> | ||
| <% @issues_by_tag[tag.name].each do |issue| %> | ||
| <%= link_to [current_project, issue], class: 'list-group-item' do %> | ||
| <li><i class="fa-solid fa-bug me-2" style="color: <%= tag.color %>"></i><%= issue.title %></li> | ||
| <% end %> | ||
| <% end %> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <% end %> | ||
| <% end %> | ||
|
|
||
| <% if @issues_by_tag[:unassigned].any? %> | ||
| <div class="card untagged"> | ||
| <a data-bs-toggle="collapse" href="#collapseUnassigned" class="card-header" data-behavior="card-header"> | ||
| <h5>Unassigned<span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5> | ||
| </a> | ||
| <div id="collapseUnassigned" class="collapse show"> | ||
| <div class="card-body p-0"> | ||
| <ul class="list-group"> | ||
| <% @issues_by_tag[:unassigned].each do |issue| %> | ||
| <%= link_to [current_project, issue], class: 'list-group-item' do %> | ||
| <li><i class="fa-solid fa-bug me-2"></i><%= issue.title %></li> | ||
| <% end %> | ||
| <% end %> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <% end %> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks parity with pro since it isn't used there in the same controller. As a compromise, I'm fine with moving this definition in the CE view if we add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went a step further than the view-move compromise, extracted the tag-grouping logic (including
@chart_data) into a sharedIssuesGroupingconcern, matching how Pro already needs to call it from more than one controller.ProjectsController#shownow just callsbuild_all_tags_grouping. This should make the sync cleaner since Pro's version of the concern can now land as an addition to this file rather than introducing it from scratch.