@perses-dev/dashboards 0.7.1 → 0.8.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/dist/cjs/components/Dashboard.js +1 -1
- package/dist/cjs/components/DashboardToolbar.js +3 -18
- package/dist/cjs/components/GridLayout/GridItemContent.js +3 -3
- package/dist/cjs/components/GridLayout/GridLayout.js +4 -7
- package/dist/cjs/components/GridLayout/GridTitle.js +15 -9
- package/dist/cjs/components/Panel/Panel.js +11 -6
- package/dist/cjs/components/Panel/Panel.test.js +17 -13
- package/dist/cjs/components/Panel/PanelContent.js +15 -0
- package/dist/cjs/components/Panel/index.js +29 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +124 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +111 -0
- package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +19 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +60 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -0
- package/dist/cjs/components/{TimeRangeControls.js → TimeRangeControls/TimeRangeControls.js} +20 -31
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +51 -0
- package/dist/cjs/components/TimeRangeControls/index.js +29 -0
- package/dist/cjs/components/Variables/Variable.js +57 -0
- package/dist/cjs/components/Variables/VariableList.js +27 -0
- package/dist/cjs/components/{VariableList → Variables}/index.js +1 -0
- package/dist/cjs/components/index.js +2 -3
- package/dist/cjs/context/DashboardAppSlice.js +45 -0
- package/dist/cjs/context/DashboardProvider.js +54 -36
- package/dist/cjs/context/LayoutsSlice.js +42 -0
- package/dist/cjs/context/QueryStringProvider.js +35 -0
- package/dist/cjs/context/TemplateVariableProvider.js +216 -0
- package/dist/cjs/context/TimeRangeProvider.js +66 -0
- package/dist/cjs/context/index.js +6 -3
- package/dist/cjs/css/styles.js +173 -169
- package/dist/cjs/test/plugin-registry.js +24 -17
- package/dist/cjs/test/render.js +11 -2
- package/dist/cjs/test/testDashboard.js +14 -37
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -0
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +52 -0
- package/dist/cjs/views/ViewDashboard/index.js +29 -0
- package/dist/cjs/views/index.js +1 -1
- package/dist/components/Dashboard.d.ts.map +1 -1
- package/dist/components/Dashboard.js +1 -1
- package/dist/components/DashboardToolbar.d.ts +0 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +1 -0
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts +1 -0
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +1 -1
- package/dist/components/Panel/Panel.d.ts +2 -0
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +1 -1
- package/dist/components/Panel/Panel.test.d.ts.map +1 -1
- package/dist/components/Panel/Panel.test.js +1 -1
- package/dist/components/Panel/PanelContent.d.ts +11 -0
- package/dist/components/Panel/PanelContent.d.ts.map +1 -0
- package/dist/components/Panel/PanelContent.js +1 -0
- package/dist/components/Panel/index.d.ts +2 -0
- package/dist/components/Panel/index.d.ts.map +1 -0
- package/dist/components/Panel/index.js +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.js +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.d.ts +2 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js +1 -0
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +9 -0
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelOptionsEditor.js +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts +2 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -0
- package/dist/components/{TimeRangeControls.d.ts → TimeRangeControls/TimeRangeControls.d.ts} +0 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts +2 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -0
- package/dist/components/TimeRangeControls/index.d.ts +2 -0
- package/dist/components/TimeRangeControls/index.d.ts.map +1 -0
- package/dist/components/TimeRangeControls/index.js +1 -0
- package/dist/components/Variables/Variable.d.ts +8 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -0
- package/dist/components/Variables/Variable.js +1 -0
- package/dist/components/Variables/VariableList.d.ts +3 -0
- package/dist/components/Variables/VariableList.d.ts.map +1 -0
- package/dist/components/Variables/VariableList.js +1 -0
- package/dist/components/Variables/index.d.ts +3 -0
- package/dist/components/Variables/index.d.ts.map +1 -0
- package/dist/components/Variables/index.js +1 -0
- package/dist/components/index.d.ts +2 -3
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/context/DashboardAppSlice.d.ts +26 -0
- package/dist/context/DashboardAppSlice.d.ts.map +1 -0
- package/dist/context/DashboardAppSlice.js +1 -0
- package/dist/context/DashboardProvider.d.ts +8 -19
- package/dist/context/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider.js +1 -1
- package/dist/context/LayoutsSlice.d.ts +12 -0
- package/dist/context/LayoutsSlice.d.ts.map +1 -0
- package/dist/context/LayoutsSlice.js +1 -0
- package/dist/context/QueryStringProvider.d.ts +13 -0
- package/dist/context/QueryStringProvider.d.ts.map +1 -0
- package/dist/context/QueryStringProvider.js +1 -0
- package/dist/context/TemplateVariableProvider.d.ts +25 -0
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider.js +1 -0
- package/dist/context/TimeRangeProvider.d.ts +12 -0
- package/dist/context/TimeRangeProvider.d.ts.map +1 -0
- package/dist/context/TimeRangeProvider.js +1 -0
- package/dist/context/index.d.ts +5 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/css/styles.d.ts +7 -7
- package/dist/css/styles.d.ts.map +1 -1
- package/dist/css/styles.js +1 -1
- package/dist/test/plugin-registry.d.ts +4 -2
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +1 -1
- package/dist/test/render.d.ts +2 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.js +1 -0
- package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
- package/dist/views/ViewDashboard/ViewDashboard.js +1 -0
- package/dist/views/ViewDashboard/index.d.ts +2 -0
- package/dist/views/ViewDashboard/index.d.ts.map +1 -0
- package/dist/views/ViewDashboard/index.js +1 -0
- package/package.json +9 -11
- package/dist/cjs/components/AddPanel/AddPanel.js +0 -75
- package/dist/cjs/components/VariableAutocomplete.js +0 -63
- package/dist/cjs/components/VariableList/VariableList.js +0 -42
- package/dist/cjs/components/VariableList/VariableList.test.js +0 -86
- package/dist/cjs/context/TemplateVariablesProvider.js +0 -142
- package/dist/cjs/context/TimeRangeStateProvider.js +0 -49
- package/dist/cjs/views/DashboardApp.js +0 -46
- package/dist/cjs/views/ViewDashboard.js +0 -15
- package/dist/components/AddPanel/AddPanel.d.ts +0 -8
- package/dist/components/AddPanel/AddPanel.d.ts.map +0 -1
- package/dist/components/AddPanel/AddPanel.js +0 -1
- package/dist/components/TimeRangeControls.d.ts.map +0 -1
- package/dist/components/TimeRangeControls.js +0 -1
- package/dist/components/VariableAutocomplete.d.ts +0 -21
- package/dist/components/VariableAutocomplete.d.ts.map +0 -1
- package/dist/components/VariableAutocomplete.js +0 -1
- package/dist/components/VariableList/VariableList.d.ts +0 -11
- package/dist/components/VariableList/VariableList.d.ts.map +0 -1
- package/dist/components/VariableList/VariableList.js +0 -1
- package/dist/components/VariableList/VariableList.test.d.ts +0 -2
- package/dist/components/VariableList/VariableList.test.d.ts.map +0 -1
- package/dist/components/VariableList/VariableList.test.js +0 -1
- package/dist/components/VariableList/index.d.ts +0 -2
- package/dist/components/VariableList/index.d.ts.map +0 -1
- package/dist/components/VariableList/index.js +0 -1
- package/dist/context/TemplateVariablesProvider.d.ts +0 -23
- package/dist/context/TemplateVariablesProvider.d.ts.map +0 -1
- package/dist/context/TemplateVariablesProvider.js +0 -1
- package/dist/context/TimeRangeStateProvider.d.ts +0 -22
- package/dist/context/TimeRangeStateProvider.d.ts.map +0 -1
- package/dist/context/TimeRangeStateProvider.js +0 -1
- package/dist/views/DashboardApp.d.ts +0 -4
- package/dist/views/DashboardApp.d.ts.map +0 -1
- package/dist/views/DashboardApp.js +0 -1
- package/dist/views/ViewDashboard.d.ts.map +0 -1
- package/dist/views/ViewDashboard.js +0 -1
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemplateVariableProvider = exports.useTemplateVariableStore = exports.useTemplateVariableDefinitions = exports.useTemplateVariableActions = exports.useTemplateVariable = exports.useTemplateVariableValues = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2022 The Perses Authors
|
|
6
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
// you may not use this file except in compliance with the License.
|
|
8
|
+
// You may obtain a copy of the License at
|
|
9
|
+
//
|
|
10
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
//
|
|
12
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
// See the License for the specific language governing permissions and
|
|
16
|
+
// limitations under the License.
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
const zustand_1 = require("zustand");
|
|
19
|
+
const immer_1 = require("zustand/middleware/immer");
|
|
20
|
+
const middleware_1 = require("zustand/middleware");
|
|
21
|
+
const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
22
|
+
const core_1 = require("@perses-dev/core");
|
|
23
|
+
const TemplateVariableStoreContext = (0, react_1.createContext)(undefined);
|
|
24
|
+
function useTemplateVariableStoreCtx() {
|
|
25
|
+
const context = (0, react_1.useContext)(TemplateVariableStoreContext);
|
|
26
|
+
if (!context) {
|
|
27
|
+
throw new Error('TemplateVariableStoreContext not initialized');
|
|
28
|
+
}
|
|
29
|
+
return context;
|
|
30
|
+
}
|
|
31
|
+
function useTemplateVariableValues(variableNames) {
|
|
32
|
+
const store = useTemplateVariableStoreCtx();
|
|
33
|
+
const state = (0, zustand_1.useStore)(store, (s) => {
|
|
34
|
+
const names = variableNames !== null && variableNames !== void 0 ? variableNames : Object.keys(s.variableState);
|
|
35
|
+
const vars = {};
|
|
36
|
+
names.forEach((name) => {
|
|
37
|
+
const varState = s.variableState[name];
|
|
38
|
+
if (!varState) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
vars[name] = varState;
|
|
42
|
+
});
|
|
43
|
+
return vars;
|
|
44
|
+
}, (left, right) => {
|
|
45
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
46
|
+
});
|
|
47
|
+
return state;
|
|
48
|
+
}
|
|
49
|
+
exports.useTemplateVariableValues = useTemplateVariableValues;
|
|
50
|
+
function useTemplateVariable(name) {
|
|
51
|
+
const store = useTemplateVariableStoreCtx();
|
|
52
|
+
return (0, zustand_1.useStore)(store, (s) => {
|
|
53
|
+
const variableState = s.variableState[name];
|
|
54
|
+
const definition = s.variableDefinitions.find((v) => v.name === name);
|
|
55
|
+
return {
|
|
56
|
+
state: variableState,
|
|
57
|
+
definition,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.useTemplateVariable = useTemplateVariable;
|
|
62
|
+
function useTemplateVariableActions() {
|
|
63
|
+
const store = useTemplateVariableStoreCtx();
|
|
64
|
+
return (0, zustand_1.useStore)(store, (s) => {
|
|
65
|
+
return {
|
|
66
|
+
setVariableValue: s.setVariableValue,
|
|
67
|
+
loadTemplateVariable: s.loadTemplateVariable,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.useTemplateVariableActions = useTemplateVariableActions;
|
|
72
|
+
function useTemplateVariableDefinitions() {
|
|
73
|
+
const store = useTemplateVariableStoreCtx();
|
|
74
|
+
return (0, zustand_1.useStore)(store, (s) => s.variableDefinitions);
|
|
75
|
+
}
|
|
76
|
+
exports.useTemplateVariableDefinitions = useTemplateVariableDefinitions;
|
|
77
|
+
function useTemplateVariableStore() {
|
|
78
|
+
const store = useTemplateVariableStoreCtx();
|
|
79
|
+
return (0, zustand_1.useStore)(store);
|
|
80
|
+
}
|
|
81
|
+
exports.useTemplateVariableStore = useTemplateVariableStore;
|
|
82
|
+
function PluginProvider({ children }) {
|
|
83
|
+
const values = useTemplateVariableValues();
|
|
84
|
+
return (0, jsx_runtime_1.jsx)(plugin_system_1.TemplateVariableContext.Provider, { value: { state: values }, children: children });
|
|
85
|
+
}
|
|
86
|
+
function createTemplateVariableSrvStore({ initialVariableDefinitions = [] }) {
|
|
87
|
+
const store = (0, zustand_1.createStore)()((0, middleware_1.devtools)((0, immer_1.immer)((set, get) => ({
|
|
88
|
+
variableState: hydrateTemplateVariableStates(initialVariableDefinitions),
|
|
89
|
+
variableDefinitions: initialVariableDefinitions,
|
|
90
|
+
// Actions
|
|
91
|
+
loadTemplateVariable: async (name) => {
|
|
92
|
+
const def = get().variableDefinitions.find((v) => v.name === name);
|
|
93
|
+
if (!def) {
|
|
94
|
+
// Can't find the variable definition
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
set((state) => {
|
|
98
|
+
const varState = state.variableState[name];
|
|
99
|
+
if (varState) {
|
|
100
|
+
varState.loading = true;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
// Replace with loader
|
|
104
|
+
const { data: values } = await loadTemplateVariables();
|
|
105
|
+
if (def.options.allowAllValue) {
|
|
106
|
+
values.unshift(getAllOption());
|
|
107
|
+
}
|
|
108
|
+
set((state) => {
|
|
109
|
+
const varState = state.variableState[name];
|
|
110
|
+
if (varState) {
|
|
111
|
+
varState.options = values;
|
|
112
|
+
varState.loading = false;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return;
|
|
116
|
+
},
|
|
117
|
+
setVariableValue: (name, value) => set((state) => {
|
|
118
|
+
let val = value;
|
|
119
|
+
const varState = state.variableState[name];
|
|
120
|
+
if (!varState) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// Make sure there is only one all value
|
|
124
|
+
if (Array.isArray(val) && val.includes(core_1.DEFAULT_ALL_VALUE)) {
|
|
125
|
+
if (val.at(-1) === core_1.DEFAULT_ALL_VALUE) {
|
|
126
|
+
val = [core_1.DEFAULT_ALL_VALUE];
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
val = val.filter((v) => v !== core_1.DEFAULT_ALL_VALUE);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
varState.value = val;
|
|
133
|
+
}),
|
|
134
|
+
}))));
|
|
135
|
+
return store;
|
|
136
|
+
}
|
|
137
|
+
function TemplateVariableProvider({ children, initialVariableDefinitions = [], }) {
|
|
138
|
+
const store = createTemplateVariableSrvStore({ initialVariableDefinitions });
|
|
139
|
+
return ((0, jsx_runtime_1.jsx)(TemplateVariableStoreContext.Provider, { value: store, children: (0, jsx_runtime_1.jsx)(PluginProvider, { children: children }) }));
|
|
140
|
+
}
|
|
141
|
+
exports.TemplateVariableProvider = TemplateVariableProvider;
|
|
142
|
+
/** Helpers */
|
|
143
|
+
async function loadTemplateVariables() {
|
|
144
|
+
// @TODO: Replace with plugin call
|
|
145
|
+
// simluate sleep for 2 seconds
|
|
146
|
+
// random time between 1 and 3 seconds
|
|
147
|
+
const sleepTime = Math.floor(Math.random() * 10000) + 1000;
|
|
148
|
+
await new Promise((resolve) => setTimeout(resolve, sleepTime));
|
|
149
|
+
return {
|
|
150
|
+
data: [
|
|
151
|
+
'a',
|
|
152
|
+
'b',
|
|
153
|
+
'c',
|
|
154
|
+
'd',
|
|
155
|
+
'e',
|
|
156
|
+
'f',
|
|
157
|
+
'g',
|
|
158
|
+
'h',
|
|
159
|
+
'i',
|
|
160
|
+
'j',
|
|
161
|
+
'k',
|
|
162
|
+
'l',
|
|
163
|
+
'm',
|
|
164
|
+
'n',
|
|
165
|
+
'o',
|
|
166
|
+
'p',
|
|
167
|
+
'q',
|
|
168
|
+
'r',
|
|
169
|
+
's',
|
|
170
|
+
't',
|
|
171
|
+
'u',
|
|
172
|
+
'v',
|
|
173
|
+
'w',
|
|
174
|
+
'x',
|
|
175
|
+
'y',
|
|
176
|
+
'z',
|
|
177
|
+
].map((v) => ({ label: v, value: v })),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function getAllOption() {
|
|
181
|
+
return { label: 'All', value: core_1.DEFAULT_ALL_VALUE };
|
|
182
|
+
}
|
|
183
|
+
function hydrateTemplateVariableState(definition) {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
const v = definition;
|
|
186
|
+
const varState = {
|
|
187
|
+
value: null,
|
|
188
|
+
loading: false,
|
|
189
|
+
};
|
|
190
|
+
switch (v.kind) {
|
|
191
|
+
case 'TextVariable':
|
|
192
|
+
varState.value = v.options.value;
|
|
193
|
+
break;
|
|
194
|
+
case 'ListVariable':
|
|
195
|
+
varState.options = [];
|
|
196
|
+
if (v.options.allowAllValue) {
|
|
197
|
+
varState.options.unshift({ label: 'All', value: core_1.DEFAULT_ALL_VALUE });
|
|
198
|
+
}
|
|
199
|
+
if (varState.options.length > 0 && !varState.value) {
|
|
200
|
+
const firstOptionValue = (_b = (_a = varState.options[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
|
|
201
|
+
if (firstOptionValue !== null) {
|
|
202
|
+
varState.value = v.options.allowMultiple ? [firstOptionValue] : firstOptionValue;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
default:
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
return varState;
|
|
209
|
+
}
|
|
210
|
+
function hydrateTemplateVariableStates(definitions) {
|
|
211
|
+
const state = {};
|
|
212
|
+
definitions.forEach((v) => {
|
|
213
|
+
state[v.name] = hydrateTemplateVariableState(v);
|
|
214
|
+
});
|
|
215
|
+
return state;
|
|
216
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeRangeProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2022 The Perses Authors
|
|
6
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
// you may not use this file except in compliance with the License.
|
|
8
|
+
// You may obtain a copy of the License at
|
|
9
|
+
//
|
|
10
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
//
|
|
12
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
// See the License for the specific language governing permissions and
|
|
16
|
+
// limitations under the License.
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
const date_fns_1 = require("date-fns");
|
|
19
|
+
const core_1 = require("@perses-dev/core");
|
|
20
|
+
const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
21
|
+
/**
|
|
22
|
+
* Provider implementation that supplies the time range state at runtime.
|
|
23
|
+
*/
|
|
24
|
+
function TimeRangeProvider(props) {
|
|
25
|
+
const { initialTimeRange, children, onTimeRangeChange } = props;
|
|
26
|
+
const { queryString, setQueryString } = (0, plugin_system_1.useQueryString)();
|
|
27
|
+
const defaultTimeRange = (0, core_1.isRelativeTimeRange)(initialTimeRange)
|
|
28
|
+
? (0, core_1.toAbsoluteTimeRange)(initialTimeRange)
|
|
29
|
+
: initialTimeRange;
|
|
30
|
+
const [timeRange, setActiveTimeRange] = (0, react_1.useState)(defaultTimeRange);
|
|
31
|
+
const setTimeRange = (0, react_1.useCallback)((value) => {
|
|
32
|
+
if (onTimeRangeChange !== undefined) {
|
|
33
|
+
// optional callback to override default behavior
|
|
34
|
+
onTimeRangeChange(value);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if ((0, core_1.isRelativeTimeRange)(value)) {
|
|
38
|
+
if (setQueryString) {
|
|
39
|
+
queryString.set('start', value.pastDuration);
|
|
40
|
+
// end not required for relative time but may have been set by AbsoluteTimePicker or zoom
|
|
41
|
+
queryString.delete('end');
|
|
42
|
+
setQueryString(queryString);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
setActiveTimeRange((0, core_1.toAbsoluteTimeRange)(value));
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// allows app to specify whether query params should be source of truth for active time range
|
|
50
|
+
if (setQueryString) {
|
|
51
|
+
// Absolute URL example) ?start=1663707045000&end=1663713330000
|
|
52
|
+
// currently set from ViewDashboard initial queryString, AbsoluteTimePicker, or LineChart panel onDataZoom
|
|
53
|
+
const startUnixMs = (0, date_fns_1.getUnixTime)(value.start) * 1000;
|
|
54
|
+
const endUnixMs = (0, date_fns_1.getUnixTime)(value.end) * 1000;
|
|
55
|
+
queryString.set('start', startUnixMs.toString());
|
|
56
|
+
queryString.set('end', endUnixMs.toString());
|
|
57
|
+
setQueryString(queryString);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
setActiveTimeRange(value);
|
|
61
|
+
}
|
|
62
|
+
}, [queryString, setQueryString, onTimeRangeChange]);
|
|
63
|
+
const ctx = (0, react_1.useMemo)(() => ({ timeRange, setTimeRange }), [timeRange, setTimeRange]);
|
|
64
|
+
return (0, jsx_runtime_1.jsx)(plugin_system_1.TimeRangeContext.Provider, { value: ctx, children: children });
|
|
65
|
+
}
|
|
66
|
+
exports.TimeRangeProvider = TimeRangeProvider;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
5
5
|
// You may obtain a copy of the License at
|
|
@@ -26,6 +26,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
__exportStar(require("./
|
|
30
|
-
__exportStar(require("./
|
|
29
|
+
__exportStar(require("./DashboardAppSlice"), exports);
|
|
30
|
+
__exportStar(require("./LayoutsSlice"), exports);
|
|
31
|
+
__exportStar(require("./TemplateVariableProvider"), exports);
|
|
31
32
|
__exportStar(require("./DashboardProvider"), exports);
|
|
33
|
+
__exportStar(require("./TimeRangeProvider"), exports);
|
|
34
|
+
__exportStar(require("./QueryStringProvider"), exports);
|
package/dist/cjs/css/styles.js
CHANGED
|
@@ -12,173 +12,177 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
15
|
+
exports.styles = void 0;
|
|
16
|
+
const styles = (theme) => {
|
|
17
|
+
return {
|
|
18
|
+
'&.react-grid-layout': {
|
|
19
|
+
position: 'relative',
|
|
20
|
+
transition: 'height 200ms ease',
|
|
21
|
+
},
|
|
22
|
+
'&.react-grid-item': {
|
|
23
|
+
transition: 'all 200ms ease',
|
|
24
|
+
transitionProperty: 'left, top',
|
|
25
|
+
},
|
|
26
|
+
'&.react-grid-item img': {
|
|
27
|
+
pointerEvents: 'none',
|
|
28
|
+
userSelect: 'none',
|
|
29
|
+
},
|
|
30
|
+
'&.react-grid-item.cssTransforms': {
|
|
31
|
+
transitionProperty: 'transform',
|
|
32
|
+
},
|
|
33
|
+
'&.react-grid-item.resizing': {
|
|
34
|
+
zIndex: 1,
|
|
35
|
+
willChange: 'width, height',
|
|
36
|
+
},
|
|
37
|
+
'&.react-grid-item.react-draggable-dragging': {
|
|
38
|
+
transition: 'none',
|
|
39
|
+
zIndex: 3,
|
|
40
|
+
willChange: 'transform',
|
|
41
|
+
},
|
|
42
|
+
'&.react-grid-item.dropping': {
|
|
43
|
+
visibility: 'hidden',
|
|
44
|
+
},
|
|
45
|
+
'&.react-grid-item.react-grid-placeholder': {
|
|
46
|
+
background: theme.palette.primary.main,
|
|
47
|
+
opacity: 0.2,
|
|
48
|
+
transitionDuration: '100ms',
|
|
49
|
+
zIndex: 2,
|
|
50
|
+
userSelect: 'none',
|
|
51
|
+
WebkitUserSelect: 'none',
|
|
52
|
+
MozUserSelect: 'none',
|
|
53
|
+
msUserSelect: 'none',
|
|
54
|
+
OUserSelect: 'none',
|
|
55
|
+
},
|
|
56
|
+
'&.react-grid-item > .react-resizable-handle': {
|
|
57
|
+
position: 'absolute',
|
|
58
|
+
width: '20px',
|
|
59
|
+
height: '20px',
|
|
60
|
+
},
|
|
61
|
+
'&.react-grid-item > .react-resizable-handle::after': {
|
|
62
|
+
content: '""',
|
|
63
|
+
position: 'absolute',
|
|
64
|
+
right: '3px',
|
|
65
|
+
bottom: '3px',
|
|
66
|
+
width: '5px',
|
|
67
|
+
height: '5px',
|
|
68
|
+
borderRight: '2px solid rgba(0, 0, 0, 0.4)',
|
|
69
|
+
borderBottom: '2px solid rgba(0, 0, 0, 0.4)',
|
|
70
|
+
},
|
|
71
|
+
'&.react-resizable-hide > .react-resizable-handle': {
|
|
72
|
+
display: 'none',
|
|
73
|
+
},
|
|
74
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-sw': {
|
|
75
|
+
bottom: '0',
|
|
76
|
+
left: '0',
|
|
77
|
+
cursor: 'sw-resize',
|
|
78
|
+
transform: 'rotate(90deg)',
|
|
79
|
+
},
|
|
80
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-se': {
|
|
81
|
+
bottom: '0',
|
|
82
|
+
right: '0',
|
|
83
|
+
cursor: 'se-resize',
|
|
84
|
+
},
|
|
85
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-nw': {
|
|
86
|
+
top: '0',
|
|
87
|
+
left: '0',
|
|
88
|
+
cursor: 'nw-resize',
|
|
89
|
+
transform: 'rotate(180deg)',
|
|
90
|
+
},
|
|
91
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-ne': {
|
|
92
|
+
top: '0',
|
|
93
|
+
right: '0',
|
|
94
|
+
cursor: 'ne-resize',
|
|
95
|
+
transform: 'rotate(270deg)',
|
|
96
|
+
},
|
|
97
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-w, &.react-grid-item > .react-resizable-handle.react-resizable-handle-e': {
|
|
98
|
+
top: '50%',
|
|
99
|
+
marginTop: '-10px',
|
|
100
|
+
cursor: 'ew-resize',
|
|
101
|
+
},
|
|
102
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-w': {
|
|
103
|
+
left: '0',
|
|
104
|
+
transform: 'rotate(135deg)',
|
|
105
|
+
},
|
|
106
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-e': {
|
|
107
|
+
right: '0',
|
|
108
|
+
transform: 'rotate(315deg)',
|
|
109
|
+
},
|
|
110
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-n, &.react-grid-item > .react-resizable-handle.react-resizable-handle-s': {
|
|
111
|
+
left: '50%',
|
|
112
|
+
marginLeft: '-10px',
|
|
113
|
+
cursor: 'ns-resize',
|
|
114
|
+
},
|
|
115
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-n': {
|
|
116
|
+
top: '0',
|
|
117
|
+
transform: 'rotate(225deg)',
|
|
118
|
+
},
|
|
119
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-s': {
|
|
120
|
+
bottom: '0',
|
|
121
|
+
transform: 'rotate(45deg)',
|
|
122
|
+
},
|
|
123
|
+
'&.react-resizable': {
|
|
124
|
+
position: 'relative',
|
|
125
|
+
},
|
|
126
|
+
'&.react-resizable-handle': {
|
|
127
|
+
position: 'absolute',
|
|
128
|
+
width: '20px',
|
|
129
|
+
height: '20px',
|
|
130
|
+
backgroundRepeat: 'no-repeat',
|
|
131
|
+
backgroundOrigin: 'content-box',
|
|
132
|
+
boxSizing: 'border-box',
|
|
133
|
+
backgroundImage: `url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+')`,
|
|
134
|
+
backgroundPosition: 'bottom right',
|
|
135
|
+
padding: '0 3px 3px 0',
|
|
136
|
+
},
|
|
137
|
+
'&.react-resizable-handle-sw': {
|
|
138
|
+
bottom: '0',
|
|
139
|
+
left: '0',
|
|
140
|
+
cursor: 'sw-resize',
|
|
141
|
+
transform: 'rotate(90deg)',
|
|
142
|
+
},
|
|
143
|
+
'&.react-resizable-handle-se': {
|
|
144
|
+
bottom: '0',
|
|
145
|
+
right: '0',
|
|
146
|
+
cursor: 'se-resize',
|
|
147
|
+
},
|
|
148
|
+
'&.react-resizable-handle-nw': {
|
|
149
|
+
top: '0',
|
|
150
|
+
left: '0',
|
|
151
|
+
cursor: 'nw-resize',
|
|
152
|
+
transform: 'rotate(180deg)',
|
|
153
|
+
},
|
|
154
|
+
'&.react-resizable-handle-ne': {
|
|
155
|
+
top: '0',
|
|
156
|
+
right: '0',
|
|
157
|
+
cursor: 'ne-resize',
|
|
158
|
+
transform: 'rotate(270deg)',
|
|
159
|
+
},
|
|
160
|
+
'&.react-resizable-handle-w, .react-resizable-handle-e': {
|
|
161
|
+
top: '50%',
|
|
162
|
+
marginTop: '-10px',
|
|
163
|
+
cursor: 'ew-resize',
|
|
164
|
+
},
|
|
165
|
+
'&.react-resizable-handle-w': {
|
|
166
|
+
left: '0',
|
|
167
|
+
transform: 'rotate(135deg)',
|
|
168
|
+
},
|
|
169
|
+
'&.react-resizable-handle-e': {
|
|
170
|
+
right: '0',
|
|
171
|
+
transform: 'rotate(315deg)',
|
|
172
|
+
},
|
|
173
|
+
'&.react-resizable-handle-n, .react-resizable-handle-s': {
|
|
174
|
+
left: '50%',
|
|
175
|
+
marginLeft: '-10px',
|
|
176
|
+
cursor: 'ns-resize',
|
|
177
|
+
},
|
|
178
|
+
'&.react-resizable-handle-n': {
|
|
179
|
+
top: '0',
|
|
180
|
+
transform: 'rotate(225deg)',
|
|
181
|
+
},
|
|
182
|
+
'&.react-resizable-handle-s': {
|
|
183
|
+
bottom: '0',
|
|
184
|
+
transform: 'rotate(45deg)',
|
|
185
|
+
},
|
|
186
|
+
};
|
|
184
187
|
};
|
|
188
|
+
exports.styles = styles;
|