From c394df99ffa592d051f7a3c0299a8e2612557b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Farcy?= Date: Wed, 30 Aug 2023 14:51:01 +0200 Subject: [PATCH] Add notification after triggering refresh --- public/locales/en/translation.json | 6 +- public/locales/fr/translation.json | 6 +- .../components/DataSourceEditActions.js | 59 +++++++++++++------ 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index f12ff5de..b71a4d03 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -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", diff --git a/public/locales/fr/translation.json b/public/locales/fr/translation.json index 73d91132..011fa295 100644 --- a/public/locales/fr/translation.json +++ b/public/locales/fr/translation.json @@ -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", diff --git a/src/modules/RA/DataSource/components/DataSourceEditActions.js b/src/modules/RA/DataSource/components/DataSourceEditActions.js index 1816dfd4..2d3ef43c 100644 --- a/src/modules/RA/DataSource/components/DataSourceEditActions.js +++ b/src/modules/RA/DataSource/components/DataSourceEditActions.js @@ -3,6 +3,7 @@ import { TopToolbar, ListButton, RefreshButton, + useNotify, withDataProvider, } from 'react-admin'; @@ -20,27 +21,47 @@ const style = () => ({ const DataSourceEditActions = ({ dataProvider, - data: { id, report } = {}, + data: { id, report, _type } = {}, basePath, classes, -}) => ( - - - {/* 'report' is null when a source has just been created */} - - dataProvider('REFRESH', RES_DATASOURCE, { id })} - /> - -); +}) => { + 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 ( + + + {/* 'report' is null when a source has just been created */} + + { _type !== 'WMTSSource' && ( + + )} + + ); +}; + export default compose( withStyles(style),