AssessmentStore.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 = false;
  23. @observable migrations: MigrationItem[] = [];
  24. @action updateSelectedEndpoint(endpoint: Endpoint) {
  25. this.selectedEndpoint = endpoint;
  26. }
  27. @action updateSelectedResourceGroup(
  28. resourceGroup: Assessment["group"] | null
  29. ) {
  30. this.selectedResourceGroup = resourceGroup;
  31. }
  32. @action async migrate(data: MigrationInfo): Promise<void> {
  33. this.migrating = true;
  34. this.migrations = [];
  35. const separateVm = data.fieldValues.separate_vm;
  36. if (separateVm) {
  37. try {
  38. const items = await AssessmentSource.migrateMultiple(data);
  39. this.migrating = false;
  40. this.migrations = items;
  41. } catch (e) {
  42. this.migrating = false;
  43. }
  44. }
  45. try {
  46. const item = await AssessmentSource.migrate(data);
  47. this.migrating = false;
  48. this.migrations = [item];
  49. } catch (e) {
  50. this.migrating = false;
  51. }
  52. }
  53. @action clearSelection() {
  54. this.selectedEndpoint = null;
  55. this.selectedResourceGroup = null;
  56. }
  57. }
  58. export default new AssessmentStore();