Skip to content

Commit

Permalink
chore: Sonarqube fixes (#3182)
Browse files Browse the repository at this point in the history
SonarQube analysis reported issues on the latest code changes.
Even though this is not a required check, we should comply when the suggestions are sensible.

Here's a link to the findings:
https://sonarcloud.io/summary/new_code?id=dhis2_dashboard-app&branch=master

Summary of changes and the quality that was flagged by Sonarqube:

* ActionsBar: break up nested ternary (maintainability)
* InformationBlock.module.css and SlideshowControlbar.module.css: missing generic font,
but since this is declared higher up in the html structure for all elements (*),
font-family declarations can be removed all-together in the app (reliability)
* NavigationMenu.js: remove role="listitem" on li element since it is is implicit
(reliability, maintainability)
* ContentMenuItem.js: non-interactive element needs key handler. Fix was to make it semantically
correct and switch to an interactive element button (reliability, maintainability)
* StartScreen.module.css: remove shorthand style that followed a more specific style (reliability)
* spec files - use object spread instead of Object.assign (conventional, maintainability)
  • Loading branch information
jenniferarnesen authored Jan 14, 2025
1 parent 821e497 commit e8d563a
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 49 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"license": "BSD-3-Clause",
"dependencies": {
"@dhis2/analytics": "git+https://github.com/d2-ci/analytics.git#e398d08e696356908725c8f51f32c30e7cb002ec",
"@dhis2/analytics": "^26.9.4",
"@dhis2/app-runtime": "^3.10.6",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/d2-i18n": "^1.1.3",
Expand Down
15 changes: 10 additions & 5 deletions src/components/DashboardsBar/InformationBlock/ActionsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ const ActionsBar = ({
return <Redirect to={redirectUrl} />
}

const slideshowTooltipContent = !hasSlideshowItems
? i18n.t('No dashboard items to show in slideshow')
: offline && !isCached
? i18n.t('Not available offline')
: null
const getSlideshowTooltipContent = () => {
if (!hasSlideshowItems) {
return i18n.t('No dashboard items to show in slideshow')
} else if (offline && !isCached) {
return i18n.t('Not available offline')
}
return null
}

const slideshowTooltipContent = getSlideshowTooltipContent()

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ useDimensions.mockImplementation(() => ['Moomin', 'Snorkmaiden'])

const baseState = { activeModalDimension: {}, itemFilters: {} }
const createMockStore = (state) =>
createStore(() => Object.assign({}, baseState, state))
createStore(() => ({ ...baseState, ...state }))

test('is disabled when offline', () => {
useDhis2ConnectionStatus.mockImplementationOnce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
}

.title {
font-family: 'Roboto';
font-size: 16px;
line-height: 16px;
font-weight: 500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const NavigationMenu = ({ close }) => {
<div ref={scrollBoxRef} className={styles.scrollbox}>
<Menu dense>
{filteredDashboards.length === 0 ? (
<li role="listitem" className={styles.noItems}>
<li className={styles.noItems}>
{i18n.t('No dashboards found')}
</li>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const baseState = {
}

const createMockStore = (state) =>
createStore(() => Object.assign({}, baseState, state))
createStore(() => ({ ...baseState, ...state }))

test('renders a list of dashboard menu items', () => {
const mockStore = createMockStore({})
Expand Down
8 changes: 4 additions & 4 deletions src/pages/edit/ItemSelector/ContentMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const LaunchLink = ({ url }) => {
}, [url])

return (
<span
<button
onClick={handleClick}
className={classes.launchLink}
className={classes.launchLinkButton}
aria-label={i18n.t('Open visualization in new tab')}
>
<IconLaunch16 color={colors.grey700} />
</span>
<IconLaunch16 />
</button>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
justify-content: space-between;
}

.launchLink {
.launchLinkButton {
all: unset;
display: flex;
margin-inline-start: 8px;
z-index: 10000;
color: var(--colors-grey600);
}

.label {
Expand Down Expand Up @@ -36,3 +38,7 @@ li .buttonInsert {
.buttonInsert:focus {
outline: none;
}

.launchLinkButton:hover {
color: var(--colors-grey900);
}
2 changes: 1 addition & 1 deletion src/pages/start/styles/StartScreen.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
line-height: 18px;
letter-spacing: 0.1px;
list-style-position: outside;
list-style: circle;
list-style-type: circle;
margin-block-start: 0;
margin-block-end: 0;
margin-inline-start: var(--spacers-dp12);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/view/FilterBar/__tests__/FilterBadge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.mock('../../../../components/WindowDimensionsProvider.js', () => ({

const baseState = { selected: { id: 'dashboard1' } }
const createMockStore = (state) =>
createStore(() => Object.assign({}, baseState, state))
createStore(() => ({ ...baseState, ...state }))

test('Displays badge containing number of filter items when filtered on multiple', () => {
const filter = {
Expand Down
1 change: 0 additions & 1 deletion src/pages/view/styles/SlideshowControlbar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
}

.pageCounter {
font-family: 'Roboto', sans-serif;
font-weight: 400;
font-style: normal;
color: var(--colors-grey300);
Expand Down
38 changes: 7 additions & 31 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2304,9 +2304,10 @@
classnames "^2.3.1"
prop-types "^15.7.2"

"@dhis2/analytics@git+https://github.com/d2-ci/analytics.git#e398d08e696356908725c8f51f32c30e7cb002ec":
version "26.9.4"
resolved "git+https://github.com/d2-ci/analytics.git#e398d08e696356908725c8f51f32c30e7cb002ec"
"@dhis2/analytics@^26.9.4":
version "26.10.0"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-26.10.0.tgz#6be4f7ad13b4a64e63f330255f0bbc57aa118ff2"
integrity sha512-JmJFXsxnpoQ1KDoAYttygp7bsP76EpLVRaXDk5bGoye7lhG+Q2k0DW3q+hj9H3tIdwV1m3N1mIxzAMzG01QEtw==
dependencies:
"@dhis2/multi-calendar-dates" "^1.2.2"
"@dnd-kit/core" "^6.0.7"
Expand Down Expand Up @@ -16035,16 +16036,7 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -16143,14 +16135,7 @@ stringify-object@^3.3.0:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

[email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", [email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -17834,7 +17819,7 @@ workerpool@^6.5.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544"
integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -17861,15 +17846,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit e8d563a

Please sign in to comment.