Skip to content

Commit 8903b25

Browse files
[ITEP-1648] Alert Configuration: Fix Name to alertDefTemplate/annotation.display_name (#87)
Co-authored-by: Matteo <matteo.scandolo@intel.com> Co-authored-by: Matteo <teone@users.noreply.github.com>
1 parent f0a2091 commit 8903b25

15 files changed

Lines changed: 218 additions & 95 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* SPDX-FileCopyrightText: (C) 2023 Intel Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { alertDefinitionOne } from "@orch-ui/utils";
7+
import AlertDisplayName from "./AlertDisplayName";
8+
import AlertDisplayNamePom from "./AlertDisplayName.pom";
9+
10+
const pom = new AlertDisplayNamePom();
11+
describe("<AlertDisplayName/>", () => {
12+
it("should render component with display_name", () => {
13+
pom.interceptApis([pom.api.getAlertTemplate]);
14+
cy.mount(<AlertDisplayName alertDefinition={alertDefinitionOne} />);
15+
pom.waitForApis();
16+
17+
pom.root.should("not.contain.text", alertDefinitionOne.name);
18+
pom.root.should("contain.text", "Host - Connection Lost");
19+
});
20+
it("should render component with name", () => {
21+
pom.interceptApis([pom.api.getAlertTemplateError]);
22+
cy.mount(<AlertDisplayName alertDefinition={alertDefinitionOne} />);
23+
pom.waitForApis();
24+
25+
pom.root.should("contain.text", alertDefinitionOne.name);
26+
pom.root.should("not.contain.text", "Host - Connection Lost");
27+
});
28+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* SPDX-FileCopyrightText: (C) 2023 Intel Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { omApi } from "@orch-ui/apis";
7+
import { CyApiDetails, CyPom } from "@orch-ui/tests";
8+
import { alertDefinitionTemplateOne } from "@orch-ui/utils";
9+
10+
const dataCySelectors = [] as const;
11+
type Selectors = (typeof dataCySelectors)[number];
12+
13+
type ApiAliases = "getAlertTemplate" | "getAlertTemplateError";
14+
15+
const mockAlert = {
16+
...alertDefinitionTemplateOne,
17+
alert: "alert-name",
18+
annotations: {
19+
...alertDefinitionTemplateOne.annotations,
20+
description: "Host $labels.host_uuid connection lost.",
21+
display_name: "Host - Connection Lost",
22+
summary: "Host has lost connection.",
23+
},
24+
};
25+
26+
const alertTemplateUrl = "**/alerts/definitions/**/template**";
27+
const alertTemplateEndpoints: CyApiDetails<
28+
ApiAliases,
29+
omApi.GetProjectAlertDefinitionRuleApiResponse
30+
> = {
31+
getAlertTemplate: {
32+
route: alertTemplateUrl,
33+
statusCode: 200,
34+
response: mockAlert,
35+
},
36+
getAlertTemplateError: {
37+
route: alertTemplateUrl,
38+
statusCode: 500,
39+
networkError: true,
40+
},
41+
};
42+
43+
class AlertDisplayNamePom extends CyPom<Selectors, ApiAliases> {
44+
constructor(public rootCy: string = "alertDisplayName") {
45+
super(rootCy, [...dataCySelectors], alertTemplateEndpoints);
46+
}
47+
}
48+
export default AlertDisplayNamePom;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SPDX-FileCopyrightText: (C) 2023 Intel Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { omApi } from "@orch-ui/apis";
7+
import { SquareSpinner } from "@orch-ui/components";
8+
import { SharedStorage } from "@orch-ui/utils";
9+
import { Text } from "@spark-design/react";
10+
11+
const dataCy = "alertDisplayName";
12+
interface AlertDisplayNameProps {
13+
alertDefinition: omApi.AlertDefinition;
14+
}
15+
const AlertDisplayName = ({ alertDefinition }: AlertDisplayNameProps) => {
16+
const cy = { "data-cy": dataCy };
17+
const {
18+
data: alertDefinitionTemplate,
19+
isSuccess,
20+
isLoading,
21+
} = omApi.useGetProjectAlertDefinitionRuleQuery(
22+
{
23+
alertDefinitionId: alertDefinition.id!,
24+
projectName: SharedStorage.project?.name ?? "",
25+
},
26+
{
27+
skip: !alertDefinition.id || !SharedStorage.project?.name,
28+
},
29+
);
30+
31+
return (
32+
<div {...cy} className="alert-display-name">
33+
<Text size="m">
34+
{isSuccess &&
35+
alertDefinitionTemplate.annotations &&
36+
alertDefinitionTemplate.annotations["display_name"]
37+
? alertDefinitionTemplate.annotations["display_name"]
38+
: alertDefinition.name}
39+
</Text>
40+
{isLoading && <SquareSpinner />}
41+
</div>
42+
);
43+
};
44+
45+
export default AlertDisplayName;

apps/admin/src/components/organisms/AlertDefinitionsList/AlertDefinitionsList.cy.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ describe("<AlertDefinitionsList/>", () => {
1515
pom.root.should("exist");
1616
pom.table.getRows().should("have.length", multipleAlertDefinitions.length);
1717
});
18+
it("should show alert definition name", () => {
19+
pom.interceptApis([pom.api.alertDefinitionSingle]);
20+
cy.mount(<AlertDefinitionsList />);
21+
pom.waitForApis();
22+
pom.alertDisplayNamePom.root.should(
23+
"contain.text",
24+
"Host - Connection Lost",
25+
);
26+
});
1827
});

apps/admin/src/components/organisms/AlertDefinitionsList/AlertDefinitionsList.pom.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import { omApi } from "@orch-ui/apis";
77
import { SiTablePom } from "@orch-ui/poms";
88
import { CyApiDetails, CyPom } from "@orch-ui/tests";
9-
import { multipleAlertDefinitions } from "@orch-ui/utils";
9+
import { alertDefinitionOne, multipleAlertDefinitions } from "@orch-ui/utils";
10+
import AlertDisplayNamePom from "../../atoms/AlertDisplayName/AlertDisplayName.pom";
1011

1112
const dataCySelectors = [] as const;
1213
type Selectors = (typeof dataCySelectors)[number];
1314

14-
type ApiAliases = "alertDefinitionList";
15+
type ApiAliases = "alertDefinitionList" | "alertDefinitionSingle";
1516

1617
const endpoints: CyApiDetails<
1718
ApiAliases,
@@ -23,13 +24,26 @@ const endpoints: CyApiDetails<
2324
alertDefinitions: multipleAlertDefinitions,
2425
},
2526
},
27+
alertDefinitionSingle: {
28+
route: "**/alerts/definitions",
29+
response: {
30+
alertDefinitions: [
31+
{
32+
...alertDefinitionOne,
33+
name: "Host - Connection Lost",
34+
},
35+
],
36+
},
37+
},
2638
};
2739

2840
class AlertDefinitionsListPom extends CyPom<Selectors, ApiAliases> {
2941
table: SiTablePom;
42+
alertDisplayNamePom: AlertDisplayNamePom;
3043
constructor(public rootCy: string = "alertDefinitionsList") {
3144
super(rootCy, [...dataCySelectors], endpoints);
3245
this.table = new SiTablePom();
46+
this.alertDisplayNamePom = new AlertDisplayNamePom();
3347
}
3448
}
3549
export default AlertDefinitionsListPom;

apps/admin/src/components/organisms/AlertDefinitionsList/AlertDefinitionsList.scss

Lines changed: 0 additions & 8 deletions
This file was deleted.

apps/admin/src/components/organisms/AlertDefinitionsList/AlertDefinitionsList.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ import AlertDefinitionDuration, {
1616
} from "../../atoms/AlertDefinitionDuration/AlertDefinitionDuration";
1717
import AlertDefinitionEnable from "../../atoms/AlertDefinitionEnable/AlertDefinitionEnable";
1818
import AlertDefinitionThreshold from "../../atoms/AlertDefinitionThreshold/AlertDefinitionThreshold";
19-
import "./AlertDefinitionsList.scss";
19+
import AlertDisplayName from "../../atoms/AlertDisplayName/AlertDisplayName";
2020

2121
const dataCy = "alertDefinitionsList";
2222

2323
const AlertDefinitionsList = () => {
2424
const cy = { "data-cy": dataCy };
25+
26+
const dispatch = useAppDispatch();
27+
2528
const [alertDefinitionsTableData, setAlertDefinitionsTableData] = useState<
2629
omApi.AlertDefinition[]
2730
>([]);
2831
const [actions, setActions] = useState<
2932
omApi.PatchProjectAlertDefinitionApiArg[]
3033
>([]);
34+
3135
const [patchAlertDefinition] = omApi.usePatchProjectAlertDefinitionMutation();
3236
const {
3337
data: alertDefinitions,
@@ -38,10 +42,11 @@ const AlertDefinitionsList = () => {
3842
} = omApi.useGetProjectAlertDefinitionsQuery({
3943
projectName: SharedStorage.project?.name ?? "",
4044
});
45+
4146
useEffect(() => {
4247
setAlertDefinitionsTableData(alertDefinitions?.alertDefinitions ?? []);
4348
}, [alertDefinitions, isSuccess]);
44-
const dispatch = useAppDispatch();
49+
4550
const updateAlertDefinitions = async () => {
4651
const requests: Promise<unknown>[] = [];
4752
if (actions && actions.length > 0) {
@@ -157,6 +162,7 @@ const AlertDefinitionsList = () => {
157162
newTableData.splice(index, 1, targetRow);
158163
setAlertDefinitionsTableData(newTableData);
159164
};
165+
160166
const columns = [
161167
{
162168
Header: "Enabled",
@@ -173,6 +179,9 @@ const AlertDefinitionsList = () => {
173179
{
174180
Header: "Name",
175181
accessor: "name",
182+
Cell: (table: { row: { original: omApi.AlertDefinition } }) => (
183+
<AlertDisplayName alertDefinition={table.row.original} />
184+
),
176185
},
177186
{
178187
Header: "Threshold",

apps/admin/src/components/organisms/AlertsList/AlertsList.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { API_INTERVAL, SharedStorage } from "@orch-ui/utils";
1111
import { Button } from "@spark-design/react";
1212
import { useState } from "react";
1313
import { useSearchParams } from "react-router-dom";
14+
import AlertDisplayName from "../../atoms/AlertDisplayName/AlertDisplayName";
1415
import AlertSource from "../../atoms/AlertSource/AlertSource";
1516
import AlertDrawer from "../AlertDrawer/AlertDrawer";
1617
import "./AlertsList.scss";
@@ -44,7 +45,7 @@ const AlertsList = () => {
4445
Header: "Alert",
4546
accessor: "alertDefinitionId",
4647
Cell: (table: { row: { original: omApi.Alert } }) => {
47-
const filteredADs = alertDefinitions?.alertDefinitions?.filter(
48+
const alertDefinition = alertDefinitions?.alertDefinitions?.find(
4849
(ad) => ad.id === table.row.original.alertDefinitionId,
4950
);
5051
return (
@@ -56,9 +57,11 @@ const AlertsList = () => {
5657
setIsOpen(true);
5758
}}
5859
>
59-
{filteredADs && filteredADs.length > 0
60-
? filteredADs[0].name
61-
: table.row.original.alertDefinitionId}
60+
{alertDefinition ? (
61+
<AlertDisplayName alertDefinition={alertDefinition} />
62+
) : (
63+
table.row.original.alertDefinitionId
64+
)}
6265
</Button>
6366
);
6467
},

apps/admin/unit-tests.cy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import "./src/components/atoms/AlertDefinitionDuration/AlertDefinitionDuration.cy.tsx";
77
import "./src/components/atoms/AlertDefinitionEnable/AlertDefinitionEnable.cy.tsx";
88
import "./src/components/atoms/AlertDefinitionThreshold/AlertDefinitionThreshold.cy.tsx";
9+
import "./src/components/atoms/AlertDisplayName/AlertDisplayName.cy.tsx";
910
import "./src/components/atoms/AlertSource/AlertSource.cy.tsx";
1011
import "./src/components/atoms/SshHostsTable/SshHostsTable.cy.tsx";
1112
import "./src/components/atoms/SshKeyInUseByHostsCell/SshKeyInUseByHostsCell.cy.tsx";

apps/root/public/runtime-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// SPDX-FileCopyrightText: (C) 2022 Intel Corporation
77
// SPDX-License-Identifier: Apache-2.0
88

9-
const fqdn = "kind.internal"
9+
const fqdn = "kind.internal";
1010

1111
window.__RUNTIME_CONFIG__ = {
1212
AUTH: "true",
@@ -73,7 +73,7 @@ window.__RUNTIME_CONFIG__ = {
7373
CO: `https://api.${fqdn}`,
7474
INFRA: `https://api.${fqdn}`,
7575
MB: `https://api.${fqdn}`,
76-
ALERT: `https://web-ui.${fqdn}/api`,
76+
ALERT: `https://api.${fqdn}/`,
7777
TM: `https://api.${fqdn}/`,
7878
},
7979
VERSIONS: {

0 commit comments

Comments
 (0)