AssessmentStore.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import { observable, action } from 'mobx'
  15. import AssessmentSource from '@src/sources/AssessmentSource'
  16. import type { Endpoint } from '@src/@types/Endpoint'
  17. import type { Assessment, MigrationInfo } from '@src/@types/Assessment'
  18. import { MigrationItem } from '@src/@types/MainItem'
  19. class AssessmentStore {
  20. @observable selectedEndpoint: Endpoint | null = null
  21. @observable selectedResourceGroup: Assessment['group'] | null = null
  22. @observable migrating: boolean = false
  23. @observable migrations: MigrationItem[] = []
  24. @action updateSelectedEndpoint(endpoint: Endpoint) {
  25. this.selectedEndpoint = endpoint
  26. }
  27. @action updateSelectedResourceGroup(resourceGroup: Assessment['group'] | null) {
  28. this.selectedResourceGroup = resourceGroup
  29. }
  30. @action async migrate(data: MigrationInfo): Promise<void> {
  31. this.migrating = true
  32. this.migrations = []
  33. const separateVm = data.fieldValues.separate_vm
  34. if (separateVm) {
  35. try {
  36. const items = await AssessmentSource.migrateMultiple(data)
  37. this.migrating = false
  38. this.migrations = items
  39. } catch (e) {
  40. this.migrating = false
  41. }
  42. }
  43. try {
  44. const item = await AssessmentSource.migrate(data)
  45. this.migrating = false
  46. this.migrations = [item]
  47. } catch (e) {
  48. this.migrating = false
  49. }
  50. }
  51. @action clearSelection() {
  52. this.selectedEndpoint = null
  53. this.selectedResourceGroup = null
  54. }
  55. }
  56. export default new AssessmentStore()