Skip to content

Commit

Permalink
fix(ui): Changes for Alert editor dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
harshilvelotio committed Jan 14, 2025
1 parent 54d3898 commit 5f16229
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { FormHelperText, Grid, TextField } from "@material-ui/core";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { NavigateAlertCreationFlowsDropdown } from "../../alert-wizard-v3/navigate-alert-creation-flows-dropdown/navigate-alert-creation-flows-dropdown-v2";
import { InputSectionV2 } from "../../form-basics/input-section-v2/input-section-v2.component";
import { AlertDetailsProps } from "./alert-details.interfaces";
import { AlertFrequency } from "./alert-frequency-v2/alert-frequency.component";
Expand Down Expand Up @@ -47,6 +48,13 @@ function AlertDetails({

return (
<Grid container>
<Grid item xs={12}>
<Grid container alignContent="center" justifyContent="flex-end">
<Grid item>
<NavigateAlertCreationFlowsDropdown />
</Grid>
</Grid>
</Grid>
<Grid item xs={4}>
<InputSectionV2
inputComponent={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { THIRDEYE_DOC_LINK } from "../../../utils/constants/constants.util";
import { validateJSON } from "../../../utils/validation/validation.util";
import { HelpDrawerV1 } from "../../help-drawer-v1/help-drawer-v1.component";
import { AlertJsonProps } from "./alert-json.interfaces";
import { NavigateAlertCreationFlowsDropdown } from "../../alert-wizard-v3/navigate-alert-creation-flows-dropdown/navigate-alert-creation-flows-dropdown-v2";

export const AlertJson: FunctionComponent<AlertJsonProps> = ({
alert,
Expand Down Expand Up @@ -63,6 +64,13 @@ export const AlertJson: FunctionComponent<AlertJsonProps> = ({

return (
<Grid container>
<Grid item xs={12}>
<Grid container alignContent="center" justifyContent="flex-end">
<Grid item>
<NavigateAlertCreationFlowsDropdown />
</Grid>
</Grid>
</Grid>
<Grid item xs={12}>
<Grid
container
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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, Grid, TextField } from "@material-ui/core";
import { Autocomplete } from "@material-ui/lab";
import React, { FunctionComponent, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useLocation, useNavigate, useSearchParams } from "react-router-dom";
import { AppRouteRelative } from "../../../utils/routes/routes.util";
import { ALERT_CREATION_NAVIGATE_DROPDOWN_TEST_IDS } from "./navigate-alert-creation-flows-dropdown.interface";
import { useNavigateAlertCreationFlowsDropdownStyles } from "./navigate-alert-creation-flows-dropdown.styles";

export const NavigateAlertCreationFlowsDropdown: FunctionComponent = () => {
const { t } = useTranslation();
const classes = useNavigateAlertCreationFlowsDropdownStyles();
const navigate = useNavigate();
const location = useLocation();
const [searchParams] = useSearchParams();

/**
* `/alerts/73/update/simple`
* `/alerts/create/new/advanced`
* `/alerts/create/new/new-user/select-type`
* `/alerts/create/copy/69689/json-editor`
* `/alerts/create/copy/69689/new-user/select-type`
* `/welcome/create-alert/simple`
* `/welcome/create-alert/new-user/select-type`
*/
const routePathPrefix = useMemo(() => {
let endIdx = 4;

if (location.pathname.includes(AppRouteRelative.WELCOME)) {
endIdx = 3;
}

if (
location.pathname.includes(
AppRouteRelative.ALERTS_CREATE_COPY.replace("/:id", "")
)
) {
endIdx = 5;
}

return location.pathname.split("/").slice(0, endIdx).join("/");
}, [location]);

const shortcutCreateMenuItems = [
{
matcher: (path: string) =>
path.endsWith(AppRouteRelative.ALERTS_CREATE_ADVANCED_V2),
navLink: AppRouteRelative.ALERTS_CREATE_ADVANCED_V2,
text: t("label.advanced-setup"),
},
{
matcher: (path: string) =>
path.endsWith(AppRouteRelative.ALERTS_CREATE_JSON_EDITOR_V2),
navLink: AppRouteRelative.ALERTS_CREATE_JSON_EDITOR_V2,
text: t("label.json-setup"),
},
];

const currentPage = useMemo(() => {
return shortcutCreateMenuItems.find((candidate) => {
return candidate.matcher(location.pathname);
});
}, [location]);

return (
<Grid container alignContent="center">
<Grid item>
<Box paddingTop={1}>
{t("label.alert-editor")}
{": "}
</Box>
</Grid>

<Grid item>
<Autocomplete
disableClearable
className={classes.autocomplete}
data-testid={
ALERT_CREATION_NAVIGATE_DROPDOWN_TEST_IDS.DROPDOWN_CONTAINER
}
getOptionLabel={(option) => option.text}
options={shortcutCreateMenuItems}
renderInput={(params) => (
<TextField
{...params}
InputProps={{
...params.InputProps,
/**
* Override class name so
* the size of input is smaller
*/
className: classes.autoCompleteInput,
}}
variant="outlined"
/>
)}
size="small"
value={currentPage}
onChange={(_, selectedValue) => {
navigate(
`${routePathPrefix}/${
selectedValue.navLink
}?${searchParams.toString()}`
);
}}
/>
</Grid>
</Grid>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import { AlertCreatedGuidedPageOutletContext } from "../../alerts-create-guided-
import { SETUP_DETAILS_TEST_IDS } from "../../alerts-create-guided-page/setup-details/setup-details-page.interface";
import { easyAlertStyles } from "./alerts-create-easy-page.styles";
import { generateInputFieldConfigsForAlertTemplate } from "../../../components/alert-wizard-v3/threshold-setup/threshold-setup.utils";
import { NavigateAlertCreationFlowsDropdown } from "../../../components/alert-wizard-v3/navigate-alert-creation-flows-dropdown/navigate-alert-creation-flows-dropdown-v2";

const PROPERTIES_TO_COPY = [
"dataSource",
Expand Down Expand Up @@ -977,6 +978,17 @@ export const AlertsCreateEasyPage: FunctionComponent = () => {
<Grid item xs={12}>
<PageContentsCardV1 className={classes.container}>
<Grid container>
<Grid item xs={12}>
<Grid
container
alignContent="center"
justifyContent="flex-end"
>
<Grid item>
<NavigateAlertCreationFlowsDropdown />
</Grid>
</Grid>
</Grid>
<Grid item xs={12}>
<Box marginBottom={2}>
<Grid
Expand Down

0 comments on commit 5f16229

Please sign in to comment.