Skip to content

Commit f62edbc

Browse files
cbourgoisjleveugle
authored andcommitted
feat: add instance creation (#390)
1 parent 255295e commit f62edbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1003
-2994
lines changed

packages/manager/modules/pci/src/components/project/flavors-list/flavor-group.class.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,40 @@ import find from 'lodash/find';
22
import map from 'lodash/map';
33
import omit from 'lodash/omit';
44
import union from 'lodash/union';
5+
import uniq from 'lodash/uniq';
56

67
import { DEFAULT_OS } from './flavors-list.constants';
78

89
export default class FlavorGroup {
910
constructor(flavors) {
1011
Object.assign(this, omit(find(flavors, { osType: DEFAULT_OS }), [
11-
'region', 'id', 'osType', 'planCodes',
12+
'regions', 'id', 'osType', 'planCodes',
1213
]));
13-
this.availableRegions = union(...map(flavors, 'regions'));
14+
15+
this.availableRegions = uniq(
16+
map(
17+
union(
18+
...map(flavors, 'regions'),
19+
),
20+
'region',
21+
),
22+
);
1423
this.flavors = flavors;
1524
}
1625

1726
isAvailableInRegion(region) {
1827
return this.availableRegions.includes(region);
1928
}
29+
30+
getFlavorByOsType(osType) {
31+
return find(this.flavors, { osType });
32+
}
33+
34+
getFlavorId(osType, region) {
35+
const flavor = this.getFlavorByOsType(osType);
36+
if (flavor) {
37+
return flavor.getIdByRegion(region);
38+
}
39+
return false;
40+
}
2041
}

packages/manager/modules/pci/src/components/project/flavors-list/flavor.class.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import find from 'lodash/find';
2+
import get from 'lodash/get';
3+
14
import { FLEX_TYPE, LEGACY_FLAVORS, SSD_DISK_TYPES } from './flavors-list.constants';
25

36
export default class Flavors {
@@ -26,4 +29,8 @@ export default class Flavors {
2629
hasSsdDisk() {
2730
return this.diskType === 'ssd';
2831
}
32+
33+
getIdByRegion(region) {
34+
return get(find(this.regions, { region }), 'id');
35+
}
2936
}

packages/manager/modules/pci/src/components/project/flavors-list/flavors-list.service.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import filter from 'lodash/filter';
22
import groupBy from 'lodash/groupBy';
33
import map from 'lodash/map';
44
import mapValues from 'lodash/mapValues';
5+
import omit from 'lodash/omit';
56

67
import Flavor from './flavor.class';
78
import FlavorGroup from './flavor-group.class';
@@ -27,10 +28,10 @@ export default class FlavorsList {
2728
})
2829
.then(({ flavors, prices }) => map(
2930
groupBy(flavors, 'name'),
30-
flavor => new Flavor({
31-
...flavor[0],
32-
prices: mapValues(flavor[0].planCodes, planCode => prices[planCode].price),
33-
regions: map(flavor, 'region'),
31+
groupedFlavors => new Flavor({
32+
...omit(groupedFlavors[0], ['id', 'region']),
33+
prices: mapValues(groupedFlavors[0].planCodes, planCode => prices[planCode].price),
34+
regions: map(groupedFlavors, ({ id, region }) => ({ id, region })),
3435
}),
3536
));
3637
}
2.89 KB
Loading
2.46 KB
Loading
1.62 KB
Loading
1.66 KB
Loading
4.52 KB
Loading
79.8 KB
Loading
2.92 KB
Loading

0 commit comments

Comments
 (0)