Skip to content

Commit f113dd5

Browse files
authored
fix(plugin): clean up resize observer and handle sonarqube warnings (#898)
* refactor: use css modules in example app * chore: remove finished todos in makeViteConfig * chore: add jira issues to todos * refactor: simplify hosted location string ternary * refactor: remove always truthy condition * fix(plugin): remove resize observer on cleanup * chore: import order * fix: consistent ref * chore: style
1 parent 5b92212 commit f113dd5

File tree

10 files changed

+35
-35
lines changed

10 files changed

+35
-35
lines changed

cli/config/makeViteConfig.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import dynamicImport from 'vite-plugin-dynamic-import'
2525
* merged with the main config if the `--allowJsxInJs` flag is passed
2626
* to the CLI
2727
*
28-
* todo: deprecate -- this config has a performance cost, especially on startup
28+
* ! deprecated -- this config has a performance cost, especially on startup
2929
*/
3030
const jsxInJsConfig = {
3131
plugins: [
@@ -178,7 +178,7 @@ export default ({ paths, config, env, host, force, allowJsxInJs }) => {
178178
dynamicImport(),
179179
react({
180180
babel: { plugins: ['styled-jsx/babel'] },
181-
// todo: deprecate with other jsx-in-js config
181+
// ! deprecated with other jsx-in-js config
182182
// This option allows HMR of JSX-in-JS files,
183183
// but it isn't possible to add with merge config:
184184
jsxRuntime: allowJsxInJs ? 'classic' : 'automatic',

cli/src/commands/deploy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ const handler = async ({ cwd = process.cwd(), timeout, ...params }) => {
152152
}
153153

154154
// todo: modify for multiple/named plugins
155+
// https://dhis2.atlassian.net/browse/LIBS-394
155156
const appUrl = constructAppUrl({
156157
baseUrl: dhis2Config.baseUrl,
157158
config,

cli/src/commands/start.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,12 @@ const handler = async ({
161161
})
162162
const server = await createServer(viteConfig)
163163

164-
const location = config.entryPoints.plugin
165-
? config.entryPoints.app
164+
let location = ''
165+
if (config.entryPoints.plugin) {
166+
location = config.entryPoints.app
166167
? ' at / and /plugin.html'
167168
: ' at /plugin.html'
168-
: ''
169+
}
169170

170171
reporter.print(
171172
`The app ${chalk.bold(

cli/src/lib/compiler/compile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ const compile = async ({
142142
inputDir: paths.src,
143143
outputDir: outDir,
144144
// todo: handle lib compilations with Vite
145+
// https://dhis2.atlassian.net/browse/LIBS-722
145146
processFileCallback: isAppType ? copyFile : compileFile,
146147
watch,
147148
}),

examples/simple-app/src/Alerter.jsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useAlert } from '@dhis2/app-runtime'
22
import { InputField, CheckboxField, Button } from '@dhis2/ui'
33
import React, { useState } from 'react'
4+
import styles from './Alerter.module.css'
45

56
export const Alerter = () => {
67
const [message, setMessage] = useState('')
@@ -12,7 +13,7 @@ export const Alerter = () => {
1213
)
1314

1415
return (
15-
<div>
16+
<div className={styles.flexContainer}>
1617
<InputField
1718
placeholder="Type alert message"
1819
value={message}
@@ -25,14 +26,6 @@ export const Alerter = () => {
2526
/>
2627
<Button onClick={() => show(message)}>Show alert</Button>
2728
<Button onClick={hide}>Hide alert</Button>
28-
<style jsx>{`
29-
div {
30-
display: flex;
31-
align-items: center;
32-
justify-content: space-between;
33-
width: 500px;
34-
}
35-
`}</style>
3629
</div>
3730
)
3831
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.flexContainer {
2+
display: flex;
3+
align-items: center;
4+
justify-content: space-between;
5+
width: 500px;
6+
}

examples/simple-app/src/App.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useDataQuery } from '@dhis2/app-runtime'
22
import moment from 'moment'
33
import React from 'react'
44
import { Alerter } from './Alerter.jsx'
5-
import style from './App.style.js'
5+
import styles from './App.module.css'
66
import i18n from './locales/index.js'
77

88
const query = {
@@ -14,8 +14,7 @@ const query = {
1414
const Component = () => {
1515
const { error, loading, data } = useDataQuery(query)
1616
return (
17-
<div>
18-
<style jsx>{style}</style>
17+
<div className={styles.appContainer}>
1918
{error && <span>ERROR</span>}
2019
{loading && <span>...</span>}
2120
{data && (
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.appContainer {
2+
width: 100%;
3+
height: 100%;
4+
5+
display: flex;
6+
flex-direction: column;
7+
align-items: center;
8+
justify-content: center;
9+
font-size: 1rem;
10+
}

examples/simple-app/src/App.style.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

shell/src/PluginLoader.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ const PluginResizeInner = ({
1515
const innerDivRef = useRef()
1616
useEffect(() => {
1717
if (divRef && divRef.current && resizePluginHeight) {
18+
const container = divRef.current
1819
const resizeObserver = new ResizeObserver(() => {
1920
// the additional pixels currently account for possible horizontal scroll bar
20-
if (resizePluginHeight) {
21-
resizePluginHeight(divRef.current.offsetHeight + 20)
22-
}
21+
resizePluginHeight(container.offsetHeight + 20)
2322
})
24-
resizeObserver.observe(divRef.current)
23+
resizeObserver.observe(container)
24+
return () => {
25+
resizeObserver.unobserve(container)
26+
resizeObserver.disconnect()
27+
}
2528
}
2629
}, [resizePluginHeight])
2730

0 commit comments

Comments
 (0)