From c63c05b51162c9a0d83cdedbf0705347e44184ef Mon Sep 17 00:00:00 2001 From: 7PH Date: Thu, 9 Feb 2023 10:34:39 +0100 Subject: [PATCH] SONAR-18361 Improve accessibility of the quality profile compare page --- .../src/main/js/app/styles/init/tables.css | 6 + .../__tests__/QualityProfilesApp-it.tsx | 6 +- .../compare/ComparisonResultActivation.tsx | 5 - .../compare/ComparisonResults.tsx | 189 ++++++++++-------- .../main/js/apps/quality-profiles/styles.css | 10 +- 5 files changed, 118 insertions(+), 98 deletions(-) diff --git a/server/sonar-web/src/main/js/app/styles/init/tables.css b/server/sonar-web/src/main/js/app/styles/init/tables.css index df2e1665f3e..a6317d0229e 100644 --- a/server/sonar-web/src/main/js/app/styles/init/tables.css +++ b/server/sonar-web/src/main/js/app/styles/init/tables.css @@ -162,6 +162,12 @@ table.data th.small { white-space: nowrap; } +table.data > caption { + padding: 8px 10px; + text-align: center; + font-weight: bold; +} + table.data > thead > tr > th { position: relative; vertical-align: top; diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfilesApp-it.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfilesApp-it.tsx index 7d5413dbbff..00c6ac5aba2 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfilesApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfilesApp-it.tsx @@ -83,9 +83,11 @@ const ui = { }), nameCreatePopupInput: byRole('textbox', { name: 'name field_required' }), comparisonDiffTableHeading: (rulesQuantity: number, profileName: string) => - byRole('heading', { name: `quality_profiles.x_rules_only_in.${rulesQuantity} ${profileName}` }), + byRole('columnheader', { + name: `quality_profiles.x_rules_only_in.${rulesQuantity} ${profileName}`, + }), comparisonModifiedTableHeading: (rulesQuantity: number) => - byRole('heading', { + byRole('table', { name: `quality_profiles.x_rules_have_different_configuration.${rulesQuantity}`, }), newRuleLink: byRole('link', { name: 'Recently Added Rule' }), diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/compare/ComparisonResultActivation.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/compare/ComparisonResultActivation.tsx index 51b987e0293..333e6aeff30 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/compare/ComparisonResultActivation.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/compare/ComparisonResultActivation.tsx @@ -77,11 +77,6 @@ export default class ComparisonResultActivation extends React.PureComponent { + canActivate(profile: Profile) { + return !profile.isBuiltIn && profile.actions && profile.actions.edit; + } + renderRule(rule: { key: string; name: string }, severity: string) { return (
@@ -70,38 +75,43 @@ export default class ComparisonResults extends React.PureComponent { if (this.props.inLeft.length === 0) { return null; } + + const renderSecondColumn = this.props.rightProfile && this.canActivate(this.props.rightProfile); + return ( - <> - - -
+ + + + - - {this.props.inLeft.map((rule) => ( - - - + + {renderSecondColumn && } - ))} - + + + {this.props.inLeft.map((rule) => ( + + + {renderSecondColumn && ( + + )} + + ))} + +
{translateWithParameters( 'quality_profiles.x_rules_only_in', this.props.inLeft.length )}{' '} {this.props.left.name} - - -  
{this.renderRule(rule, rule.severity)} - {this.props.rightProfile && ( - - - - )} -  
{this.renderRule(rule, rule.severity)} + + + +
); } @@ -109,36 +119,47 @@ export default class ComparisonResults extends React.PureComponent { if (this.props.inRight.length === 0) { return null; } + + const renderFirstColumn = this.props.leftProfile && this.canActivate(this.props.leftProfile); + return ( - <> - -   - -
+ + + + {renderFirstColumn && } + - {this.props.inRight.map((rule) => ( - - - + - ))} - + + + {this.props.inRight.map((rule) => ( + + {renderFirstColumn && ( + + )} + + + ))} + +
  {translateWithParameters( 'quality_profiles.x_rules_only_in', this.props.inRight.length )}{' '} {this.props.right.name} - - -
- - - - {this.renderRule(rule, rule.severity)}
+ + + + {this.renderRule(rule, rule.severity)}
); } @@ -147,38 +168,34 @@ export default class ComparisonResults extends React.PureComponent { return null; } return ( - <> - - -
- {translateWithParameters( - 'quality_profiles.x_rules_have_different_configuration', - this.props.modified.length - )} -
- - - - -
{this.props.left.name}
- - -
{this.props.right.name}
- - - {this.props.modified.map((rule) => ( - - - {this.renderRule(rule, rule.left.severity)} - {this.renderParameters(rule.left.params)} - - - {this.renderRule(rule, rule.right.severity)} - {this.renderParameters(rule.right.params)} - + + + + + + - ))} - + + + {this.props.modified.map((rule) => ( + + + + + ))} + +
+ {translateWithParameters( + 'quality_profiles.x_rules_have_different_configuration', + this.props.modified.length + )} +
{this.props.left.name}{this.props.right.name}
+ {this.renderRule(rule, rule.left.severity)} + {this.renderParameters(rule.left.params)} + + {this.renderRule(rule, rule.right.severity)} + {this.renderParameters(rule.right.params)} +
); } @@ -188,13 +205,11 @@ export default class ComparisonResults extends React.PureComponent { } return ( - - - {this.renderLeft()} - {this.renderRight()} - {this.renderModified()} - -
+ <> + {this.renderLeft()} + {this.renderRight()} + {this.renderModified()} + ); } } diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/styles.css b/server/sonar-web/src/main/js/apps/quality-profiles/styles.css index 3b7c844023f..4fb6b68c3e7 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/styles.css +++ b/server/sonar-web/src/main/js/apps/quality-profiles/styles.css @@ -99,10 +99,6 @@ padding: 0; } -.quality-profile-comparison-table { - table-layout: fixed; -} - .quality-profile-changelog-rule-cell { line-height: 1.5; } @@ -112,6 +108,12 @@ word-break: break-word; } +.quality-profile-compare-right-table:not(.has-first-column) td, +.quality-profile-compare-right-table:not(.has-first-column) th { + /* Aligns the first column with the second one (50%) and add usual cell padding */ + padding-left: calc(50% + 10px); +} + #create-profile-form .radio-card { width: 245px; background-color: var(--neutral50); -- 2.39.5