verificate dashboard names

This commit is contained in:
Qiuxia Fan 2022-03-22 16:47:57 +08:00
parent ecd046c663
commit 83496dc4b5
8 changed files with 24 additions and 38 deletions

View File

@ -296,7 +296,7 @@ export const dashboardStore = defineStore({
const list = [];
for (const t of data) {
const c = JSON.parse(t.configuration);
const key = [c.layer, c.entity, c.name.split(" ").join("-")].join("_");
const key = [c.layer, c.entity, c.name].join("_");
list.push({
id: t.id,
@ -404,7 +404,7 @@ export const dashboardStore = defineStore({
const key = [
this.currentDashboard.layer,
this.currentDashboard.entity,
this.currentDashboard.name.split(" ").join("-"),
this.currentDashboard.name,
].join("_");
if (this.currentDashboard.id) {
sessionStorage.removeItem(key);
@ -441,7 +441,7 @@ export const dashboardStore = defineStore({
const key = [
this.currentDashboard.layer,
this.currentDashboard.entity,
this.currentDashboard.name.split(" ").join("-"),
this.currentDashboard.name,
].join("_");
sessionStorage.removeItem(key);
},

View File

@ -55,7 +55,7 @@ async function setTemplate() {
if (!p.entity) {
const { layer, entity, name } = dashboardStore.currentDashboard;
layoutKey.value = `${layer}_${entity}_${name.split(" ").join("-")}`;
layoutKey.value = `${layer}_${entity}_${name}`;
}
const c: { configuration: string; id: string } = JSON.parse(
sessionStorage.getItem(layoutKey.value) || "{}"

View File

@ -172,7 +172,7 @@ async function importTemplates(event: any) {
(d: DashboardItem) => d.id === item.id
);
const p: DashboardItem = {
name: name,
name: name.split(" ").join("-"),
layer: layer,
entity: entity,
isRoot: false,
@ -196,7 +196,7 @@ function exportTemplates() {
}
);
const templates = arr.map((d: DashboardItem) => {
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_");
const key = [d.layer, d.entity, d.name].join("_");
const layout = JSON.parse(sessionStorage.getItem(key) || "{}");
return layout;
});
@ -211,9 +211,7 @@ function handleEdit(row: DashboardItem) {
dashboardStore.setEntity(row.entity);
dashboardStore.setLayer(row.layer);
dashboardStore.setCurrentDashboard(row);
router.push(
`/dashboard/${row.layer}/${row.entity}/${row.name.split(" ").join("-")}`
);
router.push(`/dashboard/${row.layer}/${row.entity}/${row.name}`);
}
function handleView(row: DashboardItem) {
@ -221,9 +219,7 @@ function handleView(row: DashboardItem) {
dashboardStore.setEntity(row.entity);
dashboardStore.setLayer(row.layer);
dashboardStore.setCurrentDashboard(row);
router.push(
`/dashboard/${row.layer}/${row.entity}/${row.name.split(" ").join("-")}`
);
router.push(`/dashboard/${row.layer}/${row.entity}/${row.name}`);
}
async function setRoot(row: DashboardItem) {
@ -232,7 +228,7 @@ async function setRoot(row: DashboardItem) {
for (const d of dashboardStore.dashboards) {
if (d.id === row.id) {
d.isRoot = !row.isRoot;
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_");
const key = [d.layer, d.entity, d.name].join("_");
const layout = sessionStorage.getItem(key) || "{}";
const c = {
...JSON.parse(layout).configuration,
@ -262,7 +258,7 @@ async function setRoot(row: DashboardItem) {
d.isRoot === true
) {
d.isRoot = false;
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_");
const key = [d.layer, d.entity, d.name].join("_");
const layout = sessionStorage.getItem(key) || "{}";
const c = {
...JSON.parse(layout).configuration,
@ -307,7 +303,11 @@ function handleRename(row: DashboardItem) {
});
}
async function updateName(d: DashboardItem, value: string) {
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_");
if (new RegExp(/\s/).test(value)) {
ElMessage.error("The name cannot contain spaces, carriage returns, etc");
return;
}
const key = [d.layer, d.entity, d.name].join("_");
const layout = sessionStorage.getItem(key) || "{}";
const c = {
...JSON.parse(layout).configuration,
@ -341,7 +341,7 @@ async function updateName(d: DashboardItem, value: string) {
const str = [
dashboardStore.currentDashboard.layer,
dashboardStore.currentDashboard.entity,
dashboardStore.currentDashboard.name.split(" ").join("-"),
dashboardStore.currentDashboard.name,
].join("_");
sessionStorage.setItem(
str,
@ -359,9 +359,7 @@ async function handleDelete(row: DashboardItem) {
dashboards.value = dashboardStore.dashboards;
loading.value = false;
sessionStorage.setItem("dashboards", JSON.stringify(dashboards.value));
sessionStorage.removeItem(
`${row.layer}_${row.entity}_${row.name.split(" ").join("-")}`
);
sessionStorage.removeItem(`${row.layer}_${row.entity}_${row.name}`);
}
function searchDashboards() {
const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]");

View File

@ -90,7 +90,7 @@ const onCreate = () => {
entity: states.entity,
layer: states.selectedLayer,
});
const name = states.name.split(" ").join("-");
const name = states.name;
const path = `/dashboard/${states.selectedLayer}/${states.entity}/${name}`;
router.push(path);
};

View File

@ -170,9 +170,7 @@ function clickEndpoint(scope: any) {
dashboardStore.setEntity(EntityType[2].value);
dashboardStore.setCurrentDashboard(d);
router.push(
`/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${
scope.row.id
}/${d.name.split(" ").join("-")}`
`/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${scope.row.id}/${d.name}`
);
}
function changePage(pageIndex: number) {

View File

@ -175,9 +175,7 @@ function clickInstance(scope: any) {
dashboardStore.setCurrentDashboard(d);
dashboardStore.setEntity(d.entity);
router.push(
`/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${
scope.row.id
}/${d.name.split(" ").join("-")}`
`/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${scope.row.id}/${d.name}`
);
}

View File

@ -254,9 +254,7 @@ function handleLinkClick(event: any, d: Call) {
entity: `${e}Relation`,
});
dashboardStore.setEntity(p.entity);
const path = `/dashboard/${p.layer}/${e}Relation/${d.source.id}/${
d.target.id
}/${p.name.split(" ").join("-")}`;
const path = `/dashboard/${p.layer}/${e}Relation/${d.source.id}/${d.target.id}/${p.name}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");
dashboardStore.setEntity(origin);
@ -412,9 +410,7 @@ function handleGoInstance(name: string) {
entity: EntityType[3].value,
});
dashboardStore.setEntity(p.entity);
const path = `/dashboard/${p.layer}/ServiceInstance/${
topologyStore.node.id
}/${name.split(" ").join("-")}`;
const path = `/dashboard/${p.layer}/ServiceInstance/${topologyStore.node.id}/${name}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");

View File

@ -176,9 +176,7 @@ function goDashboard() {
});
dashboardStore.setEntity(entity);
dashboardStore.setCurrentDashboard(d);
const path = `/dashboard/${d.layer}/${entity}/${
topologyStore.node.serviceId
}/${topologyStore.node.id}/${d.name.split(" ").join("-")}`;
const path = `/dashboard/${d.layer}/${entity}/${topologyStore.node.serviceId}/${topologyStore.node.id}/${d.name}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");
topologyStore.setNode(null);
@ -217,9 +215,7 @@ function selectNodeLink(d: any) {
entity,
});
dashboardStore.setEntity(entity);
const path = `/dashboard/${p.layer}/${entity}/${sourceObj.serviceId}/${
sourceObj.id
}/${targetObj.serviceId}/${targetObj.id}/${p.name.split(" ").join("-")}`;
const path = `/dashboard/${p.layer}/${entity}/${sourceObj.serviceId}/${sourceObj.id}/${targetObj.serviceId}/${targetObj.id}/${p.name}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");
return;