function storageValidate()

in frontend/src/old-pages/Configure/Storage.tsx [92:173]


function storageValidate() {
  const storages: Storages = getState(storagePath)
  let valid = true

  if (storages) {
    storages.forEach((storage: Storage, index: number) => {
      const settings = `${storage.StorageType}Settings`
      //TODO Add idType as an attribute within STORAGE_TYPE_PROPS to avoid nested ternary operations.
      const idType = STORAGE_TYPE_PROPS[storage.StorageType].mountFilesystem
        ? 'FileSystemId'
        : storage.StorageType == 'FileCache'
        ? 'FileCacheId'
        : 'VolumeId'
      const useExisting =
        getState(['app', 'wizard', 'storage', 'ui', index, 'useExisting']) ||
        !(STORAGE_TYPE_PROPS[storage.StorageType].maxToCreate > 0)

      if (useExisting) {
        const [externalFsValid, error] = validateExternalFileSystem(storage)
        if (!externalFsValid) {
          const errorMessage = i18next.t(externalFsErrorsMapping[error!])
          setState([...errorsPath, index, settings, idType], errorMessage)
          valid = false
        } else {
          clearState([...errorsPath, index, settings, idType])
        }
      } else {
        if (storage.StorageType === 'Ebs') {
          const [ebsValid, error] = validateEbs(storage as EbsStorage)
          if (!ebsValid) {
            const errorMessage = i18next.t(ebsErrorsMapping[error!])
            setState(
              [...errorsPath, index, 'EbsSettings', 'Size'],
              errorMessage,
            )
            valid = false
          } else {
            clearState([...errorsPath, index, 'EbsSettings', 'Size'])
          }
        }
        if (storage.StorageType === 'Efs') {
          const [efsValid, error] = validateEfs(storage as EfsStorage)
          if (!efsValid) {
            const errorMessage = i18next.t(efsErrorsMapping[error!])
            setState(
              [...errorsPath, index, 'EfsSettings', 'ProvisionedThroughput'],
              errorMessage,
            )
            valid = false
          } else {
            clearState([
              ...errorsPath,
              index,
              'EfsSettings',
              'ProvisionedThroughput',
            ])
          }
        }
      }

      const name = getState([...storagePath, index, 'Name'])
      const [nameValid, error] = validateStorageName(name)
      if (!nameValid) {
        let errorMessage: string
        if (error === 'max_length') {
          errorMessage = i18next.t(storageNameErrorsMapping[error], {
            maxChars: STORAGE_NAME_MAX_LENGTH,
          })
        } else {
          errorMessage = i18next.t(storageNameErrorsMapping[error!])
        }
        setState([...errorsPath, index, 'Name'], errorMessage)
        valid = false
      } else {
        clearState([...errorsPath, index, 'Name'])
      }
    })
  }

  setState([...errorsPath, 'validated'], true)
  return valid
}