Skip to content

Commit

Permalink
feat(ui): TE-2216 create alert page (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshilvelotio authored Sep 23, 2024
1 parent 910d43a commit 443f1a8
Show file tree
Hide file tree
Showing 98 changed files with 6,507 additions and 96 deletions.
1 change: 1 addition & 0 deletions thirdeye-ui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"],
clearMocks: true,
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif)$": "<rootDir>/src/test/unit/mocks/font.mock.js", // Mock PNG imports
"\\.ttf$": "<rootDir>/src/test/unit/mocks/font.mock.js", // Mock font imports
"\\.svg$": "<rootDir>/src/test/unit/mocks/svg.mock.js", // Mock SVG imports
"\\.(css|scss)$": "identity-obj-proxy", // Mock style imports
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Copyright 2023 StarTree Inc
*
* Licensed under the StarTree Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at http://www.startree.ai/legal/startree-community-license
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions and limitations under
* the License.
*/

import { Icon } from "@iconify/react";
import { Box, Button, Drawer, Typography } from "@material-ui/core";
import React, { FunctionComponent, useState } from "react";
import { useTranslation } from "react-i18next";
import {
PropertyConfigValueTypes,
TemplatePropertiesObject,
} from "../../rest/dto/alert.interfaces";
import { AdditonalFiltersDrawerProps } from "./additional-filters-drawer.interfaces";
import { useAdditonalFiltersDrawerStyles } from "./additional-filters-drawer.styles";
import { FormComponentForTemplateField } from "../alert-wizard-v2/alert-template/alert-template-form-field/form-component-for-template-field/form-component-for-template-field.component";
import { LabelForTemplateFieldV2 } from "../alert-wizard-v2/alert-template/alert-template-form-field/label-for-template-field-v2/label-for-template-field-v2.component";

/**
* Convenience wrapper on top of HelpDrawerCoreV1 so consumers do not have
* to maintain isOpen state
*/
export const AdditonalFiltersDrawer: FunctionComponent<AdditonalFiltersDrawerProps> =
({ defaultValues, onApply, isOpen, onClose, availableConfigurations }) => {
const classes = useAdditonalFiltersDrawerStyles();
const { t } = useTranslation();
const [localCopyOfProperties, setLocalCopyOfProperties] =
useState<TemplatePropertiesObject>({
...defaultValues,
});

const handleOnChange = (
key: string,
value: PropertyConfigValueTypes
): void => {
setLocalCopyOfProperties((prev) => ({
...prev,
[key]: value,
}));
};

const onSubmit = (): void => {
onApply(localCopyOfProperties);
};

return (
<Drawer
PaperProps={{
className: classes.drawerPaper,
}}
anchor="right"
open={isOpen}
onClose={onClose}
>
<form onSubmit={onSubmit}>
<Box
alignItems="center"
className={classes.header}
display="flex"
justifyContent="space-between"
>
<Typography variant="h6">
{t("label.advanced-options")}
</Typography>
<Icon
cursor="pointer"
fontSize={24}
icon="ic:round-close"
onClick={onClose}
/>
</Box>
<Box className={classes.content} flex={1}>
<Box>
{availableConfigurations.map((config) => (
<Box
className={classes.configItem}
key={config.name}
mb={3}
width="100%"
>
<Typography color="inherit" variant="h6">
{config.name}
</Typography>
<Box className={classes.configItemFields}>
{config.requiredPropertiesWithMetadata.map(
(propertyMetadata) => (
<Box
key={propertyMetadata.name}
>
<LabelForTemplateFieldV2
className={
classes.formLabel
}
name={
propertyMetadata.name
}
tooltipText={
propertyMetadata.description
}
/>
<FormComponentForTemplateField
propertyKey={
propertyMetadata.name
}
templateFieldProperty={
propertyMetadata
}
value={
localCopyOfProperties[
propertyMetadata
.name
]
}
onChange={(
newValue
) => {
handleOnChange(
propertyMetadata.name,
newValue
);
}}
/>
</Box>
)
)}
</Box>
</Box>
))}
</Box>
</Box>
<Box
className={classes.footer}
display="flex"
justifyContent="space-between"
>
<Button
className={classes.actionSecondary}
size="medium"
variant="contained"
onClick={onClose}
>
{t("label.close")}
</Button>
<Button
className={classes.actionPrimary}
color="primary"
size="medium"
type="submit"
variant="contained"
>
{t("label.apply-filter")}
</Button>
</Box>
</form>
</Drawer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2023 StarTree Inc
*
* Licensed under the StarTree Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at http://www.startree.ai/legal/startree-community-license
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions and limitations under
* the License.
*/

import { TemplatePropertiesObject } from "../../rest/dto/alert.interfaces";
import { AnomaliesFilterConfiguratorRenderConfigs } from "../alert-wizard-v3/anomalies-filter-panel/anomalies-filter-panel.interfaces";

export interface AdditonalFiltersDrawerProps {
defaultValues: TemplatePropertiesObject;
isOpen: boolean;
onApply: (fieldData: TemplatePropertiesObject) => void;
onClose: () => void;
availableConfigurations: AnomaliesFilterConfiguratorRenderConfigs[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2023 StarTree Inc
*
* Licensed under the StarTree Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at http://www.startree.ai/legal/startree-community-license
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions and limitations under
* the License.
*/
import { makeStyles } from "@material-ui/core";
import { ColorV1 } from "../../platform/utils/material-ui/color.util";
import { PaletteV1 } from "../../platform/utils";

export const useAdditonalFiltersDrawerStyles = makeStyles((theme) => ({
drawerPaper: {
backgroundColor: theme.palette.background.paper,
maxWidth: 280,
width: "100%",

"& form": {
height: "100%",
display: "flex",
flexDirection: "column",
},
},
header: {
padding: "10px 12px",

"& h6": {
color: PaletteV1.NavBarBackgroundColor,
},
},
content: {
borderBottom: `1px solid ${ColorV1.Grey10}`,
borderTop: `1px solid ${ColorV1.Grey10}`,
padding: "20px 12px",
flex: "1 1 auto",
overflowY: "auto",
height: 0,
},
footer: {
padding: "10px 12px",
backgroundColor: ColorV1.Grey9,
},
actionSecondary: {
textTransform: "none",
backgroundColor: ColorV1.White1,
border: `1px solid ${ColorV1.Grey10}`,
},
actionPrimary: {
textTransform: "none",
},
configItem: {
"& h6": {
color: PaletteV1.NavBarBackgroundColor,
fontWeight: 700,
fontSize: 16,
marginBottom: 6,
},
},
configItemFields: {
display: "flex",
flexDirection: "column",
gap: 4,
},
formLabel: {
display: "flex",
justifyContent: "flex-start",
alignItems: "center",
gap: 8,
fontWeight: 700,
fontSize: 12,
color: PaletteV1.NavBarBackgroundColor,
marginBottom: 4,
},
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2023 StarTree Inc
*
* Licensed under the StarTree Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at http://www.startree.ai/legal/startree-community-license
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions and limitations under
* the License.
*/
import { Box, Button, Grid, Typography } from "@material-ui/core";
import React, { FunctionComponent } from "react";
import { useTranslation } from "react-i18next";
import ControlPointOutlinedIcon from "@material-ui/icons/ControlPointOutlined";
import { Modal } from "../modal/modal.component";
import { AlertAddConfigrationModalProps } from "./alert-add-configration-modal.interfaces";
import Image from "../../../assets/images/alert-type-examples/configuration.png";
import {
getSubscriptionGroupsCreatePathWithAlertId,
getSubscriptionGroupsPath,
} from "../../utils/routes/routes.util";
import { boxCardStyles } from "./alert-add-configration-modal.styles";
import { useSearchParams } from "react-router-dom";
import { QUERY_PARAM_KEY_ALERT_TYPE } from "../../pages/alerts-view-page/alerts-view-page.utils";

export const AlertAddConfigrationModal: FunctionComponent<AlertAddConfigrationModalProps> =
({ alertId }) => {
const { t } = useTranslation();
const classes = boxCardStyles();
const [searchParams] = useSearchParams();

return (
<Modal
initiallyOpen
showFooter={false}
submitButtonLabel={t("label.got-it")}
title={t("label.alert-completed")}
>
<Box className={classes.card}>
<Grid container>
<Grid item>
<Box sx={{ width: "266px" }}>
<Typography variant="h6">
{t("label.congratulations-,")}
</Typography>
<Typography variant="h6">
{searchParams.get(
QUERY_PARAM_KEY_ALERT_TYPE
) === "create"
? t("label.your-alert-has-been-created")
: t(
"label.your-alert-has-been-updated"
)}
</Typography>
<Box sx={{ my: 2 }}>
<Typography variant="subtitle2">
{t(
"message.to-receive-notifications-configure"
)}
</Typography>
</Box>
</Box>
</Grid>
<Grid item>
<Box>
<img
alt={t("label.configure-notifications")}
src={Image}
/>
</Box>
</Grid>
<Grid item>
<Box display="flex" gridGap={10}>
<Button
color="primary"
href={getSubscriptionGroupsCreatePathWithAlertId(
alertId
)}
size="small"
startIcon={<ControlPointOutlinedIcon />}
variant="contained"
>
{t("label.create-notifications")}
</Button>
<Button
color="primary"
href={getSubscriptionGroupsPath()}
size="small"
variant="outlined"
>
{t("label.explore-all-notifications")}
</Button>
</Box>
</Grid>
</Grid>
</Box>
</Modal>
);
};
Loading

0 comments on commit 443f1a8

Please sign in to comment.