Skip to content

Commit

Permalink
Add closeButtonText prop to modal components; implement confirmation …
Browse files Browse the repository at this point in the history
…modal for unsaved changes in DashboardToolbar
  • Loading branch information
simlarsen committed Dec 3, 2024
1 parent d473784 commit 9d0add6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Common/UI/Components/Modal/ConfirmModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ComponentProps {
onSubmit: () => void;
submitButtonType?: undefined | ButtonStyleType;
closeButtonType?: undefined | ButtonStyleType;
closeButtonText?: undefined | string;
isLoading?: boolean;
error?: string | undefined;
disableSubmitButton?: boolean | undefined;
Expand All @@ -27,6 +28,9 @@ const ConfirmModal: FunctionComponent<ComponentProps> = (
submitButtonText={
props.submitButtonText ? props.submitButtonText : "Confirm"
}
closeButtonText={
props.closeButtonText ? props.closeButtonText : "Cancel"
}
closeButtonStyleType={
props.closeButtonType ? props.closeButtonType : ButtonStyleType.NORMAL
}
Expand Down
4 changes: 4 additions & 0 deletions Common/UI/Components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface ComponentProps {
iconType?: IconType | undefined;
modalWidth?: ModalWidth | undefined;
rightElement?: ReactElement | undefined;
closeButtonText?: string | undefined;
}

const Modal: FunctionComponent<ComponentProps> = (
Expand Down Expand Up @@ -164,6 +165,9 @@ const Modal: FunctionComponent<ComponentProps> = (
submitButtonText={
props.submitButtonText ? props.submitButtonText : "Save"
}
closeButtonText={
props.closeButtonText ? props.closeButtonText : "Cancel"
}
onSubmit={props.onSubmit}
onClose={props.onClose ? props.onClose : undefined}
isLoading={props.isLoading || false}
Expand Down
3 changes: 2 additions & 1 deletion Common/UI/Components/Modal/ModalFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ComponentProps {
submitButtonType?: undefined | ButtonType;
isLoading?: undefined | boolean;
disableSubmitButton?: undefined | boolean;
closeButtonText?: undefined | string;
}

const ModalFooter: FunctionComponent<ComponentProps> = (
Expand Down Expand Up @@ -49,7 +50,7 @@ const ModalFooter: FunctionComponent<ComponentProps> = (
? props.closeButtonStyleType
: ButtonStyleType.NORMAL
}
title={"Close"}
title={props.closeButtonText ? props.closeButtonText : "Cancel"}
data-dismiss="modal"
onClick={() => {
props.onClose && props.onClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ const DashboardChartComponentElement: FunctionComponent<ComponentProps> = (
}

if (error) {
return <div className="m-auto flex flex-col justify-center w-full h-full">
<div className="h-7 w-7 text-gray-400 w-full text-center mx-auto">
<Icon icon={IconProp.ChartBar} />
return (
<div className="m-auto flex flex-col justify-center w-full h-full">
<div className="h-7 w-7 text-gray-400 w-full text-center mx-auto">
<Icon icon={IconProp.ChartBar} />
</div>
<ErrorMessage error={error} />
</div>
<ErrorMessage error={error} />
</div>
);
}

let heightOfChart: number | undefined =
Expand All @@ -142,18 +144,18 @@ const DashboardChartComponentElement: FunctionComponent<ComponentProps> = (
const chartMetricViewData: MetricViewData = {
queryConfigs: props.component.arguments.metricQueryConfig
? [
{
...props.component.arguments.metricQueryConfig!,
metricAliasData: {
title: props.component.arguments.chartTitle || undefined,
description:
props.component.arguments.chartDescription || undefined,
metricVariable: undefined,
legend: props.component.arguments.legendText || undefined,
legendUnit: props.component.arguments.legendUnit || undefined,
{
...props.component.arguments.metricQueryConfig!,
metricAliasData: {
title: props.component.arguments.chartTitle || undefined,
description:
props.component.arguments.chartDescription || undefined,
metricVariable: undefined,
legend: props.component.arguments.legendText || undefined,
legendUnit: props.component.arguments.legendUnit || undefined,
},
},
},
]
]
: [],
startAndEndDate: DashboardStartAndEndDateUtil.getStartAndEndDate(
props.dashboardStartAndEndDate,
Expand Down
28 changes: 27 additions & 1 deletion Dashboard/src/Components/Dashboard/Toolbar/DashboardToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DashboardStartAndEndDate from "../Types/DashboardStartAndEndDate";
import DashboardStartAndEndDateElement from "./DashboardStartAndEndDateEdit";
import DashboardStartAndEndDateView from "./DashboardStartAndEndDateView";
import DashboardViewConfig from "Common/Types/Dashboard/DashboardViewConfig";
import ConfirmModal from "Common/UI/Components/Modal/ConfirmModal";

export interface ComponentProps {
onEditClick: () => void;
Expand All @@ -35,6 +36,8 @@ const DashboardToolbar: FunctionComponent<ComponentProps> = (
const [showTimeSelectModal, setShowTimeSelectModal] =
useState<boolean>(false);

const [showCancelModal, setShowCancelModal] = useState<boolean>(false);

return (
<div
className={`mt-1.5 mb-1.5 ml-1 mr-1 p-1 h-20 pt-5 pb-5 pl-4 pr-4 rounded bg-white border-2 border-gray-100`}
Expand Down Expand Up @@ -120,7 +123,9 @@ const DashboardToolbar: FunctionComponent<ComponentProps> = (
icon={IconProp.Close}
title="Cancel"
buttonStyle={ButtonStyleType.HOVER_DANGER_OUTLINE}
onClick={props.onCancelEditClick}
onClick={()=>{
setShowCancelModal(true);
}}
/>
)}
</div>
Expand All @@ -133,6 +138,27 @@ const DashboardToolbar: FunctionComponent<ComponentProps> = (
)}
</div>

{showCancelModal ? (
<ConfirmModal
title={`Are you sure?`}
description={
"You have unsaved changes. Are you sure you want to cancel?"
}
submitButtonType={ButtonStyleType.DANGER}
submitButtonText={"Discard Changes"}
closeButtonText={"Keep Editing"}
onSubmit={() => {
props.onCancelEditClick();
setShowCancelModal(false);
}}
onClose={() => {
setShowCancelModal(false);
}}
/>
) : (
<></>
)}

{showTimeSelectModal && (
<Modal
title="Select Start and End Time"
Expand Down

0 comments on commit 9d0add6

Please sign in to comment.