Skip to content

Commit d9eb041

Browse files
authored
Revert "Handle machine types with region-varying hardware [SVC-3814] (#1672)" (#1677)
This reverts commit b6f7fcc.
1 parent 1324ea6 commit d9eb041

File tree

11 files changed

+283
-1068
lines changed

11 files changed

+283
-1068
lines changed

package-lock.json

Lines changed: 44 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"knip": "knip"
4646
},
4747
"dependencies": {
48-
"@bitrise/bitkit": "^13.318.0",
48+
"@bitrise/bitkit": "^13.314.0",
4949
"@dagrejs/dagre": "^1.1.5",
5050
"@datadog/browser-rum": "^6.23.0",
5151
"@datadog/browser-rum-react": "^6.23.0",

source/javascripts/components/StacksAndMachine/MachineTypeSelector.tsx

Lines changed: 17 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
import {
2-
Avatar,
3-
Box,
4-
BoxProps,
5-
Dropdown,
6-
DropdownDetailedOption,
7-
DropdownGroup,
8-
Text,
9-
Toggletip,
10-
TypeIconName,
11-
} from '@bitrise/bitkit';
12-
import { ReactNode, useMemo } from 'react';
1+
import { Avatar, Box, Dropdown, DropdownDetailedOption, DropdownGroup, Toggletip, TypeIconName } from '@bitrise/bitkit';
2+
import { ReactNode } from 'react';
133

14-
import { MachineRegionName, MachineTypeOption, MachineTypeOptionGroup } from '@/core/models/StackAndMachine';
15-
import { doesHardwareVaryByRegion, MachineTypeWithValue } from '@/core/services/StackAndMachineService';
4+
import { MachineTypeOption, MachineTypeOptionGroup } from '@/core/models/StackAndMachine';
5+
import { MachineTypeWithValue } from '@/core/services/StackAndMachineService';
166

177
const getIconName = (osId?: string): TypeIconName | undefined => {
188
switch (osId) {
@@ -26,62 +16,34 @@ const getIconName = (osId?: string): TypeIconName | undefined => {
2616
}
2717
};
2818

29-
const renderOptions = (machineTypeOptions: MachineTypeOption[]) => {
30-
return machineTypeOptions.map(({ isDisabled, label, os, subtitle, value }) => {
31-
const iconName = getIconName(os);
32-
19+
const renderOptions = (machines: MachineTypeOption[], isDisabled?: boolean) => {
20+
return machines.map((machine) => {
21+
const iconName = getIconName(machine.os);
3322
return (
3423
<DropdownDetailedOption
35-
key={value}
36-
value={value}
37-
title={label}
38-
subtitle={subtitle}
24+
key={machine.value}
25+
value={machine.value}
26+
title={machine.label}
27+
subtitle=""
3928
isDisabled={isDisabled}
40-
icon={iconName && <Avatar variant="brand" size="32" iconName={iconName} />}
29+
icon={iconName && <Avatar variant="brand" size="24" iconName={iconName} />}
4130
/>
4231
);
4332
});
4433
};
4534

46-
const renderFormLabel = (machineTypeOption: MachineTypeOption) => {
47-
const { label, os } = machineTypeOption;
48-
const iconName = getIconName(os);
49-
50-
return (
51-
<Box display="flex" gap={12} alignItems="center">
52-
{iconName && <Avatar variant="brand" size="24" iconName={iconName} />}
53-
{label}
54-
</Box>
55-
);
56-
};
57-
58-
type Props = Pick<BoxProps, 'width'> & {
35+
type Props = {
5936
isLoading: boolean;
6037
isInvalid: boolean;
6138
isDisabled: boolean;
6239
machineType: MachineTypeWithValue;
6340
optionGroups: MachineTypeOptionGroup[];
6441
onChange: (machineId: string) => void;
65-
selectedRegion?: MachineRegionName;
6642
};
6743

68-
const MachineTypeSelector = ({
69-
isLoading,
70-
isInvalid,
71-
isDisabled,
72-
machineType,
73-
optionGroups,
74-
onChange,
75-
selectedRegion,
76-
...boxProps
77-
}: Props) => {
78-
const doesHardwareVaryByRegionForSelectedMachineType = useMemo(
79-
() => doesHardwareVaryByRegion(machineType),
80-
[machineType],
81-
);
82-
44+
const MachineTypeSelector = ({ isLoading, isInvalid, isDisabled, machineType, optionGroups, onChange }: Props) => {
8345
const toggletip = (icon: ReactNode) => {
84-
if (!optionGroups.find((group) => group.options.find((option) => option.isDisabled))) {
46+
if (!optionGroups.find((group) => group.status === 'promoted')) {
8547
return null;
8648
}
8749

@@ -97,48 +59,9 @@ const MachineTypeSelector = ({
9759
);
9860
};
9961

100-
const helperText = () => {
101-
if (doesHardwareVaryByRegionForSelectedMachineType && !selectedRegion) {
102-
return (
103-
<Box as="span" display="flex" flexDir="column" gap={8}>
104-
<Text as="span">Machine types may vary depending on high demand.</Text>
105-
{Object.entries(machineType.availableInRegions).map(([regionName, machineTypeInfoText]) => {
106-
return (
107-
<Text as="span" color="input/text/helper" key={regionName} textStyle="body/sm/regular">
108-
<Text as="span" fontWeight="bold">
109-
{regionName}:
110-
</Text>{' '}
111-
{machineTypeInfoText}
112-
</Text>
113-
);
114-
})}
115-
</Box>
116-
);
117-
}
118-
119-
const region = selectedRegion || (Object.keys(machineType.availableInRegions)[0] as MachineRegionName);
120-
121-
return (
122-
<Text as="span" color="input/text/helper" textStyle="body/sm/regular">
123-
{machineType.availableInRegions[region]}
124-
</Text>
125-
);
126-
};
127-
128-
let selectedOption: MachineTypeOption | null = null;
129-
optionGroups.find((group) => {
130-
const option = group.options.find(({ value }) => value === machineType.value);
131-
if (option) {
132-
selectedOption = option;
133-
return true;
134-
}
135-
});
136-
13762
return (
13863
<Dropdown
139-
{...boxProps}
14064
flex="1"
141-
formLabel={selectedOption && renderFormLabel(selectedOption)}
14265
required
14366
search={false}
14467
label="Machine type"
@@ -147,7 +70,7 @@ const MachineTypeSelector = ({
14770
disabled={isLoading || isDisabled}
14871
isError={isInvalid}
14972
errorText={isInvalid ? 'Invalid machine type' : undefined}
150-
helperText={helperText()}
73+
helperText={machineType.creditPerMinute ? `${machineType.creditPerMinute} credits/min` : undefined}
15174
value={machineType.value}
15275
onChange={(e) => onChange(e.target.value ?? '')}
15376
>
@@ -156,7 +79,7 @@ const MachineTypeSelector = ({
15679
<>
15780
{optionGroups.map((group) => (
15881
<DropdownGroup key={group.label} label={group.label} labelProps={{ whiteSpace: 'nowrap' }}>
159-
{renderOptions(group.options)}
82+
{renderOptions(group.options, group.status === 'promoted')}
16083
</DropdownGroup>
16184
))}
16285
</>

source/javascripts/components/StacksAndMachine/StackAndMachine.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ const StackAndMachine = ({
118118
}
119119
isRollbackVersionAvailable={!!availableRollbackVersion}
120120
useRollbackVersion={useRollbackVersion}
121-
width={orientation === 'horizontal' ? '50%' : undefined}
122121
/>
123122
<MachineTypeSelector
124123
machineType={selectedMachineType}
@@ -127,8 +126,6 @@ const StackAndMachine = ({
127126
isDisabled={isMachineTypeSelectionDisabled}
128127
optionGroups={machineOptionGroups}
129128
onChange={(selectedMachineTypeValue) => handleChange(selectedStack.value, selectedMachineTypeValue)}
130-
selectedRegion={data?.region}
131-
width={orientation === 'horizontal' ? '50%' : undefined}
132129
/>
133130
</Box>
134131
{useRollbackVersion && (

source/javascripts/components/StacksAndMachine/StackSelector.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Avatar,
33
Box,
4-
BoxProps,
54
Checkbox,
65
Dropdown,
76
DropdownDetailedOption,
@@ -70,13 +69,13 @@ const renderOptions = (stacks: StackOption[]) => {
7069
value={stack.value}
7170
title={stack.label}
7271
subtitle=""
73-
icon={iconName && <Avatar variant="brand" size="32" iconName={iconName} />}
72+
icon={iconName && <Avatar variant="brand" size="24" iconName={iconName} />}
7473
/>
7574
);
7675
});
7776
};
7877

79-
type Props = Pick<BoxProps, 'width'> & {
78+
type Props = {
8079
isLoading: boolean;
8180
isInvalid: boolean;
8281
isRollbackVersionAvailable: boolean;
@@ -94,10 +93,9 @@ const StackSelector = ({
9493
stack,
9594
optionGroups,
9695
onChange,
97-
...boxProps
9896
}: Props) => {
9997
return (
100-
<Box {...boxProps} flex="1">
98+
<Box flex="1">
10199
<Dropdown
102100
required
103101
search={false}

0 commit comments

Comments
 (0)