This topic provides examples of Quick BI features.
Drill-down /Linkage /Jump
Style isolation
Since the scope of CSS selectors is global, it is easy to cause selector conflicts. In order to ensure that the style of the custom component you write does not affect Quick BI other components, style isolation can be achieved in the following ways.
Shadow DOM
Shadow DOM can hide tags, styles, and behaviors from the rest of the code on the page, ensuring that different parts don't get mixed up. In Quick BI, custom components are rendered within the shadow DOM node by default. If you do not need to enable shadow DOM, you can manually disable it in the custom component management platform.
When using the Shadow DOM, we recommend that you use a browser with the IE 11 technology version.
CSS Modules
CSS Modules means that we introduce our CSS code like JS modules. Each class name in the code is an attribute of the introduced object. The CSS class name will be added with a unique hash value at compile time.
If your custom components need to support lower-version browsers, it is recommended to use CSS Modules isolation styles. CSS Modules are already built in the seed project. As long as files ending in .module.css or .module.css can be directly imported,
// index.module.css
.test-class {
color: #ddd;
}
// Compiled index.module.css
._2GdXV4wBykbQ3MN-f1VJv7 {
color: #ddd;
}
import styles from './index.css';
// Use the class
document.getElementById('foo').classList.add(styles['test-class'])BEM Specification
If you don't want to use CSS Modules, you need to ensure that the style class names are unique.
CSS doesn't really have a namespace. . To simulate a namespace, we recommend that you use the CSS BEM specification.
// good. All styles are written in the. my-component parent class.
.my-component {
color: #ddd;
ul {
color: #aaa
}
&__header {}
&__header--title {}
}
// bad, try not to define the style outside the parent class
ul {
background: #aaa
}Internationalization
Custom components can localize content into the relevant language by bi-open-sdk or bi-open-react-sdk -provided I18n classes.
Initialization
Internationalization can be initialized through I18n.init. First, the translated language is assembled into resources in the form of keys and values, and then t translation functions and i18n instances are exported. Example:
import { I18n } from 'bi-open-sdk';
const { t, i18n } = I18n.init({
resources: {
// English key
'en-US': {
Start angle: 'start angle',
},
// The Japanese key.
'ja-JP': {
Start Angle: 'Start Angle',
}
},
});In this example, two languages are set: en-US and ja-JP. The following table lists the supported languages.
Region String | Language |
zh-CN | Simplified Chinese (default) |
en-US | English |
ja-JP | Japanese |
Translation functions
You can call the t function to translate languages, t the return value of the function depends on the language package configured resources. If the corresponding slave translation is not configured in the resources, the t function will return the first parameter value.
console.log(t ('Start angle')) // Start angle
console.log(t ('End angle')) // The end angle is not translated in resources. The end angle is returned. Change the language
You can switch languages through the i18n.changeLanguage. Generally speaking, the Quick BI has built-in logic for language switching without manually calling the i18n.changeLanguage.
// The default language is zh-CN.
console.log(t ('Start angle')) // Start angle
i18n.changeLanguage('en-US') // You do not need to manually call the
console.log(t ('Start angle')) // start angle
i18n.changeLanguage (ja-JP) // You do not need to manually call the
console.log(t ('Start angle')) // Start angle Splice entry
If a splice entry is available, you can pass the second parameter of the t function.
const { t, i18n } = I18n.init({
resources: {
'en-US': {
'My {{version}} {{item}}': 'My my {{version}} {{item}}',
'New': 'new',
'Mobile phone': 'cellphone'
},
},
});
// Splice the two entries "new" and "mobile phone".
console.log(t ('My {{version}}{{item}}', { item: t ('Phone'), version: t ('New') })) // my new cellphone single and plural translation
Some languages have singular and plural numbers. In order to deal with this situation, _plural suffix can be added to the end of the key of the term that needs to deal with plural numbers in the resources to represent the translation of plural forms.
const { t, i18n } = I18n.init({
resources: {
'en-US': {
'{{count}} an apple': '{{count}} apple', // singular translation
'{{count}} apples_plural': '{{count}} apples', // Plural translation
},
},
});
console.log(t ('Apple' {{count}}, { count: 3 })) // 3 apples
console.log(t ('Apples {{count}} ', { count: 1 })) // 1 apple Get the current language
Generally, you do not need to manually set the current language in the Quick BI. The SDK has built-in logic for recognizing the current language. If you must obtain the current language, you can use one of the following methods to obtain the current language:
const currentLang = window.globalConfig.currentLang
const currentLang = i18n.lngPerformance improvements:
Here are some suggestions on how to achieve the best performance for custom components.
Update the SDK for Go
As we continue to improve and enhance the platform, new versions of the API will be released continuously. To take full advantage of the features of the Quick BI platform, it is recommended to use the latest version of the bi-open-sdk or bi-open-react-sdk to stay current.
Decrease packing volume
Quick BI provides the following public libraries:
react - 16.12.0
react-dom - 16.12.0
lodash - 4.17.20
moment - 2.29.1
These libraries are injected into the global variables of the sandbox. To ensure the best performance of your components, we recommend that you use these public libraries.
The Quick BI immediately executes the meta.js of the custom component when entering the page. To ensure the speed of loading the first screen of the dashboard, do not introduce too many third-party libraries into the meta.js to ensure that the volume of the meta.js after compilation is small enough.
Caching DOM nodes
When retrieving nodes or node list from the DOM, you need to consider whether you can reuse them in subsequent calculations (sometimes even the next loop iteration). Caching them improves the overall efficiency of your application as long as you do not need to add or remove additional nodes in the relevant area.
Avoid DOM manipulation
Restrict DOM manipulation as much as possible. Insertion operations such as prepend(), append(), and after() are time-consuming and should not be used unless necessary.