GcsSetting.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { useTranslation } from 'next-i18next';
  2. export type GcsSettingMoleculeProps = {
  3. gcsReferenceFileWithRelayMode
  4. gcsUseOnlyEnvVars
  5. gcsApiKeyJsonPath
  6. gcsBucket
  7. gcsUploadNamespace
  8. envGcsApiKeyJsonPath?
  9. envGcsBucket?
  10. envGcsUploadNamespace?
  11. onChangeGcsReferenceFileWithRelayMode: (val: boolean) => void
  12. onChangeGcsApiKeyJsonPath: (val: string) => void
  13. onChangeGcsBucket: (val: string) => void
  14. onChangeGcsUploadNamespace: (val: string) => void
  15. };
  16. export const GcsSettingMolecule = (props: GcsSettingMoleculeProps): JSX.Element => {
  17. const { t } = useTranslation();
  18. const {
  19. gcsReferenceFileWithRelayMode,
  20. gcsUseOnlyEnvVars,
  21. gcsApiKeyJsonPath,
  22. envGcsApiKeyJsonPath,
  23. gcsBucket,
  24. envGcsBucket,
  25. gcsUploadNamespace,
  26. envGcsUploadNamespace,
  27. } = props;
  28. return (
  29. <>
  30. <div className="row my-3">
  31. <label className="text-start text-md-end col-md-3 col-form-label">
  32. {t('admin:app_setting.file_delivery_method')}
  33. </label>
  34. <div className="col-md-6">
  35. <div className="dropdown">
  36. <button
  37. className="btn btn-outline-secondary dropdown-toggle"
  38. type="button"
  39. id="ddGcsReferenceFileWithRelayMode"
  40. data-bs-toggle="dropdown"
  41. aria-haspopup="true"
  42. aria-expanded="true"
  43. >
  44. {gcsReferenceFileWithRelayMode && t('admin:app_setting.file_delivery_method_relay')}
  45. {!gcsReferenceFileWithRelayMode && t('admin:app_setting.file_delivery_method_redirect')}
  46. </button>
  47. <div className="dropdown-menu" aria-labelledby="ddGcsReferenceFileWithRelayMode">
  48. <button
  49. className="dropdown-item"
  50. type="button"
  51. onClick={() => { props?.onChangeGcsReferenceFileWithRelayMode(true) }}
  52. >
  53. {t('admin:app_setting.file_delivery_method_relay')}
  54. </button>
  55. <button
  56. className="dropdown-item"
  57. type="button"
  58. onClick={() => { props?.onChangeGcsReferenceFileWithRelayMode(false) }}
  59. >
  60. { t('admin:app_setting.file_delivery_method_redirect')}
  61. </button>
  62. </div>
  63. <p className="form-text text-muted small">
  64. {t('admin:app_setting.file_delivery_method_redirect_info')}
  65. <br />
  66. {t('admin:app_setting.file_delivery_method_relay_info')}
  67. </p>
  68. </div>
  69. </div>
  70. </div>
  71. {gcsUseOnlyEnvVars && (
  72. <p
  73. className="alert alert-info"
  74. // eslint-disable-next-line react/no-danger
  75. dangerouslySetInnerHTML={{ __html: t('admin:app_setting.note_for_the_only_env_option', { env: 'GCS_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS' }) }}
  76. />
  77. )}
  78. <table className={`table settings-table ${gcsUseOnlyEnvVars && 'use-only-env-vars'}`}>
  79. <colgroup>
  80. <col className="item-name" />
  81. <col className="from-db" />
  82. <col className="from-env-vars" />
  83. </colgroup>
  84. <thead>
  85. <tr>
  86. <th></th>
  87. <th>Database</th>
  88. <th>Environment variables</th>
  89. </tr>
  90. </thead>
  91. <tbody>
  92. <tr>
  93. <th>Api Key Json Path</th>
  94. <td>
  95. <input
  96. className="form-control"
  97. type="text"
  98. name="gcsApiKeyJsonPath"
  99. readOnly={gcsUseOnlyEnvVars}
  100. defaultValue={gcsApiKeyJsonPath}
  101. onChange={e => props?.onChangeGcsApiKeyJsonPath(e.target.value)}
  102. />
  103. </td>
  104. <td>
  105. <input className="form-control" type="text" value={envGcsApiKeyJsonPath || ''} readOnly tabIndex={-1} />
  106. <p className="form-text text-muted">
  107. {/* eslint-disable-next-line react/no-danger */}
  108. <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_API_KEY_JSON_PATH' }) }} />
  109. </p>
  110. </td>
  111. </tr>
  112. <tr>
  113. <th>{t('admin:app_setting.bucket_name')}</th>
  114. <td>
  115. <input
  116. className="form-control"
  117. type="text"
  118. name="gcsBucket"
  119. readOnly={gcsUseOnlyEnvVars}
  120. defaultValue={gcsBucket}
  121. onChange={e => props?.onChangeGcsBucket(e.target.value)}
  122. />
  123. </td>
  124. <td>
  125. <input className="form-control" type="text" value={envGcsBucket || ''} readOnly tabIndex={-1} />
  126. <p className="form-text text-muted">
  127. {/* eslint-disable-next-line react/no-danger */}
  128. <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_BUCKET' }) }} />
  129. </p>
  130. </td>
  131. </tr>
  132. <tr>
  133. <th>Name Space</th>
  134. <td>
  135. <input
  136. className="form-control"
  137. type="text"
  138. name="gcsUploadNamespace"
  139. readOnly={gcsUseOnlyEnvVars}
  140. defaultValue={gcsUploadNamespace}
  141. onChange={e => props?.onChangeGcsUploadNamespace(e.target.value)}
  142. />
  143. </td>
  144. <td>
  145. <input className="form-control" type="text" value={envGcsUploadNamespace || ''} readOnly tabIndex={-1} />
  146. <p className="form-text text-muted">
  147. {/* eslint-disable-next-line react/no-danger */}
  148. <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_UPLOAD_NAMESPACE' }) }} />
  149. </p>
  150. </td>
  151. </tr>
  152. </tbody>
  153. </table>
  154. </>
  155. );
  156. };