Skip to content

Commit 96f88c2

Browse files
Merge pull request #6968 from microsoft/hanli-fixes-202209
Resolve issues in end game tests
2 parents 81db5c4 + a1d2a38 commit 96f88c2

File tree

3 files changed

+48
-49
lines changed

3 files changed

+48
-49
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/FunctionDeploymentSettingEditor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.microsoft.azure.toolkit.intellij.legacy.function.runner.deploy.ui.FunctionDeploymentPanel;
1313
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
1414
import org.jetbrains.annotations.NotNull;
15+
import reactor.core.scheduler.Schedulers;
1516

1617
import java.util.Objects;
1718

@@ -33,6 +34,7 @@ protected void applyEditorTo(@NotNull FunctionDeployConfiguration conf) throws C
3334
.filter(i -> !i.isValid())
3435
.findAny().orElse(null);
3536
if (Objects.nonNull(error)) {
37+
mainPanel.validateAllInputsAsync().subscribeOn(Schedulers.boundedElastic()).subscribe(ignore -> this.fireEditorStateChanged());
3638
final String message = error.getType() == AzureValidationInfo.Type.PENDING ? "Validating..." : error.getMessage();
3739
throw new ConfigurationException(message);
3840
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/ui/FunctionDeploymentPanel.form

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="27dc6" binding="pnlRoot" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="604" height="220"/>
6+
<xy x="20" y="20" width="604" height="133"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -53,18 +53,6 @@
5353
<text value="Module: "/>
5454
</properties>
5555
</component>
56-
<component id="56e9e" class="javax.swing.JLabel" binding="lblDeploymentSlot">
57-
<constraints>
58-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
59-
<minimum-size width="-1" height="24"/>
60-
<preferred-size width="-1" height="24"/>
61-
<maximum-size width="-1" height="24"/>
62-
</grid>
63-
</constraints>
64-
<properties>
65-
<text value="Deployment Slot:"/>
66-
</properties>
67-
</component>
6856
<component id="760ca" class="com.microsoft.azure.toolkit.intellij.legacy.function.FunctionAppComboBox" binding="functionAppComboBox" custom-create="true">
6957
<constraints>
7058
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
@@ -73,29 +61,29 @@
7361
</component>
7462
<component id="35551" class="com.microsoft.azure.toolkit.intellij.legacy.function.runner.deploy.ui.components.DeploymentSlotComboBox" binding="cbDeploymentSlot" custom-create="true">
7563
<constraints>
76-
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
64+
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
7765
</constraints>
7866
<properties>
7967
<visible value="true"/>
8068
</properties>
8169
</component>
70+
<component id="2bbdf" class="javax.swing.JComboBox" binding="cbFunctionModule">
71+
<constraints>
72+
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
73+
</constraints>
74+
<properties/>
75+
</component>
8276
<component id="60952" class="javax.swing.JCheckBox" binding="chkSlot">
8377
<constraints>
84-
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
78+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
8579
</constraints>
8680
<properties>
8781
<contentAreaFilled value="true"/>
8882
<hideActionText value="false"/>
8983
<horizontalTextPosition value="4"/>
90-
<text value="Deploy To Slot"/>
84+
<text value="Deploy to Slot:"/>
9185
</properties>
9286
</component>
93-
<component id="2bbdf" class="javax.swing.JComboBox" binding="cbFunctionModule">
94-
<constraints>
95-
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
96-
</constraints>
97-
<properties/>
98-
</component>
9987
</children>
10088
</grid>
10189
</form>

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/ui/FunctionDeploymentPanel.java

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.intellij.ui.ListCellRendererWrapper;
1515
import com.microsoft.azure.toolkit.ide.appservice.function.FunctionAppConfig;
1616
import com.microsoft.azure.toolkit.ide.appservice.model.DeploymentSlotConfig;
17+
import com.microsoft.azure.toolkit.intellij.common.AzureFormPanel;
1718
import com.microsoft.azure.toolkit.intellij.legacy.common.AzureSettingPanel;
1819
import com.microsoft.azure.toolkit.intellij.legacy.function.FunctionAppComboBox;
1920
import com.microsoft.azure.toolkit.intellij.legacy.function.runner.component.table.FunctionAppSettingsTable;
@@ -24,36 +25,31 @@
2425
import com.microsoft.azure.toolkit.lib.Azure;
2526
import com.microsoft.azure.toolkit.lib.appservice.AppServiceAppBase;
2627
import com.microsoft.azure.toolkit.lib.appservice.function.AzureFunctions;
27-
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp;
28-
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppBase;
2928
import com.microsoft.azure.toolkit.lib.common.form.AzureFormInput;
30-
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
3129
import com.microsoft.azure.toolkit.lib.common.model.AbstractAzResource;
3230
import com.microsoft.azure.toolkit.lib.common.task.AzureTask;
3331
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
3432
import org.apache.commons.collections.MapUtils;
33+
import org.apache.commons.lang3.ObjectUtils;
3534
import org.apache.commons.lang3.StringUtils;
3635
import org.jetbrains.annotations.NotNull;
3736
import org.jetbrains.annotations.Nullable;
3837
import org.jetbrains.idea.maven.project.MavenProject;
3938

4039
import javax.annotation.Nonnull;
4140
import javax.swing.*;
42-
import java.awt.event.ItemEvent;
4341
import java.nio.file.Paths;
4442
import java.util.Arrays;
4543
import java.util.Collections;
4644
import java.util.List;
47-
import java.util.Map;
4845
import java.util.Objects;
4946
import java.util.Optional;
5047
import java.util.UUID;
51-
import java.util.stream.Collectors;
5248

5349
import static com.microsoft.azure.toolkit.intellij.common.AzureBundle.message;
5450

5551

56-
public class FunctionDeploymentPanel extends AzureSettingPanel<FunctionDeployConfiguration> {
52+
public class FunctionDeploymentPanel extends AzureSettingPanel<FunctionDeployConfiguration> implements AzureFormPanel<FunctionDeployConfiguration> {
5753

5854
private JPanel pnlRoot;
5955
private HyperlinkLabel lblCreateFunctionApp;
@@ -65,14 +61,15 @@ public class FunctionDeploymentPanel extends AzureSettingPanel<FunctionDeployCon
6561
private JLabel lblAppSettings;
6662
private JCheckBox chkSlot;
6763
private DeploymentSlotComboBox cbDeploymentSlot;
68-
private JLabel lblDeploymentSlot;
6964
private FunctionAppSettingsTable appSettingsTable;
7065
private String appSettingsKey;
7166
private String appSettingsResourceId;
7267
private Module previousModule = null;
68+
private final FunctionDeployConfiguration configuration;
7369

7470
public FunctionDeploymentPanel(@NotNull Project project, @NotNull FunctionDeployConfiguration functionDeployConfiguration) {
7571
super(project);
72+
this.configuration = functionDeployConfiguration;
7673
this.appSettingsKey = StringUtils.firstNonBlank(functionDeployConfiguration.getAppSettingsKey(), UUID.randomUUID().toString());
7774
$$$setupUI$$$();
7875

@@ -86,11 +83,12 @@ public void customize(JList list, Module module, int i, boolean b, boolean b1) {
8683
}
8784
});
8885
functionAppComboBox.setRequired(true);
89-
chkSlot.addItemListener(e -> onSelectSlot());
86+
chkSlot.addItemListener(e -> onSlotCheckBoxChanged());
9087

9188
lblModule.setLabelFor(cbFunctionModule);
9289
lblFunction.setLabelFor(functionAppComboBox);
9390
lblAppSettings.setLabelFor(appSettingsTable);
91+
final JLabel lblDeploymentSlot = new JLabel("Deployment Slot:");
9492
lblDeploymentSlot.setLabelFor(cbDeploymentSlot);
9593
fillModules();
9694
}
@@ -202,24 +200,23 @@ private void onSelectFunctionApp(final FunctionAppConfig value) {
202200
return;
203201
}
204202
// disable slot for draft function
203+
this.chkSlot.setEnabled(StringUtils.isNotEmpty(value.getResourceId()));
205204
if (StringUtils.isEmpty(value.getResourceId())) {
206205
this.chkSlot.setSelected(false);
207206
}
208-
this.chkSlot.setEnabled(StringUtils.isNotEmpty(value.getResourceId()));
209-
this.toggleDeploymentSlot(chkSlot.isSelected());
210207
this.cbDeploymentSlot.setAppService(value.getResourceId());
211208
if (!this.chkSlot.isSelected()) {
212209
loadAppSettings(getResourceId(value, null));
213210
}
214211
}
215212

216-
private void loadAppSettings(@Nonnull final String resourceId) {
213+
private void loadAppSettings(@Nullable final String resourceId) {
217214
if (StringUtils.equalsIgnoreCase(resourceId, this.appSettingsResourceId) && MapUtils.isNotEmpty(this.appSettingsTable.getAppSettings())) {
218215
return;
219216
}
220217
this.appSettingsResourceId = resourceId;
221218
this.appSettingsTable.loadAppSettings(() -> {
222-
final AbstractAzResource<?, ?, ?> resource = Azure.az().getById(resourceId);
219+
final AbstractAzResource<?, ?, ?> resource = StringUtils.isBlank(resourceId) ? null : Azure.az().getById(resourceId);
223220
return resource instanceof AppServiceAppBase<?, ?, ?> ? ((AppServiceAppBase<?, ?, ?>) resource).getAppSettings() : Collections.emptyMap();
224221
});
225222
}
@@ -247,10 +244,14 @@ private void selectModule(final Module target) {
247244
}
248245
}
249246

250-
private void onSelectSlot() {
247+
private void onSlotCheckBoxChanged() {
251248
toggleDeploymentSlot(chkSlot.isSelected());
252-
if (!chkSlot.isSelected() && functionAppComboBox.getValue() != null) {
253-
// reload app settings for function app
249+
final FunctionAppConfig function = functionAppComboBox.getValue();
250+
final DeploymentSlotConfig slot = cbDeploymentSlot.getValue();
251+
// reload app settings when switch slot configuration
252+
if (chkSlot.isSelected() && ObjectUtils.allNotNull(function, slot)) {
253+
loadAppSettings(getResourceId(functionAppComboBox.getValue(), slot));
254+
} else if (!chkSlot.isSelected() && Objects.nonNull(function)) {
254255
loadAppSettings(getResourceId(functionAppComboBox.getValue(), null));
255256
}
256257
}
@@ -261,24 +262,32 @@ private void toggleDeploymentSlot(boolean isDeployToSlot) {
261262
cbDeploymentSlot.validateValueAsync();
262263
}
263264

264-
// todo: @hanli migrate to AzureFormInput
265-
public List<AzureValidationInfo> getAllValidationInfos(final boolean revalidateIfNone) {
266-
final List<AzureFormInput<?>> inputs = Arrays.asList(functionAppComboBox, cbDeploymentSlot);
267-
return inputs.stream()
268-
.map(input -> input.getValidationInfo(revalidateIfNone))
269-
.filter(Objects::nonNull).collect(Collectors.toList());
265+
@Override
266+
public void setValue(FunctionDeployConfiguration data) {
267+
resetFromConfig(data);
268+
}
269+
270+
@Override
271+
public FunctionDeployConfiguration getValue() {
272+
final FunctionDeployConfiguration result = new FunctionDeployConfiguration(configuration.getProject(), configuration.getFactory(), configuration.getName());
273+
apply(result);
274+
return result;
270275
}
271276

277+
@Override
278+
public List<AzureFormInput<?>> getInputs() {
279+
return Arrays.asList(functionAppComboBox, cbDeploymentSlot);
280+
}
281+
282+
@Nullable
272283
private String getResourceId(@Nonnull FunctionAppConfig config, @Nullable DeploymentSlotConfig slotConfig) {
273284
if (Objects.isNull(slotConfig)) {
274285
return StringUtils.isNoneBlank(config.getResourceId()) ? config.getResourceId() :
275286
Azure.az(AzureFunctions.class).functionApps(config.getSubscriptionId()).getOrTemp(config.getName(), config.getResourceGroupName()).getId();
276287
} else {
277-
return Azure.az(AzureFunctions.class).functionApp(config.getResourceId()).slots().getOrTemp(slotConfig.getName(), null).getId();
288+
return Optional.ofNullable(Azure.az(AzureFunctions.class).functionApp(config.getResourceId()))
289+
.map(func -> func.slots().getOrTemp(slotConfig.getName(), null).getId())
290+
.orElse(null);
278291
}
279292
}
280-
281-
// CHECKSTYLE IGNORE check FOR NEXT 1 LINES
282-
void $$$setupUI$$$() {
283-
}
284293
}

0 commit comments

Comments
 (0)