-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
#10516 added ellipsis if more than 5 warnings occurs #10595
base: develop
Are you sure you want to change the base?
Changes from 3 commits
c598143
03e4d02
7c5b0bb
d11014d
6b2ee66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,103 +1,98 @@ | ||||||||||
import { select as d3_select } from 'd3-selection'; | ||||||||||
|
||||||||||
import { t } from '../core/localizer'; | ||||||||||
import { svgIcon } from '../svg/icon'; | ||||||||||
import { uiTooltip } from './tooltip'; | ||||||||||
import { uiSection } from '../ui/section'; | ||||||||||
import { utilEntityOrMemberSelector } from '../util'; | ||||||||||
|
||||||||||
|
||||||||||
export function uiCommitWarnings(context) { | ||||||||||
|
||||||||||
var _issuesBySeverity = {}; | ||||||||||
|
||||||||||
function commitWarnings(selection) { | ||||||||||
var issuesBySeverity = context.validator() | ||||||||||
// Load issues by severity | ||||||||||
_issuesBySeverity = context.validator() | ||||||||||
.getIssuesBySeverity({ what: 'edited', where: 'all', includeDisabledRules: true }); | ||||||||||
|
||||||||||
for (var severity in issuesBySeverity) { | ||||||||||
var issues = issuesBySeverity[severity]; | ||||||||||
for (let severity in _issuesBySeverity) { | ||||||||||
let issues = _issuesBySeverity[severity]; | ||||||||||
|
||||||||||
if (severity !== 'error') { // exclude 'fixme' and similar - #8603 | ||||||||||
if (severity !== 'error') { // exclude 'fixme' and similar - #8603 | ||||||||||
issues = issues.filter(function(issue) { return issue.type !== 'help_request'; }); | ||||||||||
} | ||||||||||
|
||||||||||
var section = severity + '-section'; | ||||||||||
var issueItem = severity + '-item'; | ||||||||||
|
||||||||||
var container = selection.selectAll('.' + section) | ||||||||||
.data(issues.length ? [0] : []); | ||||||||||
|
||||||||||
container.exit() | ||||||||||
.remove(); | ||||||||||
|
||||||||||
var containerEnter = container.enter() | ||||||||||
.append('div') | ||||||||||
.attr('class', 'modal-section ' + section + ' fillL2'); | ||||||||||
|
||||||||||
containerEnter | ||||||||||
.append('h3') | ||||||||||
.call(severity === 'warning' ? t.append('commit.warnings') : t.append('commit.errors')); | ||||||||||
|
||||||||||
containerEnter | ||||||||||
.append('ul') | ||||||||||
.attr('class', 'changeset-list'); | ||||||||||
|
||||||||||
container = containerEnter | ||||||||||
.merge(container); | ||||||||||
|
||||||||||
if (!issues.length) continue; | ||||||||||
|
||||||||||
var items = container.select('ul').selectAll('li') | ||||||||||
.data(issues, function(d) { return d.key; }); | ||||||||||
|
||||||||||
items.exit() | ||||||||||
.remove(); | ||||||||||
|
||||||||||
var itemsEnter = items.enter() | ||||||||||
.append('li') | ||||||||||
.attr('class', issueItem); | ||||||||||
|
||||||||||
var buttons = itemsEnter | ||||||||||
.append('button') | ||||||||||
.on('mouseover', function(d3_event, d) { | ||||||||||
if (d.entityIds) { | ||||||||||
context.surface().selectAll( | ||||||||||
utilEntityOrMemberSelector( | ||||||||||
d.entityIds, | ||||||||||
context.graph() | ||||||||||
) | ||||||||||
).classed('hover', true); | ||||||||||
} | ||||||||||
// Create a collapsible section for each severity level | ||||||||||
var section = uiSection('issues-'+ severity , context) | ||||||||||
.label(() => { | ||||||||||
var count = issues.length; | ||||||||||
return t.append( | ||||||||||
'inspector.title_count', | ||||||||||
{ title: t('issues.' + severity + 's.list_title'), count: count } | ||||||||||
); | ||||||||||
}) | ||||||||||
.on('mouseout', function() { | ||||||||||
context.surface().selectAll('.hover') | ||||||||||
.classed('hover', false); | ||||||||||
.disclosureContent(function(selection) { | ||||||||||
return renderIssuesList(selection, severity, issues); | ||||||||||
}) | ||||||||||
Comment on lines
+36
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be an arrow function to be more concise and consistent with the
Suggested change
same also for the |
||||||||||
.on('click', function(d3_event, d) { | ||||||||||
context.validator().focusIssue(d); | ||||||||||
.shouldDisplay(function() { | ||||||||||
return issues && issues.length; | ||||||||||
}); | ||||||||||
|
||||||||||
buttons | ||||||||||
.call(svgIcon('#iD-icon-alert', 'pre-text')); | ||||||||||
|
||||||||||
buttons | ||||||||||
.append('strong') | ||||||||||
.attr('class', 'issue-message'); | ||||||||||
|
||||||||||
buttons.filter(function(d) { return d.tooltip; }) | ||||||||||
.call(uiTooltip() | ||||||||||
.title(function(d) { return d.tooltip; }) | ||||||||||
.placement('top') | ||||||||||
); | ||||||||||
|
||||||||||
items = itemsEnter | ||||||||||
.merge(items); | ||||||||||
|
||||||||||
items.selectAll('.issue-message') | ||||||||||
.text('') | ||||||||||
.each(function(d) { | ||||||||||
return d.message(context)(d3_select(this)); | ||||||||||
}); | ||||||||||
selection.call(section.render); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
function renderIssuesList(selection, severity, issues) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function argument |
||||||||||
selection.selectAll('.issues-list').remove(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this could work (if the correct css class was referenced in the d3 select 😅 ), the approach to recreate the list from scratch every time the list needs to be rendered is not the best. See the suggestion in the next comment for a solution that does actually use a d3 data binding to make sure the |
||||||||||
var container = selection | ||||||||||
.append('ul') | ||||||||||
.attr('class', 'changeset-list issues-list ' + severity + '-list'); | ||||||||||
|
||||||||||
container.exit().remove(); | ||||||||||
|
||||||||||
var items = container.selectAll('li') | ||||||||||
.data(issues, function(d) { return d.key; }); | ||||||||||
|
||||||||||
items.exit().remove(); | ||||||||||
|
||||||||||
var itemsEnter = items.enter() | ||||||||||
.append('li') | ||||||||||
.attr('class', severity + '-item'); | ||||||||||
|
||||||||||
var buttons = itemsEnter | ||||||||||
.append('button') | ||||||||||
.on('mouseover', function(d3_event, d) { | ||||||||||
if (d.entityIds) { | ||||||||||
context.surface().selectAll( | ||||||||||
utilEntityOrMemberSelector( | ||||||||||
d.entityIds, | ||||||||||
context.graph() | ||||||||||
) | ||||||||||
).classed('hover', true); | ||||||||||
} | ||||||||||
}) | ||||||||||
.on('mouseout', function() { | ||||||||||
context.surface().selectAll('.hover').classed('hover', false); | ||||||||||
}) | ||||||||||
.on('click', function(d3_event, d) { | ||||||||||
context.validator().focusIssue(d); | ||||||||||
}); | ||||||||||
|
||||||||||
buttons | ||||||||||
.call(svgIcon('#iD-icon-alert', 'pre-text')); | ||||||||||
|
||||||||||
buttons | ||||||||||
.append('strong') | ||||||||||
.attr('class', 'issue-message'); | ||||||||||
|
||||||||||
itemsEnter | ||||||||||
.merge(items) | ||||||||||
.selectAll('.issue-message') | ||||||||||
.text('') | ||||||||||
.each(function(d) { | ||||||||||
return d.message(context)(d3_select(this)); | ||||||||||
}); | ||||||||||
} | ||||||||||
|
||||||||||
return commitWarnings; | ||||||||||
} |
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.
good idea to refactor some of the old code using
var
. Could you please also useconst/let
instead ofvar
in the remaining new code of this PR?