* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { checkStatus, corsRequest, getJSON, parseJSON, postJSON } from '../helpers/request';
+import { checkStatus, corsRequest, getJSON, parseJSON, post, postJSON } from '../helpers/request';
import throwGlobalError from '../app/utils/throwGlobalError';
export interface Edition {
}
export function uninstallEdition(): Promise<void | Response> {
- return postJSON('/api/editions/uninstall').catch(throwGlobalError);
+ return post('/api/editions/uninstall').catch(throwGlobalError);
+}
+
+export function dismissErrorMessage(): Promise<void | Response> {
+ return post('/api/editions/clear_error_message').catch(throwGlobalError);
}
<div className="page page-limited" id="marketplace-page">
<Helmet title={translate('marketplace.page')} />
<div className="marketplace-notifs">
- {editionStatus && <EditionsStatusNotif editionStatus={editionStatus} />}
+ {editionStatus && (
+ <EditionsStatusNotif
+ editionStatus={editionStatus}
+ updateEditionStatus={this.updateEditionStatus}
+ />
+ )}
<PendingActions refreshPending={this.fetchPendingPlugins} pending={pending} />
</div>
<Header />
*/
import * as React from 'react';
import RestartForm from '../../../components/common/RestartForm';
-import { EditionStatus } from '../../../api/marketplace';
+import CloseIcon from '../../../components/icons-components/CloseIcon';
+import { dismissErrorMessage, EditionStatus } from '../../../api/marketplace';
import { translate } from '../../../helpers/l10n';
interface Props {
editionStatus: EditionStatus;
+ updateEditionStatus: (editionStatus: EditionStatus) => void;
}
interface State {
handleOpenRestart = () => this.setState({ openRestart: true });
hanleCloseRestart = () => this.setState({ openRestart: false });
+ handleDismissError = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
+ event.preventDefault();
+ dismissErrorMessage().then(
+ () =>
+ this.props.updateEditionStatus({ ...this.props.editionStatus, installError: undefined }),
+ () => {}
+ );
+ };
+
renderStatusAlert() {
const { installationStatus } = this.props.editionStatus;
switch (installationStatus) {
const { installError } = this.props.editionStatus;
return (
<div>
- {installError && <div className="alert alert-danger">{installError}</div>}
+ {installError && (
+ <div className="alert alert-danger">
+ {installError}
+ <a
+ className="pull-right button-link text-danger"
+ href="#"
+ onClick={this.handleDismissError}>
+ <CloseIcon />
+ </a>
+ </div>
+ )}
{this.renderStatusAlert}
</div>
);
*/
import * as React from 'react';
import { shallow } from 'enzyme';
+import { click } from '../../../../helpers/testUtils';
import EditionsStatusNotif from '../EditionsStatusNotif';
+jest.mock('../../../../api/marketplace', () => ({
+ dismissErrorMessage: jest.fn(() => Promise.resolve())
+}));
+
+const dismissMsg = require('../../../../api/marketplace').dismissErrorMessage as jest.Mock<any>;
+
+beforeEach(() => {
+ dismissMsg.mockClear();
+});
+
it('should display an in progress notif', () => {
const wrapper = shallow(
- <EditionsStatusNotif editionStatus={{ installationStatus: 'AUTOMATIC_IN_PROGRESS' }} />
+ <EditionsStatusNotif
+ editionStatus={{ installationStatus: 'AUTOMATIC_IN_PROGRESS' }}
+ updateEditionStatus={jest.fn()}
+ />
);
expect(wrapper).toMatchSnapshot();
});
it('should display an error notification', () => {
const wrapper = shallow(
- <EditionsStatusNotif editionStatus={{ installationStatus: 'AUTOMATIC_FAILURE' }} />
+ <EditionsStatusNotif
+ editionStatus={{ installationStatus: 'AUTOMATIC_FAILURE' }}
+ updateEditionStatus={jest.fn()}
+ />
);
expect(wrapper).toMatchSnapshot();
});
it('should display a ready notification', () => {
const wrapper = shallow(
- <EditionsStatusNotif editionStatus={{ installationStatus: 'AUTOMATIC_READY' }} />
+ <EditionsStatusNotif
+ editionStatus={{ installationStatus: 'AUTOMATIC_READY' }}
+ updateEditionStatus={jest.fn()}
+ />
);
expect(wrapper).toMatchSnapshot();
});
const wrapper = shallow(
<EditionsStatusNotif
editionStatus={{ installationStatus: 'AUTOMATIC_IN_PROGRESS', installError: 'Foo error' }}
+ updateEditionStatus={jest.fn()}
/>
);
expect(wrapper).toMatchSnapshot();
});
+
+it('should allow to dismiss install errors', async () => {
+ const updateEditionStatus = jest.fn();
+ const wrapper = shallow(
+ <EditionsStatusNotif
+ editionStatus={{ installationStatus: 'NONE', installError: 'Foo error' }}
+ updateEditionStatus={updateEditionStatus}
+ />
+ );
+ click(wrapper.find('a'));
+ expect(dismissMsg).toHaveBeenCalled();
+ await new Promise(setImmediate);
+ expect(updateEditionStatus).toHaveBeenCalledWith({
+ installationStatus: 'NONE',
+ installError: undefined
+ });
+});
className="alert alert-danger"
>
Foo error
+ <a
+ className="pull-right button-link text-danger"
+ href="#"
+ onClick={[Function]}
+ >
+ <CloseIcon />
+ </a>
</div>
</div>
`;