Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit eae0a16

Browse files
authored
fix: don't break the page structure while loading data for the headerbar (#7)
* fix: don't break the page structure while loading data for the headerbar * chore: conform to CSS classname convention * chore: upgrade app-runtime to 1.2.0
1 parent 51c124c commit eae0a16

5 files changed

Lines changed: 41 additions & 25 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@babel/plugin-transform-react-constant-elements": "^7.2.0",
4343
"@babel/preset-env": "^7.1.6",
4444
"@babel/preset-react": "^7.0.0",
45-
"@dhis2/app-runtime": "1.1.0",
45+
"@dhis2/app-runtime": "1.2.0",
4646
"@dhis2/cli-style": "3.1.1",
4747
"@dhis2/d2-i18n-extract": "1.0.7",
4848
"@dhis2/d2-i18n-generate": "1.1.1",

src/HeaderBar/Notifications.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export const Notifications = ({ interpretations, messages }) => (
2020

2121
<style jsx>{`
2222
div {
23-
margin-left: auto;
2423
user-select: none;
2524
display: flex;
2625
flex-direction: row;

src/HeaderBar/index.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,35 @@ export const HeaderBar = ({ appName, className }) => {
3434
},
3535
})
3636

37-
if (loading) return <span>...</span>
38-
3937
if (error) return <span>{`ERROR: ${error.message}`}</span>
4038

41-
const locale = data.user.settings.keyUiLocale || 'en'
42-
i18n.changeLanguage(locale)
39+
if (!loading) {
40+
// TODO: This will run every render which is probably wrong! Also, setting the global locale shouldn't be done in the headerbar
41+
const locale = data.user.settings.keyUiLocale || 'en'
42+
i18n.changeLanguage(locale)
43+
}
4344

4445
return (
4546
<header className={className}>
4647
<Logo />
4748

48-
<Title app={appName} instance={data.systemInfo.systemName} />
49-
50-
<Notifications
51-
interpretations={data.notifications.unreadInterpretations}
52-
messages={data.notifications.unreadMessageConversations}
53-
/>
54-
55-
<Apps apps={data.apps.modules} />
56-
57-
<Profile user={data.user} />
49+
{!loading && (
50+
<>
51+
<Title
52+
app={appName}
53+
instance={data.systemInfo.systemName}
54+
/>
55+
<div className="right-control-spacer" />
56+
<Notifications
57+
interpretations={
58+
data.notifications.unreadInterpretations
59+
}
60+
messages={data.notifications.unreadMessageConversations}
61+
/>
62+
<Apps apps={data.apps.modules} />
63+
<Profile user={data.user} />
64+
</>
65+
)}
5866

5967
<style jsx>{`
6068
header {
@@ -67,6 +75,9 @@ export const HeaderBar = ({ appName, className }) => {
6775
border-bottom: 1px solid rgba(32, 32, 32, 0.15);
6876
color: ${colors.white};
6977
}
78+
.right-control-spacer {
79+
margin-left: auto;
80+
}
7081
`}</style>
7182
</header>
7283
)

stories/HeaderBar.stories.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,14 @@ const customData = {
7474
},
7575
}
7676

77-
storiesOf('HeaderBar', module).add('Default', () => (
78-
<CustomDataProvider data={customData}>
79-
<HeaderBar appName="Example!" />
80-
</CustomDataProvider>
81-
))
77+
storiesOf('HeaderBar', module)
78+
.add('Default', () => (
79+
<CustomDataProvider data={customData}>
80+
<HeaderBar appName="Example!" />
81+
</CustomDataProvider>
82+
))
83+
.add('Loading...', () => (
84+
<CustomDataProvider options={{ loadForever: true }}>
85+
<HeaderBar appName="Example!" />
86+
</CustomDataProvider>
87+
))

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,10 +1441,10 @@
14411441
dependencies:
14421442
find-up "^2.1.0"
14431443

1444-
"@dhis2/app-runtime@1.1.0":
1445-
version "1.1.0"
1446-
resolved "https://registry.yarnpkg.com/@dhis2/app-runtime/-/app-runtime-1.1.0.tgz#0b6256f7c61428ab62e7b2403338c2fbf6b28530"
1447-
integrity sha512-0fJ61KeHRF2FsGVoSdogUX1zCOCoFWa6jJdPJl6GPUo8IaR//Fv7PYQvTuSUMAIO61dOmnh1pAQ8ouf8Ip7lyw==
1444+
"@dhis2/app-runtime@1.2.0":
1445+
version "1.2.0"
1446+
resolved "https://registry.yarnpkg.com/@dhis2/app-runtime/-/app-runtime-1.2.0.tgz#87e22d817a13d45a7d89d854e6152cfd959ec55d"
1447+
integrity sha512-2JOKPYIdNVpb6vVwuqmO+1ERelUdOYqFgWJDD2xnMNWYhNOPxvqi8v5rPLaOfTsUWeQ0RgBukPfRRJbBSqkipw==
14481448

14491449
"@dhis2/cli-helpers-engine@^1.0.1":
14501450
version "1.0.1"

0 commit comments

Comments
 (0)