Import.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { FC } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { makeStyles, Theme, Divider, Typography } from '@material-ui/core';
  4. import CustomSelector from '../customSelector/CustomSelector';
  5. import { InsertImportProps } from './Types';
  6. import Uploader from '../uploader/Uploader';
  7. import { INSERT_CSV_SAMPLE, INSERT_MAX_SIZE } from '../../consts/Insert';
  8. import { parseByte } from '../../utils/Format';
  9. const getStyles = makeStyles((theme: Theme) => ({
  10. tip: {
  11. color: theme.palette.milvusGrey.dark,
  12. fontWeight: 500,
  13. marginBottom: theme.spacing(1),
  14. },
  15. selectors: {
  16. '& .selectorWrapper': {
  17. display: 'flex',
  18. justifyContent: 'space-between',
  19. alignItems: 'center',
  20. marginBottom: theme.spacing(3),
  21. '& .selectLabel': {
  22. fontSize: '14px',
  23. lineHeight: '20px',
  24. color: theme.palette.milvusDark.main,
  25. },
  26. '& .divider': {
  27. width: '20px',
  28. margin: theme.spacing(0, 4),
  29. backgroundColor: theme.palette.milvusGrey.dark,
  30. },
  31. },
  32. '& .selector': {
  33. flexBasis: '40%',
  34. minWidth: '256px',
  35. },
  36. },
  37. uploadWrapper: {
  38. marginTop: theme.spacing(3),
  39. padding: theme.spacing(1),
  40. backgroundColor: '#f9f9f9',
  41. '& .text': {
  42. color: theme.palette.milvusGrey.dark,
  43. },
  44. '& .file': {
  45. marginBottom: theme.spacing(1),
  46. },
  47. '& .uploaderWrapper': {
  48. display: 'flex',
  49. alignItems: 'center',
  50. border: '1px solid #e9e9ed',
  51. borderRadius: '4px',
  52. padding: theme.spacing(1),
  53. backgroundColor: '#fff',
  54. '& .uploader': {
  55. marginRight: theme.spacing(1),
  56. },
  57. },
  58. '& .sampleWrapper': {
  59. '& .sample': {
  60. backgroundColor: '#fff',
  61. padding: theme.spacing(2),
  62. margin: theme.spacing(1, 0),
  63. },
  64. },
  65. '& .title': {
  66. marginTop: theme.spacing(1),
  67. },
  68. '& .noteList': {
  69. marginTop: theme.spacing(1),
  70. paddingLeft: theme.spacing(3),
  71. },
  72. '& .noteItem': {
  73. maxWidth: '560px',
  74. },
  75. },
  76. }));
  77. const InsertImport: FC<InsertImportProps> = ({
  78. collectionOptions,
  79. partitionOptions,
  80. selectedCollection,
  81. selectedPartition,
  82. handleCollectionChange,
  83. handlePartitionChange,
  84. handleUploadedData,
  85. handleUploadFileChange,
  86. fileName,
  87. setFileName,
  88. }) => {
  89. const { t: insertTrans } = useTranslation('insert');
  90. const { t: collectionTrans } = useTranslation('collection');
  91. const { t: partitionTrans } = useTranslation('partition');
  92. const classes = getStyles();
  93. return (
  94. <section>
  95. <Typography className={classes.tip}>
  96. {insertTrans('targetTip')}
  97. </Typography>
  98. <form className={classes.selectors}>
  99. <div className="selectorWrapper">
  100. <CustomSelector
  101. options={collectionOptions}
  102. disabled={collectionOptions.length === 0}
  103. wrapperClass="selector"
  104. labelClass="selectLabel"
  105. value={selectedCollection}
  106. variant="filled"
  107. label={collectionTrans('collection')}
  108. onChange={(e: { target: { value: unknown } }) => {
  109. const collection = e.target.value;
  110. handleCollectionChange &&
  111. handleCollectionChange(collection as string);
  112. }}
  113. />
  114. <Divider classes={{ root: 'divider' }} />
  115. <CustomSelector
  116. options={partitionOptions}
  117. disabled={partitionOptions.length === 0}
  118. wrapperClass="selector"
  119. labelClass="selectLabel"
  120. value={selectedPartition}
  121. variant="filled"
  122. label={partitionTrans('partition')}
  123. onChange={(e: { target: { value: unknown } }) => {
  124. const partition = e.target.value;
  125. handlePartitionChange(partition as string);
  126. }}
  127. />
  128. </div>
  129. </form>
  130. <div className={classes.uploadWrapper}>
  131. <Typography className="text file" variant="body1">
  132. {insertTrans('file')}
  133. </Typography>
  134. <div className="uploaderWrapper">
  135. <Uploader
  136. btnClass="uploader"
  137. label={insertTrans('uploaderLabel')}
  138. accept=".csv"
  139. // selected collection will affect schema, which is required for uploaded data validation check
  140. // so upload file should be disabled until user select one collection
  141. disabled={!selectedCollection}
  142. disableTooltip={insertTrans('uploadFileDisableTooltip')}
  143. setFileName={setFileName}
  144. handleUploadedData={handleUploadedData}
  145. maxSize={parseByte(`${INSERT_MAX_SIZE}m`)}
  146. overSizeWarning={insertTrans('overSizeWarning', {
  147. size: INSERT_MAX_SIZE,
  148. })}
  149. handleUploadFileChange={handleUploadFileChange}
  150. />
  151. <Typography className="text">
  152. {fileName || insertTrans('fileNamePlaceHolder')}
  153. </Typography>
  154. </div>
  155. <div className="sampleWrapper">
  156. <Typography variant="body2" className="text title">
  157. {insertTrans('sample')}
  158. </Typography>
  159. <pre className="sample">{INSERT_CSV_SAMPLE}</pre>
  160. </div>
  161. <Typography variant="body2" className="text title">
  162. {insertTrans('noteTitle')}
  163. </Typography>
  164. <ul className="noteList">
  165. {insertTrans('notes').map(note => (
  166. <li key={note} className="text noteItem">
  167. <Typography>{note}</Typography>
  168. </li>
  169. ))}
  170. </ul>
  171. </div>
  172. </section>
  173. );
  174. };
  175. export default InsertImport;