CacheClean.tsx 1023 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React, { useState } from 'react';
  2. import { Button, ConfirmModal } from '@grafana/ui';
  3. import { Props } from './DataSourceCache';
  4. export const CacheClean = (props: Props) => {
  5. const { cleanCache, pageId } = props;
  6. const [showCleanModal, setShowCleanModal] = useState(false);
  7. const showConfirmCleanModal = (show: boolean) => () => {
  8. setShowCleanModal(show);
  9. };
  10. const handleCleanCache = () => {
  11. cleanCache(pageId);
  12. setShowCleanModal(false);
  13. };
  14. return (
  15. <div>
  16. <Button variant="destructive" onClick={showConfirmCleanModal(true)}>
  17. Clear cache
  18. </Button>
  19. <ConfirmModal
  20. isOpen={showCleanModal}
  21. title="Clear cache"
  22. body="Warning: This action impacts all cache-enabled data sources. If you are using Memcached, the system clears all data from the Memcached instance. Do you want to continue?"
  23. confirmText="Clear cache"
  24. onConfirm={handleCleanCache}
  25. onDismiss={showConfirmCleanModal(false)}
  26. />
  27. </div>
  28. );
  29. };