Commit 41ef001a authored by Alejandro De Maria Antolinos's avatar Alejandro De Maria Antolinos

Merge branch 'issue466' into 'master'

it fixes #466. Tests are not included yet

Closes #466

See merge request !473
parents 4b7b7357 2d413012
Pipeline #37641 passed with stages
in 12 minutes and 11 seconds
import PropTypes from 'prop-types';
import React from 'react';
import { Panel } from 'react-bootstrap';
import { Panel, Button } from 'react-bootstrap';
/**
* React component which renders a message to the user
*/
function UserMessage(props) {
const { type, message } = props;
const { type, message, onRetryClicked } = props;
if (!type || !message || message === '') {
return null;
}
const retryButton = onRetryClicked && (
<Button bsStyle="link" onClick={onRetryClicked}>
Retry
</Button>
);
return (
<Panel bsStyle={getbsStyle(type)} style={{ marginBottom: 0 }}>
<Panel.Heading> {getHeaderText(type)} </Panel.Heading>
<Panel.Body>{message}</Panel.Body>
<Panel.Body>
{message}
{retryButton}
</Panel.Body>
</Panel>
);
}
......@@ -23,6 +32,8 @@ function UserMessage(props) {
UserMessage.propTypes = {
/** Message itself */
message: PropTypes.string.isRequired,
/** Function triggered when the use clicks the retry link. No link displayed when not provided */
onRetryClicked: PropTypes.func,
/* Type of the message */
type: PropTypes.oneOf(['error', 'info', 'success']).isRequired,
};
......
......@@ -9,18 +9,19 @@ import { getSearchFilter } from './SelectionFilterHelper';
import { LIST_VIEW, DOC_VIEW } from '../../constants/eventTypes';
import { store } from '../../store';
import { getFirstIndexToDisplay } from '../../helpers/eventsProviderHelper';
import UserMessage from '../../components/UserMessage';
/**
* Events Provider. It takes care about events retrieval and page management.
*/
function EventsProvider(props) {
const { children, investigationId, sortingFilter } = props;
const { setErrorMessage, searchCriteria, forceReload, view, page } = props;
const { searchCriteria, forceReload, view, page } = props;
const [downloadedEvents, setDownloadedEvents] = useState({}); //{ isFetching: bool, events: [], startIndex: Number, endIndex: Number}
const [downloadedEvents, setDownloadedEvents] = useState({}); //{ isFetching: bool, events: [], startIndex: Number, endIndex: Number, isError: bool}
const { EVENTS_PER_PAGE } = UI.logbook;
const { events, isFetching, startIndex } = downloadedEvents;
const { events, isFetching, startIndex, isError } = downloadedEvents;
const isDownloaded = isLocallyAvailable(page, downloadedEvents);
const skip = EVENTS_PER_PAGE * (page - 1);
......@@ -30,7 +31,7 @@ function EventsProvider(props) {
}, [investigationId, sortingFilter, searchCriteria, view, forceReload]);
useEffect(() => {
if (isFetching || isDownloaded) {
if (isFetching || isDownloaded || isError) {
return;
}
......@@ -47,24 +48,33 @@ function EventsProvider(props) {
});
})
.catch(() => {
setDownloadedEvents({ isFetching: false });
setErrorMessage('Could not get the logs');
setDownloadedEvents({ isFetching: false, isError: true });
});
}, [
investigationId,
skip,
sortingFilter,
setErrorMessage,
searchCriteria,
view,
isDownloaded,
isFetching,
isError,
]);
if (isFetching) {
return <Loader message="Loading logbook..." />;
}
if (isError) {
return (
<UserMessage
type="error"
message="Could not get the logs"
onRetryClicked={() => setDownloadedEvents({})}
/>
);
}
if (!isDownloaded) {
return children(null);
}
......@@ -85,8 +95,6 @@ EventsProvider.propTypes = {
investigationId: PropTypes.number,
/** Sorting filter */
sortingFilter: PropTypes.object,
/** Function triggered when an error during events retrival occurs */
setErrorMessage: PropTypes.func,
/** search criteria */
searchCriteria: PropTypes.array,
/** current logbook view */
......
......@@ -84,7 +84,6 @@ export class LogbookContainerClass extends React.Component {
this.searchEvents = this.searchEvents.bind(this);
this.setNewEventVisibility = this.setNewEventVisibility.bind(this);
this.setView = this.setView.bind(this);
this.setErrorMessage = this.setErrorMessage.bind(this);
}
render() {
......@@ -229,7 +228,6 @@ export class LogbookContainerClass extends React.Component {
<EventsProvider
page={page}
setErrorMessage={this.setErrorMessage}
searchCriteria={searchCriteria}
view={view}
sortingFilter={sortingFilter}
......@@ -531,10 +529,6 @@ export class LogbookContainerClass extends React.Component {
});
}
}
setErrorMessage(errorMessage) {
this.setState({ errorMessage });
}
}
function mapStateToProps(state) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment