@dhis2-ui/header-bar 10.9.1 → 10.10.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/header-bar.js +21 -11
- package/build/cjs/header-bar.prod.stories.js +22 -2
- package/build/es/header-bar.js +22 -12
- package/build/es/header-bar.prod.stories.js +18 -1
- package/package.json +15 -15
- package/types/index.d.ts +1 -0
package/build/cjs/header-bar.js
CHANGED
|
@@ -42,12 +42,13 @@ const query = {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
const HeaderBar = _ref => {
|
|
45
|
-
var _data$user$avatar;
|
|
45
|
+
var _data$user2, _data$user2$settings, _data$user$avatar;
|
|
46
46
|
let {
|
|
47
47
|
appName,
|
|
48
48
|
className,
|
|
49
49
|
updateAvailable,
|
|
50
|
-
onApplyAvailableUpdate
|
|
50
|
+
onApplyAvailableUpdate,
|
|
51
|
+
skipI18n
|
|
51
52
|
} = _ref;
|
|
52
53
|
const {
|
|
53
54
|
appName: configAppName,
|
|
@@ -67,15 +68,18 @@ const HeaderBar = _ref => {
|
|
|
67
68
|
defaultAction: getPath(app.defaultAction)
|
|
68
69
|
}));
|
|
69
70
|
}, [data, baseUrl]);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
(0, _react.useEffect)(() => {
|
|
72
|
+
if (!loading && !error && !skipI18n) {
|
|
73
|
+
var _data$user, _data$user$settings;
|
|
74
|
+
// This is the "legacy" way of localising the header bar, which is necesasry for external (non-platform) apps
|
|
75
|
+
// For platform apps, setting i18n is handled by the app-shell so this logic is redundant (and running it twice caused issues)
|
|
76
|
+
// For external apps, this logic is kept for backwards compatibility, but they also have the option of passing `skipI18n`
|
|
77
|
+
// and initialising i18n in the consumer
|
|
78
|
+
const locale = (data === null || data === void 0 ? void 0 : (_data$user = data.user) === null || _data$user === void 0 ? void 0 : (_data$user$settings = _data$user.settings) === null || _data$user$settings === void 0 ? void 0 : _data$user$settings.keyUiLocale) || 'en';
|
|
79
|
+
_index.default.setDefaultNamespace('default');
|
|
80
|
+
_index.default.changeLanguage(locale);
|
|
81
|
+
}
|
|
82
|
+
}, [data === null || data === void 0 ? void 0 : (_data$user2 = data.user) === null || _data$user2 === void 0 ? void 0 : (_data$user2$settings = _data$user2.settings) === null || _data$user2$settings === void 0 ? void 0 : _data$user2$settings.keyUiLocale, error, loading, skipI18n]);
|
|
79
83
|
return /*#__PURE__*/_react.default.createElement(_headerBarContext.HeaderBarContextProvider, {
|
|
80
84
|
updateAvailable: updateAvailable,
|
|
81
85
|
onApplyAvailableUpdate: onApplyAvailableUpdate
|
|
@@ -110,6 +114,12 @@ exports.HeaderBar = HeaderBar;
|
|
|
110
114
|
HeaderBar.propTypes = {
|
|
111
115
|
appName: _propTypes.default.string,
|
|
112
116
|
className: _propTypes.default.string,
|
|
117
|
+
/**
|
|
118
|
+
* `skipI18n` skips initalising internationalisation in the UI component
|
|
119
|
+
* This is useful for app-platform apps, as the platform already sets i18n, so it can skip i18n (and avoid race conditions).
|
|
120
|
+
* For non-platform apps, they can continue relying on this logic running for backwards compatibility.
|
|
121
|
+
* */
|
|
122
|
+
skipI18n: _propTypes.default.bool,
|
|
113
123
|
updateAvailable: _propTypes.default.bool,
|
|
114
124
|
onApplyAvailableUpdate: _propTypes.default.func
|
|
115
125
|
};
|
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.WithUpdateNotification = exports.WithOnlineStatusMessage = exports.WithOnlineStatus = exports.RTLHeader = exports.NonEnglishUserLocale = exports.NoAuthorityForInterpretationsApp = exports.Loading = exports.Error = exports.Default = exports.CustomLogoWideDimension = void 0;
|
|
6
|
+
exports.default = exports.WithUpdateNotification = exports.WithOnlineStatusMessage = exports.WithOnlineStatus = exports.RTLHeader = exports.NonEnglishUserLocaleIgnoringI18n = exports.NonEnglishUserLocale = exports.NoAuthorityForInterpretationsApp = exports.Loading = exports.Error = exports.Default = exports.CustomLogoWideDimension = void 0;
|
|
7
7
|
var _appRuntime = require("@dhis2/app-runtime");
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _common = require("./__e2e__/stories/common.js");
|
|
10
10
|
var _onlineStatusMessage = require("./__e2e__/stories/online-status-message.js");
|
|
11
11
|
var _headerBar = require("./header-bar.js");
|
|
12
|
+
var _index = _interopRequireDefault(require("./locales/index.js"));
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
16
|
const subtitle = 'The common navigation bar used in all DHIS2 apps';
|
|
14
17
|
const description = `
|
|
15
18
|
The header bar is mandatory for all apps. This creates a stable, understandable point of reference for the user across all kinds of different apps. It must always be displayed fixed to the top of the screen. Do not interfere or obstruct interaction with the header bar.
|
|
@@ -183,6 +186,23 @@ const NonEnglishUserLocale = () => /*#__PURE__*/_react.default.createElement(_ap
|
|
|
183
186
|
}));
|
|
184
187
|
exports.NonEnglishUserLocale = NonEnglishUserLocale;
|
|
185
188
|
NonEnglishUserLocale.storyName = 'Non-english user locale';
|
|
189
|
+
const NonEnglishUserLocaleIgnoringI18n = () => {
|
|
190
|
+
const [language, setLanguage] = (0, _react.useState)();
|
|
191
|
+
(0, _react.useEffect)(() => {
|
|
192
|
+
console.log('custom effect to set language from consumer');
|
|
193
|
+
_index.default.setDefaultNamespace('default');
|
|
194
|
+
_index.default.changeLanguage('es');
|
|
195
|
+
setLanguage('es');
|
|
196
|
+
}, []);
|
|
197
|
+
return language ? /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
198
|
+
data: customLocaleData
|
|
199
|
+
}, /*#__PURE__*/_react.default.createElement(_headerBar.HeaderBar, {
|
|
200
|
+
appName: "Exemple!",
|
|
201
|
+
skipI18n: true
|
|
202
|
+
})) : null;
|
|
203
|
+
};
|
|
204
|
+
exports.NonEnglishUserLocaleIgnoringI18n = NonEnglishUserLocaleIgnoringI18n;
|
|
205
|
+
NonEnglishUserLocaleIgnoringI18n.storyName = 'Custom locale initialisation (spanish) from the consumer';
|
|
186
206
|
const NoAuthorityForInterpretationsApp = () => /*#__PURE__*/_react.default.createElement(_appRuntime.CustomDataProvider, {
|
|
187
207
|
data: customAuthoritiesData
|
|
188
208
|
}, /*#__PURE__*/_react.default.createElement(_headerBar.HeaderBar, {
|
package/build/es/header-bar.js
CHANGED
|
@@ -2,7 +2,7 @@ import _JSXStyle from "styled-jsx/style";
|
|
|
2
2
|
import { useDataQuery, useConfig } from '@dhis2/app-runtime';
|
|
3
3
|
import { colors } from '@dhis2/ui-constants';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
|
-
import React, { useMemo } from 'react';
|
|
5
|
+
import React, { useEffect, useMemo } from 'react';
|
|
6
6
|
import Apps from './apps.js';
|
|
7
7
|
import { HeaderBarContextProvider } from './header-bar-context.js';
|
|
8
8
|
import { joinPath } from './join-path.js';
|
|
@@ -33,12 +33,13 @@ const query = {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
export const HeaderBar = _ref => {
|
|
36
|
-
var _data$user$avatar;
|
|
36
|
+
var _data$user2, _data$user2$settings, _data$user$avatar;
|
|
37
37
|
let {
|
|
38
38
|
appName,
|
|
39
39
|
className,
|
|
40
40
|
updateAvailable,
|
|
41
|
-
onApplyAvailableUpdate
|
|
41
|
+
onApplyAvailableUpdate,
|
|
42
|
+
skipI18n
|
|
42
43
|
} = _ref;
|
|
43
44
|
const {
|
|
44
45
|
appName: configAppName,
|
|
@@ -58,15 +59,18 @@ export const HeaderBar = _ref => {
|
|
|
58
59
|
defaultAction: getPath(app.defaultAction)
|
|
59
60
|
}));
|
|
60
61
|
}, [data, baseUrl]);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!loading && !error && !skipI18n) {
|
|
64
|
+
var _data$user, _data$user$settings;
|
|
65
|
+
// This is the "legacy" way of localising the header bar, which is necesasry for external (non-platform) apps
|
|
66
|
+
// For platform apps, setting i18n is handled by the app-shell so this logic is redundant (and running it twice caused issues)
|
|
67
|
+
// For external apps, this logic is kept for backwards compatibility, but they also have the option of passing `skipI18n`
|
|
68
|
+
// and initialising i18n in the consumer
|
|
69
|
+
const locale = (data === null || data === void 0 ? void 0 : (_data$user = data.user) === null || _data$user === void 0 ? void 0 : (_data$user$settings = _data$user.settings) === null || _data$user$settings === void 0 ? void 0 : _data$user$settings.keyUiLocale) || 'en';
|
|
70
|
+
i18n.setDefaultNamespace('default');
|
|
71
|
+
i18n.changeLanguage(locale);
|
|
72
|
+
}
|
|
73
|
+
}, [data === null || data === void 0 ? void 0 : (_data$user2 = data.user) === null || _data$user2 === void 0 ? void 0 : (_data$user2$settings = _data$user2.settings) === null || _data$user2$settings === void 0 ? void 0 : _data$user2$settings.keyUiLocale, error, loading, skipI18n]);
|
|
70
74
|
return /*#__PURE__*/React.createElement(HeaderBarContextProvider, {
|
|
71
75
|
updateAvailable: updateAvailable,
|
|
72
76
|
onApplyAvailableUpdate: onApplyAvailableUpdate
|
|
@@ -100,6 +104,12 @@ export const HeaderBar = _ref => {
|
|
|
100
104
|
HeaderBar.propTypes = {
|
|
101
105
|
appName: PropTypes.string,
|
|
102
106
|
className: PropTypes.string,
|
|
107
|
+
/**
|
|
108
|
+
* `skipI18n` skips initalising internationalisation in the UI component
|
|
109
|
+
* This is useful for app-platform apps, as the platform already sets i18n, so it can skip i18n (and avoid race conditions).
|
|
110
|
+
* For non-platform apps, they can continue relying on this logic running for backwards compatibility.
|
|
111
|
+
* */
|
|
112
|
+
skipI18n: PropTypes.bool,
|
|
103
113
|
updateAvailable: PropTypes.bool,
|
|
104
114
|
onApplyAvailableUpdate: PropTypes.func
|
|
105
115
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CustomDataProvider } from '@dhis2/app-runtime';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import { createDecoratorProvider, mockOfflineInterface, providerConfig } from './__e2e__/stories/common.js';
|
|
4
4
|
import { OnlineStatusMessageUpdate } from './__e2e__/stories/online-status-message.js';
|
|
5
5
|
import { HeaderBar } from './header-bar.js';
|
|
6
|
+
import i18n from './locales/index.js';
|
|
6
7
|
const subtitle = 'The common navigation bar used in all DHIS2 apps';
|
|
7
8
|
const description = `
|
|
8
9
|
The header bar is mandatory for all apps. This creates a stable, understandable point of reference for the user across all kinds of different apps. It must always be displayed fixed to the top of the screen. Do not interfere or obstruct interaction with the header bar.
|
|
@@ -173,6 +174,22 @@ export const NonEnglishUserLocale = () => /*#__PURE__*/React.createElement(Custo
|
|
|
173
174
|
appName: "Exemple!"
|
|
174
175
|
}));
|
|
175
176
|
NonEnglishUserLocale.storyName = 'Non-english user locale';
|
|
177
|
+
export const NonEnglishUserLocaleIgnoringI18n = () => {
|
|
178
|
+
const [language, setLanguage] = useState();
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
console.log('custom effect to set language from consumer');
|
|
181
|
+
i18n.setDefaultNamespace('default');
|
|
182
|
+
i18n.changeLanguage('es');
|
|
183
|
+
setLanguage('es');
|
|
184
|
+
}, []);
|
|
185
|
+
return language ? /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
186
|
+
data: customLocaleData
|
|
187
|
+
}, /*#__PURE__*/React.createElement(HeaderBar, {
|
|
188
|
+
appName: "Exemple!",
|
|
189
|
+
skipI18n: true
|
|
190
|
+
})) : null;
|
|
191
|
+
};
|
|
192
|
+
NonEnglishUserLocaleIgnoringI18n.storyName = 'Custom locale initialisation (spanish) from the consumer';
|
|
176
193
|
export const NoAuthorityForInterpretationsApp = () => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
177
194
|
data: customAuthoritiesData
|
|
178
195
|
}, /*#__PURE__*/React.createElement(HeaderBar, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/header-bar",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.10.0-alpha.1",
|
|
4
4
|
"description": "UI HeaderBar",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,21 +34,21 @@
|
|
|
34
34
|
"styled-jsx": "^4"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@dhis2-ui/box": "10.
|
|
38
|
-
"@dhis2-ui/button": "10.
|
|
39
|
-
"@dhis2-ui/card": "10.
|
|
40
|
-
"@dhis2-ui/center": "10.
|
|
41
|
-
"@dhis2-ui/divider": "10.
|
|
42
|
-
"@dhis2-ui/input": "10.
|
|
43
|
-
"@dhis2-ui/layer": "10.
|
|
44
|
-
"@dhis2-ui/loader": "10.
|
|
45
|
-
"@dhis2-ui/logo": "10.
|
|
46
|
-
"@dhis2-ui/menu": "10.
|
|
47
|
-
"@dhis2-ui/modal": "10.
|
|
48
|
-
"@dhis2-ui/user-avatar": "10.
|
|
37
|
+
"@dhis2-ui/box": "10.10.0-alpha.1",
|
|
38
|
+
"@dhis2-ui/button": "10.10.0-alpha.1",
|
|
39
|
+
"@dhis2-ui/card": "10.10.0-alpha.1",
|
|
40
|
+
"@dhis2-ui/center": "10.10.0-alpha.1",
|
|
41
|
+
"@dhis2-ui/divider": "10.10.0-alpha.1",
|
|
42
|
+
"@dhis2-ui/input": "10.10.0-alpha.1",
|
|
43
|
+
"@dhis2-ui/layer": "10.10.0-alpha.1",
|
|
44
|
+
"@dhis2-ui/loader": "10.10.0-alpha.1",
|
|
45
|
+
"@dhis2-ui/logo": "10.10.0-alpha.1",
|
|
46
|
+
"@dhis2-ui/menu": "10.10.0-alpha.1",
|
|
47
|
+
"@dhis2-ui/modal": "10.10.0-alpha.1",
|
|
48
|
+
"@dhis2-ui/user-avatar": "10.10.0-alpha.1",
|
|
49
49
|
"@dhis2/prop-types": "^3.1.2",
|
|
50
|
-
"@dhis2/ui-constants": "10.
|
|
51
|
-
"@dhis2/ui-icons": "10.
|
|
50
|
+
"@dhis2/ui-constants": "10.10.0-alpha.1",
|
|
51
|
+
"@dhis2/ui-icons": "10.10.0-alpha.1",
|
|
52
52
|
"classnames": "^2.3.1",
|
|
53
53
|
"moment": "^2.29.1",
|
|
54
54
|
"prop-types": "^15.7.2"
|