Line data Source code
1 : /*
2 : * This file is part of Cockpit.
3 : *
4 : * Copyright (C) 2019 Red Hat, Inc.
5 : *
6 : * Cockpit is free software; you can redistribute it and/or modify it
7 : * under the terms of the GNU Lesser General Public License as published by
8 : * the Free Software Foundation; either version 2.1 of the License, or
9 : * (at your option) any later version.
10 : *
11 : * Cockpit is distributed in the hope that it will be useful, but
12 : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : * Lesser General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public License
17 : * along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
18 : */
19 43 : import React from 'react';
20 :
21 : import { Alert, AlertActionCloseButton } from "@patternfly/react-core/dist/esm/components/Alert";
22 :
23 : import cockpit from 'cockpit';
24 :
25 43 : const _ = cockpit.gettext;
26 :
27 43 : let last_error = "";
28 :
29 7 : function log_error_if_changed(error) {
30 : // Put the error in the browser log, for easier debugging and
31 : // matching of known issues in the integration tests.
32 7 : if (error != last_error) {
33 7 : last_error = error;
34 7 : console.error(error);
35 7 : }
36 7 : }
37 :
38 7 : export const ErrorNotification = ({ errorMessage, errorDetail, onDismiss }) => {
39 0 : log_error_if_changed(errorMessage + (errorDetail ? ": " + errorDetail : ""));
40 7 : return (
41 7 : <Alert isInline variant='danger' title={errorMessage}
42 0 : actionClose={onDismiss ? <AlertActionCloseButton onClose={onDismiss} /> : null}>
43 7 : { errorDetail && <p> {_("Error message")}: <samp>{errorDetail}</samp> </p> }
44 7 : </Alert>
45 : );
46 7 : };
|