Skip to content

Commit

Permalink
Add notification after triggering refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Farcy authored and CFarcy committed Aug 30, 2023
1 parent ac096be commit c394df9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
6 changes: 5 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@
"started": "Started at",
"ended": "Ended at"
},
"status": "status"
"status": "Status",
"refresh": {
"accepted": "Refresh accepted",
"notAllowed": "Refresh not possible"
}
},
"edit": {
"refresh": "Refresh data",
Expand Down
6 changes: 5 additions & 1 deletion public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@
"started": "Commencée à",
"ended": "Finie à"
},
"status": "Statut"
"status": "Statut",
"refresh": {
"accepted": "Actualisation acceptée",
"notAllowed": "Actualisation impossible"
}
},
"edit": {
"refresh": "Actualiser les données",
Expand Down
59 changes: 40 additions & 19 deletions src/modules/RA/DataSource/components/DataSourceEditActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TopToolbar,
ListButton,
RefreshButton,
useNotify,
withDataProvider,
} from 'react-admin';

Expand All @@ -20,27 +21,47 @@ const style = () => ({

const DataSourceEditActions = ({
dataProvider,
data: { id, report } = {},
data: { id, report, _type } = {},
basePath,
classes,
}) => (
<TopToolbar>
<ListButton
basePath={basePath}
variant="outlined"
label="ra.action.back-to-list"
className={classes.list}
/>
{/* 'report' is null when a source has just been created */}
<StatusChip label="datasource.form.status" status={report ?? {}} />
<RefreshButton
color="primary"
variant="contained"
label="datasource.edit.refresh"
onClick={() => dataProvider('REFRESH', RES_DATASOURCE, { id })}
/>
</TopToolbar>
);
}) => {
const [pending, setPending] = React.useState(null);
const notify = useNotify();

const refreshData = React.useCallback(async () => {
try {
setPending(true);
await dataProvider('REFRESH', RES_DATASOURCE, { id });
notify('datasource.form.refresh.accepted', { type: 'success' });
} catch {
setPending(false);
notify('datasource.form.refresh.notAllowed', { type: 'error' });
}
}, [setPending, dataProvider, notify, id]);

return (
<TopToolbar>
<ListButton
basePath={basePath}
variant="outlined"
label="ra.action.back-to-list"
className={classes.list}
/>
{/* 'report' is null when a source has just been created */}
<StatusChip label="datasource.form.status" status={report ?? {}} />
{ _type !== 'WMTSSource' && (
<RefreshButton
color="primary"
variant="contained"
label="datasource.edit.refresh"
onClick={refreshData}
disabled={pending}
/>
)}
</TopToolbar>
);
};


export default compose(
withStyles(style),
Expand Down

0 comments on commit c394df9

Please sign in to comment.