Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DHIS2-17874] replace remaining Material UI components #3794

Merged
13 changes: 2 additions & 11 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-08-10T10:42:21.141Z\n"
"PO-Revision-Date: 2024-08-10T10:42:21.141Z\n"
"POT-Creation-Date: 2024-09-08T20:48:49.045Z\n"
"PO-Revision-Date: 2024-09-08T20:48:49.045Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -598,15 +598,6 @@ msgstr "Program doesn't exist"
msgid "Selected program is invalid for selected organisation unit"
msgstr "Selected program is invalid for selected organisation unit"

msgid "Online"
msgstr "Online"

msgid "Offline"
msgstr "Offline"

msgid "Syncing"
msgstr "Syncing"

msgid "Add note"
msgstr "Add note"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// @flow
import * as React from 'react';
import SnackBar from '@material-ui/core/Snackbar';
import React, { type Node } from 'react';
import { withStyles } from '@material-ui/core/styles';
import { IconButton } from 'capture-ui';
import { IconCross24, Button, Modal, ModalTitle, ModalContent, ModalActions } from '@dhis2/ui';
import { Button, Modal, ModalTitle, ModalContent, ModalActions, AlertStack, AlertBar } from '@dhis2/ui';
import i18n from '@dhis2/d2-i18n';
import isDefined from 'd2-utilizr/lib/isDefined';

const styles = () => ({
closeButton: {
Expand All @@ -17,110 +14,43 @@ const styles = () => ({
});

type Feedback = {
message: string | { title: string, content: string},
action?: ?React.Node,
displayType?: ?string,
message: string | { title: string, content: string },
action?: Node,
displayType?: 'alert' | 'dialog',
};

type Props = {
feedback: Feedback,
onClose: () => void,
classes: Object,
};

class Index extends React.Component<Props> {
static defaultProps = {
feedback: {},
};

constructor(props: Props) {
super(props);
this.handleClose = this.handleClose.bind(this);
}
static CLICKAWAY_KEY = 'clickaway';

static ANCHOR_ORIGIN = {
vertical: 'bottom',
horizontal: 'center',
};

handleClose = (event?: ?Object, reason?: ?string) => {
if (reason !== Index.CLICKAWAY_KEY) {
this.props.onClose();
}
}

getAction() {
const { feedback, classes } = this.props;

return (
<>
{
(() => {
if (!feedback.action) {
return null;
}

return (
<span
className={classes.actionContainer}
>
{feedback.action}
</span>
);
})()
}
<IconButton
className={classes.closeButton}
onClick={this.handleClose}
>
<IconCross24 />
</IconButton>
</>
);
}

render() {
const { feedback } = this.props;
const { message, displayType } = feedback;
const isSnackBarOpen = isDefined(message) && !displayType;
const isDialogOpen = isDefined(message) && displayType === 'dialog';
return (
<React.Fragment>
<SnackBar
open={isSnackBarOpen}
anchorOrigin={Index.ANCHOR_ORIGIN}
autoHideDuration={5000}
onClose={this.handleClose}
// $FlowFixMe[incompatible-type] automated comment
message={<span>{message}</span>}
action={this.getAction()}
/>
{isDialogOpen && (
<Modal
hide={!isDialogOpen}
>
<ModalTitle>
{
// $FlowFixMe[prop-missing] automated comment
isDialogOpen ? message && message.title : ''}
</ModalTitle>
<ModalContent>
{
// $FlowFixMe[prop-missing] automated comment
isDialogOpen ? message && message.content : ''}
</ModalContent>
<ModalActions>
<Button onClick={this.handleClose} primary>
{i18n.t('Close')}
</Button>
</ModalActions>
</Modal>
const FeedbackBarComponentPlain = ({ feedback = {}, onClose }: Props) => {
const { message, displayType } = feedback;
const isAlertBarOpen = typeof message === 'string' && !displayType;
const isDialogOpen = typeof message === 'object' && displayType === 'dialog';

return (
<>
<AlertStack>
{isAlertBarOpen && (
<AlertBar duration={5000}>
{message}
</AlertBar>
)}
</React.Fragment>
);
}
}
Index.displayName = 'FeedbackBar';
</AlertStack>
{isDialogOpen && (
<Modal hide={!isDialogOpen}>
<ModalTitle>{message?.title || ''}</ModalTitle>
<ModalContent>{message?.content || ''}</ModalContent>
<ModalActions>
<Button onClick={onClose} primary>
{i18n.t('Close')}
</Button>
</ModalActions>
</Modal>
)}
</>
);
};

export const FeedbackBarComponent = withStyles(styles)(Index);
export const FeedbackBarComponent = withStyles(styles)(FeedbackBarComponentPlain);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import parse from 'autosuggest-highlight/parse';
import MenuItem from '@material-ui/core/MenuItem';
import { MenuItem } from '@dhis2/ui';
import classNames from 'classnames';
import { SearchContext } from './Search.context';
import defaultClasses from './searchSuggestion.module.css';
Expand Down Expand Up @@ -96,7 +96,6 @@ export const SearchSuggestion = (props: Props) => {
onExitSearch();
}
}, [onExitSearch, suggestionName, inputName]);

return (
<div
name={suggestionName}
Expand All @@ -109,23 +108,24 @@ export const SearchSuggestion = (props: Props) => {
onBlur={handleBlur}
>
<MenuItem
selected={isHighlighted}
component="div"
>
<div>
{parts.map((part, index) => (part.highlight ? (
// eslint-disable-next-line react/no-array-index-key
<span key={String(index)} style={{ fontWeight: 500 }}>
{part.text}
</span>
) : (
// eslint-disable-next-line react/no-array-index-key
<strong key={String(index)} style={{ fontWeight: 300 }}>
{part.text}
</strong>
)))}
</div>
</MenuItem>
active={isHighlighted}
label={(
<div>
{parts.map((part, index) => (part.highlight ? (
// eslint-disable-next-line react/no-array-index-key
<span key={String(index)} style={{ fontWeight: 500 }}>
{part.text}
</span>
) : (
// eslint-disable-next-line react/no-array-index-key
<strong key={String(index)} style={{ fontWeight: 300 }}>
{part.text}
</strong>
)))}
</div>
)}
/>

</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import React from 'react';
import Paper from '@material-ui/core/Paper/Paper';
import { withStyles } from '@material-ui/core';
import { colors } from '@dhis2/ui';

const StyledPaper = withStyles({
root: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
background: colors.grey200,
color: colors.grey700,
padding: '12px 16px',
},
})(Paper);

const containerStyle = {
display: 'flex',
justifyContent: 'center',
width: '100%',
};

const messageBoxStyle = {
alignItems: 'center',
background: colors.grey200,
color: colors.grey700,
padding: '12px 16px',
borderRadius: '4px',
};

export const IncompleteSelectionsMessage = ({ children, dataTest = 'informative-paper' }) => (
<div style={containerStyle}>
<StyledPaper data-test={dataTest} elevation={0}>
<div style={messageBoxStyle} data-test={dataTest}>
{children}
</StyledPaper>
</div>
</div>
);
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// @flow
import * as React from 'react';
import { withStyles } from '@material-ui/core/styles';
import createSvgIcon from '@material-ui/icons/utils/createSvgIcon';
import { Tooltip, Button } from '@dhis2/ui';
import i18n from '@dhis2/d2-i18n';
import classNames from 'classnames';

const ClearIcon = createSvgIcon(
<React.Fragment>
const ClearIcon = ({ className, ...props }) => (
<svg
className={className}
{...props}
viewBox="0 0 24 24"
width={24}
height={24}
>
<path d="M12,2C17.53,2 22,6.47 22,12C22,17.53 17.53,22 12,22C6.47,22 2,17.53 2,12C2,6.47 6.47,2 12,2M15.59,7L12,10.59L8.41,7L7,8.41L10.59,12L7,15.59L8.41,17L12,13.41L15.59,17L17,15.59L13.41,12L17,8.41L15.59,7Z" />
</React.Fragment>,
'CloseCircle',
</svg>
);

const getStyles = (theme: Theme) => ({
Expand Down
Loading
Loading