@gitlab/ui 49.0.0 → 49.0.2
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/CHANGELOG.md +14 -0
- package/dist/components/base/accordion/accordion.js +2 -8
- package/dist/components/base/accordion/accordion_item.js +0 -14
- package/dist/components/base/alert/alert.js +4 -22
- package/dist/components/base/avatar/avatar.js +0 -7
- package/dist/components/base/avatar_labeled/avatar_labeled.js +0 -2
- package/dist/components/base/avatars_inline/avatars_inline.js +2 -10
- package/dist/components/base/badge/badge.js +0 -8
- package/dist/components/base/banner/banner.js +0 -10
- package/dist/components/base/breadcrumb/breadcrumb.js +0 -12
- package/dist/components/base/breadcrumb/breadcrumb_item.js +0 -2
- package/dist/components/base/broadcast_message/broadcast_message.js +0 -3
- package/dist/components/base/button/button.js +0 -11
- package/dist/components/base/card/card.js +1 -2
- package/dist/components/base/datepicker/datepicker.js +7 -42
- package/dist/components/base/daterange_picker/daterange_picker.js +0 -23
- package/dist/components/base/drawer/drawer.js +0 -13
- package/dist/components/base/dropdown/dropdown.js +3 -17
- package/dist/components/base/dropdown/dropdown_item.js +2 -8
- package/dist/components/base/filtered_search/common_story_options.js +1 -2
- package/dist/components/base/filtered_search/filtered_search.js +9 -61
- package/dist/components/base/filtered_search/filtered_search_suggestion.js +0 -6
- package/dist/components/base/filtered_search/filtered_search_suggestion_list.js +0 -16
- package/dist/components/base/filtered_search/filtered_search_term.js +0 -9
- package/dist/components/base/filtered_search/filtered_search_token.js +10 -49
- package/dist/components/base/filtered_search/filtered_search_token_segment.js +3 -56
- package/dist/components/base/filtered_search/filtered_search_utils.js +7 -24
- package/dist/components/base/form/form_checkbox/form_checkbox.js +0 -2
- package/dist/components/base/form/form_checkbox_tree/checkbox_tree_node.js +0 -4
- package/dist/components/base/form/form_checkbox_tree/form_checkbox_tree.js +0 -10
- package/dist/components/base/form/form_checkbox_tree/models/node.js +1 -10
- package/dist/components/base/form/form_checkbox_tree/models/tree.js +16 -37
- package/dist/components/base/form/form_combobox/form_combobox.js +2 -36
- package/dist/components/base/form/form_group/form_group.js +2 -7
- package/dist/components/base/form/form_input/form_input.js +2 -8
- package/dist/components/base/form/form_input_group/form_input_group.js +0 -5
- package/dist/components/base/form/form_input_group/form_input_group_mixin.js +0 -8
- package/dist/components/base/form/form_radio_group/form_radio_group.js +0 -2
- package/dist/components/base/form/form_select/form_select.js +0 -3
- package/dist/components/base/form/form_textarea/form_textarea.js +2 -7
- package/dist/components/base/icon/icon.js +4 -14
- package/dist/components/base/infinite_scroll/infinite_scroll.js +7 -21
- package/dist/components/base/keyset_pagination/keyset_pagination.js +0 -9
- package/dist/components/base/label/label.js +0 -12
- package/dist/components/base/loading_icon/loading_icon.js +7 -10
- package/dist/components/base/markdown/markdown.js +1 -0
- package/dist/components/base/modal/modal.js +7 -27
- package/dist/components/base/new_dropdowns/base_dropdown/base_dropdown.js +14 -34
- package/dist/components/base/new_dropdowns/constants.js +4 -2
- package/dist/components/base/new_dropdowns/listbox/listbox.js +14 -81
- package/dist/components/base/new_dropdowns/listbox/listbox_group.js +0 -2
- package/dist/components/base/new_dropdowns/listbox/listbox_item.js +0 -5
- package/dist/components/base/new_dropdowns/listbox/utils.js +0 -7
- package/dist/components/base/paginated_list/paginated_list.js +0 -15
- package/dist/components/base/pagination/pagination.js +14 -72
- package/dist/components/base/path/path.js +0 -29
- package/dist/components/base/popover/popover.js +0 -5
- package/dist/components/base/search_box_by_click/search_box_by_click.js +1 -26
- package/dist/components/base/search_box_by_type/search_box_by_type.js +2 -12
- package/dist/components/base/segmented_control/segmented_control.js +0 -10
- package/dist/components/base/skeleton_loader/skeleton_loader.js +0 -19
- package/dist/components/base/skeleton_loading/skeleton_loading.js +0 -3
- package/dist/components/base/sorting/sorting.js +1 -9
- package/dist/components/base/sorting/sorting_item.js +4 -6
- package/dist/components/base/table/table.js +0 -4
- package/dist/components/base/tabs/tab/tab.js +2 -6
- package/dist/components/base/tabs/tabs/scrollable_tabs.js +0 -21
- package/dist/components/base/tabs/tabs/tabs.js +8 -33
- package/dist/components/base/toast/toast.js +3 -15
- package/dist/components/base/toggle/toggle.js +0 -18
- package/dist/components/base/token/token.js +0 -4
- package/dist/components/base/token_selector/token_container.js +0 -24
- package/dist/components/base/token_selector/token_selector.js +10 -61
- package/dist/components/base/token_selector/token_selector_dropdown.js +4 -32
- package/dist/components/charts/area/area.js +8 -32
- package/dist/components/charts/bar/bar.js +7 -19
- package/dist/components/charts/chart/chart.js +1 -22
- package/dist/components/charts/column/column.js +8 -18
- package/dist/components/charts/discrete_scatter/discrete_scatter.js +2 -13
- package/dist/components/charts/gauge/gauge.js +0 -15
- package/dist/components/charts/heatmap/heatmap.js +3 -16
- package/dist/components/charts/legend/legend.js +2 -24
- package/dist/components/charts/line/line.js +8 -34
- package/dist/components/charts/series_label/series_label.js +0 -12
- package/dist/components/charts/single_stat/single_stat.js +0 -8
- package/dist/components/charts/sparkline/sparkline.js +1 -16
- package/dist/components/charts/stacked_column/stacked_column.js +8 -26
- package/dist/components/charts/tooltip/tooltip.js +0 -6
- package/dist/components/mixins/button_mixin.js +0 -1
- package/dist/components/mixins/safe_link_mixin.js +0 -1
- package/dist/components/mixins/toolbox_mixin.js +0 -1
- package/dist/components/mixins/tooltip_mixin.js +1 -2
- package/dist/components/regions/empty_state/empty_state.js +0 -12
- package/dist/components/utilities/animated_number/animated_number.js +0 -16
- package/dist/components/utilities/friendly_wrap/friendly_wrap.js +0 -3
- package/dist/components/utilities/intersection_observer/intersection_observer.js +0 -7
- package/dist/components/utilities/intersperse/intersperse.js +3 -9
- package/dist/components/utilities/sprintf/sprintf.js +9 -23
- package/dist/components/utilities/truncate/truncate.js +0 -10
- package/dist/config.js +3 -4
- package/dist/directives/hover_load/hover_load.js +2 -8
- package/dist/directives/outside/get_event_like_time_stamp.js +4 -2
- package/dist/directives/outside/outside.js +5 -20
- package/dist/directives/resize_observer/resize_observer.js +0 -10
- package/dist/directives/safe_html/safe_html.js +5 -6
- package/dist/directives/safe_link/mock_data.js +1 -1
- package/dist/directives/safe_link/safe_link.js +0 -13
- package/dist/utils/breakpoints.js +0 -3
- package/dist/utils/charts/config.js +29 -42
- package/dist/utils/charts/constants.js +8 -8
- package/dist/utils/charts/mock_data.js +2 -2
- package/dist/utils/charts/story_config.js +1 -1
- package/dist/utils/charts/theme.js +1 -3
- package/dist/utils/charts/utils.js +2 -6
- package/dist/utils/constants.js +10 -7
- package/dist/utils/data_utils.js +5 -4
- package/dist/utils/datetime_utility.js +4 -4
- package/dist/utils/number_utils.js +7 -11
- package/dist/utils/stories_utils.js +1 -1
- package/dist/utils/story_decorators/container.js +0 -1
- package/dist/utils/string_utils.js +0 -14
- package/dist/utils/test_utils.js +3 -2
- package/dist/utils/use_fake_date.js +0 -4
- package/dist/utils/use_mock_intersection_observer.js +4 -19
- package/dist/utils/utils.js +5 -14
- package/package.json +3 -3
- package/src/components/base/new_dropdowns/base_dropdown/base_dropdown.spec.js +1 -0
- package/src/components/base/new_dropdowns/base_dropdown/base_dropdown.vue +13 -7
- package/src/components/base/new_dropdowns/listbox/listbox.spec.js +13 -7
- package/src/components/base/new_dropdowns/listbox/listbox.vue +12 -16
- package/src/components/base/pagination/pagination.vue +2 -2
|
@@ -3,27 +3,25 @@ import { getEventLikeTimeStamp } from './get_event_like_time_stamp';
|
|
|
3
3
|
/**
|
|
4
4
|
* Map<HTMLElement, { bindTimeStamp: number, callback: Function }>
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
6
|
const callbacks = new Map();
|
|
7
|
+
|
|
8
8
|
/**
|
|
9
9
|
* Is a global listener already set up?
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
11
|
let listening = false;
|
|
13
|
-
|
|
14
12
|
const globalListener = event => {
|
|
15
13
|
callbacks.forEach((_ref, element) => {
|
|
16
14
|
let {
|
|
17
15
|
bindTimeStamp,
|
|
18
16
|
callback
|
|
19
17
|
} = _ref;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
element.contains(event.target) ||
|
|
18
|
+
if (
|
|
19
|
+
// Ignore events that aren't targeted outside the element
|
|
20
|
+
element.contains(event.target) ||
|
|
21
|
+
// Only consider events triggered after the directive was bound
|
|
23
22
|
event.timeStamp <= bindTimeStamp) {
|
|
24
23
|
return;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
try {
|
|
28
26
|
callback(event);
|
|
29
27
|
} catch (e) {
|
|
@@ -34,41 +32,33 @@ const globalListener = event => {
|
|
|
34
32
|
}
|
|
35
33
|
});
|
|
36
34
|
};
|
|
37
|
-
|
|
38
35
|
const startListening = () => {
|
|
39
36
|
if (listening) {
|
|
40
37
|
return;
|
|
41
38
|
}
|
|
42
|
-
|
|
43
39
|
document.addEventListener('click', globalListener, {
|
|
44
40
|
capture: true
|
|
45
41
|
});
|
|
46
42
|
listening = true;
|
|
47
43
|
};
|
|
48
|
-
|
|
49
44
|
const stopListening = () => {
|
|
50
45
|
if (!listening) {
|
|
51
46
|
return;
|
|
52
47
|
}
|
|
53
|
-
|
|
54
48
|
document.removeEventListener('click', globalListener);
|
|
55
49
|
listening = false;
|
|
56
50
|
};
|
|
57
|
-
|
|
58
51
|
const bind = (el, _ref2) => {
|
|
59
52
|
let {
|
|
60
53
|
value,
|
|
61
54
|
arg = 'click'
|
|
62
55
|
} = _ref2;
|
|
63
|
-
|
|
64
56
|
if (typeof value !== 'function') {
|
|
65
57
|
throw new Error(`[GlOutsideDirective] Value must be a function; got ${typeof value}!`);
|
|
66
58
|
}
|
|
67
|
-
|
|
68
59
|
if (arg !== 'click') {
|
|
69
60
|
throw new Error(`[GlOutsideDirective] Cannot bind ${arg} events; only click events are currently supported!`);
|
|
70
61
|
}
|
|
71
|
-
|
|
72
62
|
if (callbacks.has(el)) {
|
|
73
63
|
// This element is already bound. This is possible if two components, which
|
|
74
64
|
// share the same root node, (i.e., one is a higher-order component
|
|
@@ -81,25 +71,20 @@ const bind = (el, _ref2) => {
|
|
|
81
71
|
// element.
|
|
82
72
|
return;
|
|
83
73
|
}
|
|
84
|
-
|
|
85
74
|
if (!listening) {
|
|
86
75
|
startListening();
|
|
87
76
|
}
|
|
88
|
-
|
|
89
77
|
callbacks.set(el, {
|
|
90
78
|
bindTimeStamp: getEventLikeTimeStamp(),
|
|
91
79
|
callback: value
|
|
92
80
|
});
|
|
93
81
|
};
|
|
94
|
-
|
|
95
82
|
const unbind = el => {
|
|
96
83
|
callbacks.delete(el);
|
|
97
|
-
|
|
98
84
|
if (callbacks.size === 0) {
|
|
99
85
|
stopListening();
|
|
100
86
|
}
|
|
101
87
|
};
|
|
102
|
-
|
|
103
88
|
const OutsideDirective = {
|
|
104
89
|
bind,
|
|
105
90
|
unbind
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import isFunction from 'lodash/isFunction';
|
|
2
2
|
|
|
3
3
|
let observer = null;
|
|
4
|
-
|
|
5
4
|
const attachObserver = (el, resizeHandler) => {
|
|
6
5
|
if (!isFunction(resizeHandler)) {
|
|
7
6
|
throw TypeError('directive value must be a function');
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
if (!observer) {
|
|
11
9
|
// the observer instance is shared for performance reasons
|
|
12
10
|
// more information: https://github.com/WICG/ResizeObserver/issues/59
|
|
@@ -16,45 +14,37 @@ const attachObserver = (el, resizeHandler) => {
|
|
|
16
14
|
});
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
el.glResizeHandler = resizeHandler;
|
|
21
18
|
observer.observe(el);
|
|
22
19
|
};
|
|
23
|
-
|
|
24
20
|
const detachObserver = el => {
|
|
25
21
|
if (el.glResizeHandler) {
|
|
26
22
|
var _observer;
|
|
27
|
-
|
|
28
23
|
delete el.glResizeHandler;
|
|
29
24
|
(_observer = observer) === null || _observer === void 0 ? void 0 : _observer.unobserve(el);
|
|
30
25
|
}
|
|
31
26
|
};
|
|
32
|
-
|
|
33
27
|
const GlResizeObserverDirective = {
|
|
34
28
|
bind(el, _ref) {
|
|
35
29
|
let {
|
|
36
30
|
value: resizeHandler,
|
|
37
31
|
arg: enabled = true
|
|
38
32
|
} = _ref;
|
|
39
|
-
|
|
40
33
|
if (enabled) {
|
|
41
34
|
attachObserver(el, resizeHandler);
|
|
42
35
|
}
|
|
43
36
|
},
|
|
44
|
-
|
|
45
37
|
update(el, _ref2) {
|
|
46
38
|
let {
|
|
47
39
|
value: resizeHandler,
|
|
48
40
|
arg: enabled = true
|
|
49
41
|
} = _ref2;
|
|
50
|
-
|
|
51
42
|
if (enabled) {
|
|
52
43
|
attachObserver(el, resizeHandler);
|
|
53
44
|
} else {
|
|
54
45
|
detachObserver(el);
|
|
55
46
|
}
|
|
56
47
|
},
|
|
57
|
-
|
|
58
48
|
unbind: detachObserver
|
|
59
49
|
};
|
|
60
50
|
|
|
@@ -3,30 +3,29 @@ import { forbiddenDataAttrs } from './constants';
|
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
sanitize
|
|
6
|
-
} = DOMPurify;
|
|
6
|
+
} = DOMPurify;
|
|
7
|
+
|
|
8
|
+
// Mitigate against future dompurify mXSS bypasses by
|
|
7
9
|
// avoiding additional serialize/parse round trip.
|
|
8
10
|
// See https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/1782
|
|
9
11
|
// and https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/2127
|
|
10
12
|
// for more details.
|
|
11
|
-
|
|
12
13
|
const DEFAULT_CONFIG = {
|
|
13
14
|
RETURN_DOM_FRAGMENT: true,
|
|
14
15
|
ALLOW_UNKNOWN_PROTOCOLS: true,
|
|
15
16
|
FORBID_ATTR: [...forbiddenDataAttrs]
|
|
16
17
|
};
|
|
17
|
-
|
|
18
18
|
const transform = (el, binding) => {
|
|
19
19
|
if (binding.oldValue !== binding.value) {
|
|
20
20
|
var _binding$arg;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const config = {
|
|
22
|
+
...DEFAULT_CONFIG,
|
|
23
23
|
...((_binding$arg = binding.arg) !== null && _binding$arg !== void 0 ? _binding$arg : {})
|
|
24
24
|
};
|
|
25
25
|
el.textContent = '';
|
|
26
26
|
el.appendChild(sanitize(binding.value, config));
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
|
|
30
29
|
const SafeHtmlDirective = {
|
|
31
30
|
bind: transform,
|
|
32
31
|
update: transform
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const absoluteUrls = ['http://example.org', 'http://example.org:8080', 'https://example.org', 'https://example.org:8080', 'https://192.168.1.1', 'ftp://192.168.1.1', 'mailto:someone@example.com'];
|
|
2
|
-
/* eslint-disable no-script-url */
|
|
3
2
|
|
|
3
|
+
/* eslint-disable no-script-url */
|
|
4
4
|
const javascriptUrls = ['javascript:', 'javascript:alert("XSS")', 'jav\tascript:alert("XSS");'];
|
|
5
5
|
/* eslint-disable no-script-url */
|
|
6
6
|
|
|
@@ -7,25 +7,19 @@ const getBaseURL = () => {
|
|
|
7
7
|
} = window.location;
|
|
8
8
|
return `${protocol}//${host}`;
|
|
9
9
|
};
|
|
10
|
-
|
|
11
10
|
const isExternalURL = (target, hostname) => {
|
|
12
11
|
return target === '_blank' && hostname !== window.location.hostname;
|
|
13
12
|
};
|
|
14
|
-
|
|
15
13
|
const secureRel = rel => {
|
|
16
14
|
const rels = rel ? rel.trim().split(' ') : [];
|
|
17
|
-
|
|
18
15
|
if (!rels.includes('noopener')) {
|
|
19
16
|
rels.push('noopener');
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
if (!rels.includes('noreferrer')) {
|
|
23
19
|
rels.push('noreferrer');
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
return rels.join(' ');
|
|
27
22
|
};
|
|
28
|
-
|
|
29
23
|
const isSafeURL = url => {
|
|
30
24
|
try {
|
|
31
25
|
const parsedURL = new URL(url, getBaseURL());
|
|
@@ -34,41 +28,34 @@ const isSafeURL = url => {
|
|
|
34
28
|
return false;
|
|
35
29
|
}
|
|
36
30
|
};
|
|
37
|
-
|
|
38
31
|
const transform = function (el) {
|
|
39
32
|
let {
|
|
40
33
|
arg: {
|
|
41
34
|
skipSanitization = false
|
|
42
35
|
} = {}
|
|
43
36
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
44
|
-
|
|
45
37
|
if (skipSanitization) {
|
|
46
38
|
return;
|
|
47
39
|
}
|
|
48
|
-
|
|
49
40
|
const {
|
|
50
41
|
href,
|
|
51
42
|
target,
|
|
52
43
|
rel,
|
|
53
44
|
hostname
|
|
54
45
|
} = el;
|
|
55
|
-
|
|
56
46
|
if (!isSafeURL(href)) {
|
|
57
47
|
el.href = 'about:blank';
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
if (isExternalURL(target, hostname)) {
|
|
61
50
|
el.rel = secureRel(rel);
|
|
62
51
|
}
|
|
63
52
|
};
|
|
64
|
-
|
|
65
53
|
const SafeLinkDirective = {
|
|
66
54
|
inserted: transform,
|
|
67
55
|
update: function () {
|
|
68
56
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
69
57
|
args[_key] = arguments[_key];
|
|
70
58
|
}
|
|
71
|
-
|
|
72
59
|
Vue.nextTick(() => {
|
|
73
60
|
transform(...args);
|
|
74
61
|
});
|
|
@@ -7,17 +7,14 @@ const breakpoints = {
|
|
|
7
7
|
};
|
|
8
8
|
const BreakpointInstance = {
|
|
9
9
|
windowWidth: () => window.innerWidth,
|
|
10
|
-
|
|
11
10
|
getBreakpointSize() {
|
|
12
11
|
const windowWidth = this.windowWidth();
|
|
13
12
|
const breakpoint = Object.keys(breakpoints).find(key => windowWidth > breakpoints[key]);
|
|
14
13
|
return breakpoint;
|
|
15
14
|
},
|
|
16
|
-
|
|
17
15
|
isDesktop() {
|
|
18
16
|
return ['xl', 'lg'].includes(this.getBreakpointSize());
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
};
|
|
22
19
|
|
|
23
20
|
export default BreakpointInstance;
|
|
@@ -38,7 +38,8 @@ const grid = {
|
|
|
38
38
|
left: 64,
|
|
39
39
|
right: 32
|
|
40
40
|
};
|
|
41
|
-
const gridWithSecondaryYAxis = {
|
|
41
|
+
const gridWithSecondaryYAxis = {
|
|
42
|
+
...grid,
|
|
42
43
|
right: 64
|
|
43
44
|
};
|
|
44
45
|
const lineStyle = {
|
|
@@ -46,13 +47,13 @@ const lineStyle = {
|
|
|
46
47
|
type: 'line',
|
|
47
48
|
width: 2
|
|
48
49
|
};
|
|
50
|
+
|
|
49
51
|
/**
|
|
50
52
|
* Annotations series consists of annotations lines
|
|
51
53
|
* along with markers. Annotations co-exist with data
|
|
52
54
|
* series but have their own virtual coords so that they stay put
|
|
53
55
|
* irrespective of data series extents.
|
|
54
56
|
*/
|
|
55
|
-
|
|
56
57
|
const annotationsYAxisCoords = {
|
|
57
58
|
min: 0,
|
|
58
59
|
pos: 3,
|
|
@@ -61,22 +62,23 @@ const annotationsYAxisCoords = {
|
|
|
61
62
|
show: false
|
|
62
63
|
};
|
|
63
64
|
const symbolSize = 6;
|
|
65
|
+
|
|
64
66
|
/**
|
|
65
67
|
* These comparison operators are currently in monitoring
|
|
66
68
|
* charts that have alerting related data.
|
|
67
69
|
*
|
|
68
70
|
* {Array} Possible values for greater than
|
|
69
71
|
*/
|
|
70
|
-
|
|
71
72
|
const GREATER_THAN = ['>', '>'];
|
|
73
|
+
|
|
72
74
|
/**
|
|
73
75
|
* These comparison operators are currently in monitoring
|
|
74
76
|
* charts that have alerting related data.
|
|
75
77
|
*
|
|
76
78
|
* {Array} Possible values for less than
|
|
77
79
|
*/
|
|
78
|
-
|
|
79
80
|
const LESS_THAN = ['<', '<'];
|
|
81
|
+
|
|
80
82
|
/**
|
|
81
83
|
* All default dataZoom configs will have slider & inside
|
|
82
84
|
* (for reference, see https://gitlab.com/gitlab-org/gitlab-ui/issues/240)
|
|
@@ -84,7 +86,6 @@ const LESS_THAN = ['<', '<'];
|
|
|
84
86
|
* and is specifically to enable touch zoom for mobile devices
|
|
85
87
|
* @param {Object} options
|
|
86
88
|
*/
|
|
87
|
-
|
|
88
89
|
const getDataZoomConfig = function () {
|
|
89
90
|
let {
|
|
90
91
|
filterMode = 'none'
|
|
@@ -111,20 +112,23 @@ const getDataZoomConfig = function () {
|
|
|
111
112
|
disabled
|
|
112
113
|
}]
|
|
113
114
|
};
|
|
114
|
-
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// All chart options can be merged but series
|
|
115
118
|
// needs to be concatenated.
|
|
116
119
|
// Series can be an object for single series or
|
|
117
120
|
// an array of objects.
|
|
118
|
-
|
|
119
121
|
const mergeSeriesToOptions = function (options) {
|
|
120
122
|
let series = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
121
123
|
const {
|
|
122
124
|
series: optSeries = []
|
|
123
125
|
} = options;
|
|
124
|
-
return {
|
|
126
|
+
return {
|
|
127
|
+
...options,
|
|
125
128
|
series: [...castArray(series), ...castArray(optSeries)]
|
|
126
129
|
};
|
|
127
130
|
};
|
|
131
|
+
|
|
128
132
|
/**
|
|
129
133
|
* If an annotation series exists, the chart options should have an
|
|
130
134
|
* array of yAxis settings so that the series can exist in its own
|
|
@@ -134,10 +138,10 @@ const mergeSeriesToOptions = function (options) {
|
|
|
134
138
|
* @param {Boolean} hasAnnotations if annotation series yAxis should be merged
|
|
135
139
|
* @returns {Object} options
|
|
136
140
|
*/
|
|
137
|
-
|
|
138
141
|
const mergeAnnotationAxisToOptions = function (options) {
|
|
139
142
|
let hasAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
140
|
-
return {
|
|
143
|
+
return {
|
|
144
|
+
...options,
|
|
141
145
|
...(hasAnnotations && {
|
|
142
146
|
yAxis: [options.yAxis, annotationsYAxisCoords]
|
|
143
147
|
})
|
|
@@ -162,19 +166,16 @@ const getToolboxConfig = function () {
|
|
|
162
166
|
feature: {}
|
|
163
167
|
}
|
|
164
168
|
};
|
|
165
|
-
|
|
166
169
|
if (restoreIconPath.length) {
|
|
167
170
|
toolboxConfig.toolbox.feature.restore = {
|
|
168
171
|
icon: restoreIconPath
|
|
169
172
|
};
|
|
170
173
|
}
|
|
171
|
-
|
|
172
174
|
if (saveImageIconPath.length) {
|
|
173
175
|
toolboxConfig.toolbox.feature.saveAsImage = {
|
|
174
176
|
icon: restoreIconPath
|
|
175
177
|
};
|
|
176
178
|
}
|
|
177
|
-
|
|
178
179
|
if (zoomIconPath.length && backIconPath.length) {
|
|
179
180
|
toolboxConfig.toolbox.feature.dataZoom = {
|
|
180
181
|
icon: {
|
|
@@ -183,9 +184,9 @@ const getToolboxConfig = function () {
|
|
|
183
184
|
}
|
|
184
185
|
};
|
|
185
186
|
}
|
|
186
|
-
|
|
187
187
|
return toolboxConfig;
|
|
188
188
|
};
|
|
189
|
+
|
|
189
190
|
/**
|
|
190
191
|
* Generate eCharts markArea arrays for thresholds and annotations.
|
|
191
192
|
*
|
|
@@ -204,7 +205,6 @@ const getToolboxConfig = function () {
|
|
|
204
205
|
* @param {String} axis markArea is generated against this axis
|
|
205
206
|
* @returns {Array}
|
|
206
207
|
*/
|
|
207
|
-
|
|
208
208
|
const generateMarkArea = function (_ref) {
|
|
209
209
|
let {
|
|
210
210
|
min,
|
|
@@ -217,6 +217,7 @@ const generateMarkArea = function (_ref) {
|
|
|
217
217
|
[axis]: max
|
|
218
218
|
}];
|
|
219
219
|
};
|
|
220
|
+
|
|
220
221
|
/**
|
|
221
222
|
* Generate eCharts markLine objects for thresholds and annotations.
|
|
222
223
|
*
|
|
@@ -239,25 +240,22 @@ const generateMarkArea = function (_ref) {
|
|
|
239
240
|
* @param {String} axis markLine is generated against this axis
|
|
240
241
|
* @returns {Object}
|
|
241
242
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
243
|
const generateMarkLines = function (_ref2) {
|
|
245
244
|
let {
|
|
246
245
|
min,
|
|
247
246
|
max
|
|
248
247
|
} = _ref2;
|
|
249
248
|
let axis = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yAxis';
|
|
250
|
-
|
|
251
249
|
if (min) {
|
|
252
250
|
return {
|
|
253
251
|
[axis]: min
|
|
254
252
|
};
|
|
255
253
|
}
|
|
256
|
-
|
|
257
254
|
return {
|
|
258
255
|
[axis]: max
|
|
259
256
|
};
|
|
260
257
|
};
|
|
258
|
+
|
|
261
259
|
/**
|
|
262
260
|
* Generates markPoints that are placed under the markLines.
|
|
263
261
|
*
|
|
@@ -268,8 +266,6 @@ const generateMarkLines = function (_ref2) {
|
|
|
268
266
|
* @param {Object} annotation object
|
|
269
267
|
* @return {Object}
|
|
270
268
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
269
|
const generateMarkPoints = _ref3 => {
|
|
274
270
|
let {
|
|
275
271
|
min,
|
|
@@ -282,6 +278,7 @@ const generateMarkPoints = _ref3 => {
|
|
|
282
278
|
tooltipData
|
|
283
279
|
};
|
|
284
280
|
};
|
|
281
|
+
|
|
285
282
|
/**
|
|
286
283
|
* Generate set of markAreas and markLines to draw on charts
|
|
287
284
|
* as alert thresholds.
|
|
@@ -291,19 +288,15 @@ const generateMarkPoints = _ref3 => {
|
|
|
291
288
|
* @param {Array} thresholds Array of alert thresholds
|
|
292
289
|
* @returns {Object} markAreas and markLines
|
|
293
290
|
*/
|
|
294
|
-
|
|
295
|
-
|
|
296
291
|
function getThresholdConfig(thresholds) {
|
|
297
292
|
if (!thresholds.length) {
|
|
298
293
|
return {};
|
|
299
294
|
}
|
|
300
|
-
|
|
301
295
|
const data = thresholds.reduce((acc, alert) => {
|
|
302
296
|
const {
|
|
303
297
|
threshold,
|
|
304
298
|
operator
|
|
305
299
|
} = alert;
|
|
306
|
-
|
|
307
300
|
if (GREATER_THAN.includes(operator)) {
|
|
308
301
|
acc.areas.push(generateMarkArea({
|
|
309
302
|
min: threshold,
|
|
@@ -315,7 +308,6 @@ function getThresholdConfig(thresholds) {
|
|
|
315
308
|
max: threshold
|
|
316
309
|
}));
|
|
317
310
|
}
|
|
318
|
-
|
|
319
311
|
acc.lines.push(generateMarkLines({
|
|
320
312
|
max: threshold
|
|
321
313
|
}));
|
|
@@ -334,6 +326,7 @@ function getThresholdConfig(thresholds) {
|
|
|
334
326
|
}
|
|
335
327
|
};
|
|
336
328
|
}
|
|
329
|
+
|
|
337
330
|
/**
|
|
338
331
|
* This method is only for testing both markLines and markAreas
|
|
339
332
|
* that are used for annotations.
|
|
@@ -344,7 +337,6 @@ function getThresholdConfig(thresholds) {
|
|
|
344
337
|
* @param {Array} annotations Array of annotation objects
|
|
345
338
|
* @returns {Object} { areas, lines, points }
|
|
346
339
|
*/
|
|
347
|
-
|
|
348
340
|
const parseAnnotations = annotations => annotations.reduce((acc, annotation) => {
|
|
349
341
|
// because only markLines are supported all cases will
|
|
350
342
|
// satisfy this condition. This is more of a sanity check
|
|
@@ -355,7 +347,6 @@ const parseAnnotations = annotations => annotations.reduce((acc, annotation) =>
|
|
|
355
347
|
acc.points.push(generateMarkPoints(annotation));
|
|
356
348
|
return acc;
|
|
357
349
|
}
|
|
358
|
-
|
|
359
350
|
acc.areas.push(generateMarkArea(annotation, 'xAxis'));
|
|
360
351
|
return acc;
|
|
361
352
|
}, {
|
|
@@ -363,6 +354,7 @@ const parseAnnotations = annotations => annotations.reduce((acc, annotation) =>
|
|
|
363
354
|
lines: [],
|
|
364
355
|
points: []
|
|
365
356
|
});
|
|
357
|
+
|
|
366
358
|
/**
|
|
367
359
|
* Generate set of markAreas and markLines to draw on charts
|
|
368
360
|
* as annotations.
|
|
@@ -374,14 +366,13 @@ const parseAnnotations = annotations => annotations.reduce((acc, annotation) =>
|
|
|
374
366
|
* @param {Array} annotations Array of annotations
|
|
375
367
|
* @returns {Object} { markLines }
|
|
376
368
|
*/
|
|
377
|
-
|
|
378
369
|
const getAnnotationsConfig = annotations => {
|
|
379
370
|
if (!annotations.length) {
|
|
380
371
|
return {};
|
|
381
|
-
}
|
|
382
|
-
// for markLines and markAreas.
|
|
383
|
-
|
|
372
|
+
}
|
|
384
373
|
|
|
374
|
+
// annotations parsing is moved out so that it can be tested
|
|
375
|
+
// for markLines and markAreas.
|
|
385
376
|
const {
|
|
386
377
|
lines,
|
|
387
378
|
points
|
|
@@ -405,6 +396,7 @@ const getAnnotationsConfig = annotations => {
|
|
|
405
396
|
}
|
|
406
397
|
};
|
|
407
398
|
};
|
|
399
|
+
|
|
408
400
|
/**
|
|
409
401
|
* Given thresholds and annotations options, this method generates
|
|
410
402
|
* an annotation series that co-exists along with the data series.
|
|
@@ -416,14 +408,11 @@ const getAnnotationsConfig = annotations => {
|
|
|
416
408
|
* @param {Object} params Thresholds, annotations and yAxis options
|
|
417
409
|
* @returns {Object} Annotation series
|
|
418
410
|
*/
|
|
419
|
-
|
|
420
411
|
const generateAnnotationSeries = function (annotations) {
|
|
421
412
|
let yAxisIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
422
|
-
|
|
423
413
|
if (!annotations.length) {
|
|
424
414
|
return null;
|
|
425
415
|
}
|
|
426
|
-
|
|
427
416
|
return merge({
|
|
428
417
|
name: ANNOTATIONS_SERIES_NAME,
|
|
429
418
|
yAxisIndex,
|
|
@@ -431,6 +420,7 @@ const generateAnnotationSeries = function (annotations) {
|
|
|
431
420
|
data: []
|
|
432
421
|
}, getAnnotationsConfig(annotations));
|
|
433
422
|
};
|
|
423
|
+
|
|
434
424
|
/**
|
|
435
425
|
* This method generates the data series and relevant defaults for a bar chart
|
|
436
426
|
*
|
|
@@ -442,7 +432,6 @@ const generateAnnotationSeries = function (annotations) {
|
|
|
442
432
|
* @param {number} [options.yAxisIndex] - specifies the yAxis to use (if there are multiple)
|
|
443
433
|
* @returns {Object} Bar chart series
|
|
444
434
|
*/
|
|
445
|
-
|
|
446
435
|
const generateBarSeries = _ref4 => {
|
|
447
436
|
let {
|
|
448
437
|
name,
|
|
@@ -470,6 +459,7 @@ const generateBarSeries = _ref4 => {
|
|
|
470
459
|
}
|
|
471
460
|
};
|
|
472
461
|
};
|
|
462
|
+
|
|
473
463
|
/**
|
|
474
464
|
* This method generates the data series and relevant defaults for a line chart
|
|
475
465
|
*
|
|
@@ -480,7 +470,6 @@ const generateBarSeries = _ref4 => {
|
|
|
480
470
|
* @param {number} [options.yAxisIndex] - specifies the yAxis to use (if there are multiple)
|
|
481
471
|
* @returns {Object} Line chart series
|
|
482
472
|
*/
|
|
483
|
-
|
|
484
473
|
const generateLineSeries = _ref5 => {
|
|
485
474
|
let {
|
|
486
475
|
name,
|
|
@@ -501,6 +490,7 @@ const generateLineSeries = _ref5 => {
|
|
|
501
490
|
}
|
|
502
491
|
};
|
|
503
492
|
};
|
|
493
|
+
|
|
504
494
|
/**
|
|
505
495
|
* The method works well if tooltip content should be against y-axis values.
|
|
506
496
|
* However, for bar charts, the tooltip should be against x-axis values.
|
|
@@ -511,7 +501,6 @@ const generateLineSeries = _ref5 => {
|
|
|
511
501
|
* @param {String} yAxisTitle y-axis title
|
|
512
502
|
* @returns {Object} tooltip title and content
|
|
513
503
|
*/
|
|
514
|
-
|
|
515
504
|
const getDefaultTooltipContent = function (params) {
|
|
516
505
|
let yAxisTitle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
517
506
|
const seriesDataLength = params.seriesData.length;
|
|
@@ -519,20 +508,18 @@ const getDefaultTooltipContent = function (params) {
|
|
|
519
508
|
xLabels,
|
|
520
509
|
tooltipContent
|
|
521
510
|
} = params.seriesData.reduce((acc, chartItem) => {
|
|
522
|
-
const [title, value] = chartItem.value || [];
|
|
511
|
+
const [title, value] = chartItem.value || [];
|
|
512
|
+
// Let's use the y axis title as series name when only one series exists
|
|
523
513
|
// This way, TooltipDefaultFormat will display the y axis title as label
|
|
524
|
-
|
|
525
514
|
const seriesName = seriesDataLength === 1 && yAxisTitle ? yAxisTitle : chartItem.seriesName;
|
|
526
515
|
const color = seriesDataLength === 1 ? '' : chartItem.color;
|
|
527
516
|
acc.tooltipContent[seriesName] = {
|
|
528
517
|
value,
|
|
529
518
|
color
|
|
530
519
|
};
|
|
531
|
-
|
|
532
520
|
if (!acc.xLabels.includes(title)) {
|
|
533
521
|
acc.xLabels.push(title);
|
|
534
522
|
}
|
|
535
|
-
|
|
536
523
|
return acc;
|
|
537
524
|
}, {
|
|
538
525
|
xLabels: [],
|
|
@@ -15,52 +15,52 @@ const ANNOTATIONS_SERIES_NAME = 'annotations';
|
|
|
15
15
|
*
|
|
16
16
|
* All markPoints have this component type
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
18
|
const ANNOTATIONS_COMPONENT_TYPE = 'markPoint';
|
|
19
|
+
|
|
20
20
|
/**
|
|
21
21
|
* This is so that the mouse doesn't go over the
|
|
22
22
|
* tooltip and call mouseout which will hide the
|
|
23
23
|
* tooltip.
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
25
|
const ANNOTATION_TOOLTIP_TOP_OFFSET = 10;
|
|
26
|
+
|
|
27
27
|
/**
|
|
28
28
|
* This is a slight offset that gets applied to the left
|
|
29
29
|
* of the chart tooltips to ensure a correct position.
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
31
|
const TOOLTIP_LEFT_OFFSET = 2;
|
|
32
|
+
|
|
33
33
|
/**
|
|
34
34
|
* This is an offset that gets applied between the mouse
|
|
35
35
|
* cursor and the left of the chart data tooltips to provide
|
|
36
36
|
* some spacing.
|
|
37
37
|
*/
|
|
38
|
-
|
|
39
38
|
const DATA_TOOLTIP_LEFT_OFFSET = 10;
|
|
39
|
+
|
|
40
40
|
/**
|
|
41
41
|
* These are the accepted values for the layout prop
|
|
42
42
|
* of the chart legend component
|
|
43
43
|
*/
|
|
44
|
-
|
|
45
44
|
const LEGEND_LAYOUT_INLINE = 'inline';
|
|
46
45
|
const LEGEND_LAYOUT_TABLE = 'table';
|
|
46
|
+
|
|
47
47
|
/**
|
|
48
48
|
* Default values for the chart legend field labels
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
50
|
const LEGEND_AVERAGE_TEXT = 'Avg';
|
|
52
51
|
const LEGEND_CURRENT_TEXT = 'Current';
|
|
53
52
|
const LEGEND_MIN_TEXT = 'Min';
|
|
54
53
|
const LEGEND_MAX_TEXT = 'Max';
|
|
54
|
+
|
|
55
55
|
/**
|
|
56
56
|
* These arrow symbols are used as markPoints under the annotations lines
|
|
57
57
|
* within area and line charts. This icon doesn't exist in the svg
|
|
58
58
|
* library yet. The below issue is to track the progress of the svg icon
|
|
59
59
|
* https://gitlab.com/gitlab-org/gitlab-svgs/-/issues/118
|
|
60
60
|
*/
|
|
61
|
+
const arrowSymbol = 'path://m5 229 5 8h-10z';
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
// Constants for the type property of charts
|
|
64
64
|
const CHART_TYPE_BAR = 'bar';
|
|
65
65
|
const CHART_TYPE_LINE = 'line';
|
|
66
66
|
|