mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-14 17:05:10 +00:00
verify widget name
This commit is contained in:
parent
bf218b330e
commit
437383d4b2
@ -14,12 +14,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
export default function getDashboard(param: {
|
export default function getDashboard(param: {
|
||||||
name: string;
|
name: string;
|
||||||
layer: string;
|
layer: string;
|
||||||
entity: string;
|
entity: string;
|
||||||
}) {
|
}) {
|
||||||
|
const dashboardStore = useDashboardStore();
|
||||||
const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]");
|
const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]");
|
||||||
const dashboard = list.find(
|
const dashboard = list.find(
|
||||||
(d: { name: string; layer: string; entity: string }) =>
|
(d: { name: string; layer: string; entity: string }) =>
|
||||||
@ -27,8 +28,9 @@ export default function getDashboard(param: {
|
|||||||
d.entity === param.entity &&
|
d.entity === param.entity &&
|
||||||
d.layer === param.layer
|
d.layer === param.layer
|
||||||
);
|
);
|
||||||
|
const all = dashboardStore.layout;
|
||||||
const widgets = [];
|
const widgets = [];
|
||||||
for (const item of dashboard) {
|
for (const item of all) {
|
||||||
if (item.type === "Tab") {
|
if (item.type === "Tab") {
|
||||||
if (item.children && item.children.length) {
|
if (item.children && item.children.length) {
|
||||||
for (const child of item.children) {
|
for (const child of item.children) {
|
||||||
|
@ -43,18 +43,18 @@ const widgets = computed(() => {
|
|||||||
const isRank = ["TopList"].includes(
|
const isRank = ["TopList"].includes(
|
||||||
dashboardStore.selectedGrid.graph && dashboardStore.selectedGrid.graph.type
|
dashboardStore.selectedGrid.graph && dashboardStore.selectedGrid.graph.type
|
||||||
);
|
);
|
||||||
const w = getDashboard(dashboardStore.currentDashboard).widgets;
|
const { widgets } = getDashboard(dashboardStore.currentDashboard);
|
||||||
const items = w.filter(
|
const items = widgets.filter(
|
||||||
(d: { value: string; label: string } & LayoutConfig) => {
|
(d: { value: string; label: string } & LayoutConfig) => {
|
||||||
if (dashboardStore.selectedGrid.id !== d.id) {
|
if (dashboardStore.selectedGrid.id !== d.id) {
|
||||||
if (isLinear) {
|
if (isLinear && d.widget) {
|
||||||
d.value = d.id || "";
|
d.value = d.id || "";
|
||||||
d.label = (d.widget && d.widget.title) || d.type || "";
|
d.label = d.widget.name || d.id || "";
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
if (isRank && d.type !== "Widget") {
|
if (isRank && d.type !== "Widget" && d.widget) {
|
||||||
d.value = d.id || "";
|
d.value = d.id || "";
|
||||||
d.label = (d.widget && d.widget.title) || d.type || "";
|
d.label = d.widget.name || d.id || "";
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,14 @@ function updateWidgetConfig(param: { [key: string]: string }) {
|
|||||||
function updateWidgetName(param: { [key: string]: string }) {
|
function updateWidgetName(param: { [key: string]: string }) {
|
||||||
const key = Object.keys(param)[0];
|
const key = Object.keys(param)[0];
|
||||||
const n = decodeURIComponent(param[key]);
|
const n = decodeURIComponent(param[key]);
|
||||||
const widgets = getDashboard(dashboardStore.currentDashboard).widgets;
|
const pattern = /^[A-Za-z0-9-_\u4e00-\u9fa5]{4,30}$/;
|
||||||
|
if (!pattern.test(n)) {
|
||||||
|
ElMessage.warning(
|
||||||
|
"The name only supports Chinese and English, horizontal lines and underscores"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { widgets } = getDashboard(dashboardStore.currentDashboard);
|
||||||
const item = widgets.find(
|
const item = widgets.find(
|
||||||
(d: LayoutConfig) => d.widget && d.widget.name === n
|
(d: LayoutConfig) => d.widget && d.widget.name === n
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user