Skip to content

Commit

Permalink
change: dialog and savedialog
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Nov 29, 2024
1 parent ce1cc17 commit d9ab452
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 182 deletions.
58 changes: 58 additions & 0 deletions src/web/components/dialog/SaveDialogFooter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import MultiStepFooter from 'web/components/dialog/multistepfooter';
import DialogFooter from 'web/components/dialog/twobuttonfooter';
import PropTypes from 'web/utils/proptypes';

const SaveDialogFooter = ({
multiStep,
isLoading,
prevDisabled,
nextDisabled,
buttonTitle,
currentStep,
setCurrentStep,
onClose,
handleSaveClick,
}) => {
return multiStep > 0 ? (
<MultiStepFooter
loading={isLoading}
prevDisabled={prevDisabled}
nextDisabled={nextDisabled}
rightButtonTitle={buttonTitle}
onNextButtonClick={() =>
setCurrentStep(currentStep < multiStep ? currentStep + 1 : currentStep)

Check warning on line 28 in src/web/components/dialog/SaveDialogFooter.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/dialog/SaveDialogFooter.jsx#L22-L28

Added lines #L22 - L28 were not covered by tests
}
onLeftButtonClick={onClose}
onPreviousButtonClick={() =>
setCurrentStep(currentStep > 0 ? currentStep - 1 : currentStep)

Check warning on line 32 in src/web/components/dialog/SaveDialogFooter.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/dialog/SaveDialogFooter.jsx#L30-L32

Added lines #L30 - L32 were not covered by tests
}
onRightButtonClick={handleSaveClick}
/>

Check warning on line 35 in src/web/components/dialog/SaveDialogFooter.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/dialog/SaveDialogFooter.jsx#L34-L35

Added lines #L34 - L35 were not covered by tests
) : (
<DialogFooter
isLoading={isLoading}
rightButtonTitle={buttonTitle}
onLeftButtonClick={onClose}
onRightButtonClick={handleSaveClick}
/>
);
};

SaveDialogFooter.propTypes = {
multiStep: PropTypes.number.isRequired,
isLoading: PropTypes.bool.isRequired,
prevDisabled: PropTypes.bool.isRequired,
nextDisabled: PropTypes.bool.isRequired,
buttonTitle: PropTypes.string.isRequired,
currentStep: PropTypes.number.isRequired,
setCurrentStep: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
handleSaveClick: PropTypes.func.isRequired,
};

export default SaveDialogFooter;
60 changes: 13 additions & 47 deletions src/web/components/dialog/confirmationdialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import React, {useCallback} from 'react';

import PropTypes from 'web/utils/proptypes';

import Dialog from 'web/components/dialog/dialog';
import DialogContent from 'web/components/dialog/content';
import Dialog from 'web/components/dialog/dialog';
import DialogTwoButtonFooter, {
DELETE_ACTION,
} from 'web/components/dialog/twobuttonfooter';
Expand All @@ -17,43 +15,6 @@ import useTranslation from 'web/hooks/useTranslation';

const DEFAULT_DIALOG_WIDTH = '400px';

const ConfirmationDialogContent = ({
content,
close,
rightButtonTitle,
onResumeClick,
loading,
rightButtonAction,
}) => {
const handleResume = useCallback(() => {
if (onResumeClick) {
onResumeClick();
}
}, [onResumeClick]);

return (
<DialogContent>
{content}
<DialogTwoButtonFooter
rightButtonTitle={rightButtonTitle}
onLeftButtonClick={close}
onRightButtonClick={handleResume}
loading={loading}
rightButtonAction={rightButtonAction}
/>
</DialogContent>
);
};

ConfirmationDialogContent.propTypes = {
close: PropTypes.func.isRequired,
content: PropTypes.elementOrString,
rightButtonTitle: PropTypes.string,
onResumeClick: PropTypes.func.isRequired,
loading: PropTypes.bool,
rightButtonAction: PropTypes.oneOf([undefined, DELETE_ACTION]),
};

const ConfirmationDialog = ({
width = DEFAULT_DIALOG_WIDTH,
content,
Expand All @@ -67,18 +28,23 @@ const ConfirmationDialog = ({
const [_] = useTranslation();

rightButtonTitle = rightButtonTitle || _('OK');

return (
<Dialog width={width} onClose={onClose} title={title}>
{({close}) => (
<ConfirmationDialogContent
close={close}
content={content}
<Dialog
width={width}
onClose={onClose}
title={title}
footer={
<DialogTwoButtonFooter
rightButtonTitle={rightButtonTitle}
onResumeClick={onResumeClick}
onLeftButtonClick={onClose}
onRightButtonClick={onResumeClick}
loading={loading}
rightButtonAction={rightButtonAction}
/>
)}
}
>
<DialogContent>{content}</DialogContent>
</Dialog>
);
};
Expand Down
9 changes: 0 additions & 9 deletions src/web/components/dialog/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,4 @@ const DialogContent = styled.div`
gap: 20px;
`;

export const StickyFooter = styled.div`
position: sticky;
bottom: 0;
background-color: white;
padding: 20px 0;
z-index: 201;
margin-bottom: 20;
`;

export default DialogContent;
38 changes: 25 additions & 13 deletions src/web/components/dialog/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import {Modal} from '@greenbone/opensight-ui-components-mantinev7';
import {ScrollArea} from '@mantine/core';
import {isDefined, isFunction} from 'gmp/utils/identity';
import {useCallback, useEffect, useState} from 'react';
import styled from 'styled-components';
Expand All @@ -27,6 +28,10 @@ const DialogTitleButton = styled.button`
`;

const StyledModal = styled(Modal)`
position: relative;
left: ${({position}) => `${position.x}px`};
z-index: ${MODAL_Z_INDEX};
.mantine-Modal-content {
display: flex;
flex-direction: column;
Expand All @@ -42,27 +47,30 @@ const StyledModal = styled(Modal)`
flex: 1;
}
.mantine-Modal-body {
padding-bottom: 0px;
margin-bottom: 15px;
overflow-y: auto;
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.mantine-Modal-close {
width: 2rem;
height: 2rem;
}
`;

position: relative;
left: ${({position}) => `${position.x}px`};
z-index: ${MODAL_Z_INDEX};
resize: both;
const StyledScrollArea = styled(ScrollArea)`
flex: 1;
overflow-y: auto;
padding-right: 18px;
`;

const Dialog = ({
children,
title,
footer,
onClose,
height = MODAL_HEIGHT,
width = MODAL_WIDTH,
onClose,
}) => {
const [isResizing, setIsResizing] = useState(false);

Expand Down Expand Up @@ -150,17 +158,21 @@ const Dialog = ({
height={height}
position={position}
>
{isFunction(children)
? children({
close: handleClose,
})
: children}
<StyledScrollArea>
{isFunction(children)
? children({
close: handleClose,
})
: children}
</StyledScrollArea>
{footer}
</StyledModal>
);
};

Dialog.propTypes = {
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
footer: PropTypes.node,
title: PropTypes.string,
width: PropTypes.string,
onClose: PropTypes.func,
Expand Down
Loading

0 comments on commit d9ab452

Please sign in to comment.