ZipFileTable.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { format } from 'date-fns';
  5. import { createSubscribedElement } from '../../UnstatedUtils';
  6. import AppContainer from '../../../services/AppContainer';
  7. // import { toastSuccess, toastError } from '../../../util/apiNotification';
  8. class ZipFileTable extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.deleteZipFile = this.deleteZipFile.bind(this);
  12. }
  13. async deleteZipFile(zipFile) {
  14. // TODO use appContainer.apiv3.delete
  15. await this.props.appContainer.apiRequest('delete', `/v3/export/${zipFile}`, {});
  16. this.props.removeZipFileStat(zipFile);
  17. // TODO toastSuccess, toastError
  18. }
  19. render() {
  20. // const { t } = this.props;
  21. return (
  22. <table className="table table-bordered">
  23. <thead>
  24. <tr>
  25. <th>File</th>
  26. <th>Growi Version</th>
  27. <th>Collections</th>
  28. <th>Exported At</th>
  29. <th></th>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. {this.props.zipFileStats.map(({ meta, fileName, fileStats }) => {
  34. return (
  35. <tr key={fileName}>
  36. <th>{fileName}</th>
  37. <td>{meta.version}</td>
  38. <td className="text-capitalize">{fileStats.map(fileStat => fileStat.collectionName).join(', ')}</td>
  39. <td>{meta.exportedAt ? format(new Date(meta.exportedAt), 'yyyy/MM/dd HH:mm:ss') : ''}</td>
  40. <td>
  41. <a href="/_api/v3/export">
  42. <button type="button" className="btn btn-sm btn-primary ml-2">Download</button>
  43. </a>
  44. <button type="button" className="btn btn-sm btn-danger ml-2" onClick={() => this.deleteZipFile(fileName)}>Delete</button>
  45. </td>
  46. </tr>
  47. );
  48. })}
  49. </tbody>
  50. </table>
  51. );
  52. }
  53. }
  54. ZipFileTable.propTypes = {
  55. t: PropTypes.func.isRequired, // i18next
  56. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  57. zipFileStats: PropTypes.arrayOf(PropTypes.object).isRequired,
  58. removeZipFileStat: PropTypes.func.isRequired,
  59. };
  60. /**
  61. * Wrapper component for using unstated
  62. */
  63. const ZipFileTableWrapper = (props) => {
  64. return createSubscribedElement(ZipFileTable, props, [AppContainer]);
  65. };
  66. export default withTranslation()(ZipFileTableWrapper);