From 7781ce8ce705da36bc959cde40403b4f759ce17f Mon Sep 17 00:00:00 2001 From: Dmitrii Chechetkin Date: Tue, 28 May 2024 11:38:38 -0400 Subject: [PATCH 1/3] Fixes logins --- build.gradle.kts | 2 +- .../intellij/tree/iq/CapellaOrganizationList.java | 2 -- .../com/couchbase/intellij/tree/iq/IQWindowContent.java | 4 +++- .../intellij/tree/iq/ui/MessageGroupComponent.java | 8 +++++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e7f4d9e0..a08850f9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -80,7 +80,7 @@ tasks { } patchPluginXml { - sinceBuild.set("233.*") + sinceBuild.set("232.10227.8") untilBuild.set("246.*") } diff --git a/src/main/java/com/couchbase/intellij/tree/iq/CapellaOrganizationList.java b/src/main/java/com/couchbase/intellij/tree/iq/CapellaOrganizationList.java index a9e5480b..9ab71b10 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/CapellaOrganizationList.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/CapellaOrganizationList.java @@ -25,8 +25,6 @@ public CapellaOrganizationList getOnlyIqEnabledOrgs() { .filter(org -> org.getData() != null) .filter(org -> org.getData().getIq() != null) .filter(org -> org.getData().getIq().isEnabled()) - .filter(org -> org.getData().getIq().getOther() != null) - .filter(org -> org.getData().getIq().getOther().getIsTermsAcceptedForOrg()) .collect(Collectors.toList()) ); return filteredList; diff --git a/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java b/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java index 5fab4e2b..240e6923 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java @@ -143,7 +143,9 @@ public void onOrgSelected(CapellaOrganization organization) { if (!credentials.checkIqIsEnabled(organization.getId())) { Notifications.Bus.notify(new Notification(ChatGptBundle.message("group.id"), "Unable to use this organization", "Capella iQ is not enabled for this organization.", NotificationType.ERROR)); - onLogout(null); + if (chatPanel == null) { + onLogout(null); + } return; } diff --git a/src/main/java/com/couchbase/intellij/tree/iq/ui/MessageGroupComponent.java b/src/main/java/com/couchbase/intellij/tree/iq/ui/MessageGroupComponent.java index 83b56072..45ec7c75 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/ui/MessageGroupComponent.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/ui/MessageGroupComponent.java @@ -39,6 +39,7 @@ import java.util.Comparator; import java.util.List; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; import static com.couchbase.intellij.workbench.CustomSqlFileEditor.NO_QUERY_CONTEXT_SELECTED; @@ -204,10 +205,11 @@ public void actionPerformed(@NotNull AnActionEvent e) { private JPanel createSettingsPanel(CapellaOrganizationList organizationList, ChatPanel.LogoutListener logoutListener) { JPanel panel = new NonOpaquePanel(new GridLayout(0, 1)); JPanel orgPanel = new NonOpaquePanel(new BorderLayout()); + + orgSelector = new ComboBox<>(organizationList.getData().stream() - .map(org -> org.getData()) - .filter(data -> data.getIq() != null && data.getIq().isEnabled()) - .map(data -> data.getName()) + .map(CapellaOrganizationList.Entry::getData) + .map(CapellaOrganization::getName) .toArray(String[]::new)); orgSelector.setSelectedIndex(organizationList.indexOf(organization)); From 3ea707f41205c6c7233ab6bca800033181e08f1e Mon Sep 17 00:00:00 2001 From: Dmitrii Chechetkin Date: Tue, 28 May 2024 12:09:20 -0400 Subject: [PATCH 2/3] fixes logins when no org previously selected --- .../java/com/couchbase/intellij/tree/iq/IQWindowContent.java | 2 +- .../intellij/tree/iq/ui/view/CapellaOrgSelectorView.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java b/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java index 240e6923..25024e3b 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/IQWindowContent.java @@ -87,7 +87,7 @@ public void onLogin(IQCredentials credentials) { this.credentials = credentials; this.removeAll(); try { - this.organizationList = credentials.getOrganizations(); + this.organizationList = credentials.getOrganizations().getOnlyIqEnabledOrgs(); if (organizationList.getData().isEmpty()) { Notifications.Bus.notify(new Notification(ChatGptBundle.message("group.id"), "No Capella organizations found", "At least one organization is required to use Couchbase IQ. No organizations found.", NotificationType.ERROR)); onLogout(null); diff --git a/src/main/java/com/couchbase/intellij/tree/iq/ui/view/CapellaOrgSelectorView.java b/src/main/java/com/couchbase/intellij/tree/iq/ui/view/CapellaOrgSelectorView.java index 21319823..536df1f8 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/ui/view/CapellaOrgSelectorView.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/ui/view/CapellaOrgSelectorView.java @@ -28,7 +28,6 @@ public CapellaOrgSelectorView(CapellaOrganizationList organizationList, ChatPane add(new JLabel(SELECT_ORG_LABEL), gbc); ComboBox orgSelector = new ComboBox<>(organizationList.getData().stream() .map(org -> org.getData()) - .filter(data -> data.getIq() != null && data.getIq().isEnabled()) .map(data -> String.format("%s%s", data.getName(), !data.getIq().getOther().getIsTermsAcceptedForOrg() ? " (*)" : "")) .toArray(String[]::new)); From 1b76d7742b15a9d99f6f996978da972f600c6360 Mon Sep 17 00:00:00 2001 From: Dmitrii Chechetkin Date: Tue, 28 May 2024 12:23:45 -0400 Subject: [PATCH 3/3] bumps version and adresses slow operation on EDT --- build.gradle.kts | 2 +- .../intellij/tree/iq/settings/OpenAISettingsState.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a08850f9..07202e4e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "com.couchbase" -version = "1.1.1" +version = "1.1.2" java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 diff --git a/src/main/java/com/couchbase/intellij/tree/iq/settings/OpenAISettingsState.java b/src/main/java/com/couchbase/intellij/tree/iq/settings/OpenAISettingsState.java index 68d1467d..4394144b 100644 --- a/src/main/java/com/couchbase/intellij/tree/iq/settings/OpenAISettingsState.java +++ b/src/main/java/com/couchbase/intellij/tree/iq/settings/OpenAISettingsState.java @@ -151,9 +151,11 @@ public String getApiKey() { } public void setApiKey(String apiKey) { - var credentialAttributes = createCredentialAttributes(getModelPage()); - PasswordSafe.getInstance().setPassword(credentialAttributes, apiKey); - setApiKeyMasked(maskText(apiKey)); + ApplicationManager.getApplication().executeOnPooledThread(() -> { + var credentialAttributes = createCredentialAttributes(getModelPage()); + PasswordSafe.getInstance().setPassword(credentialAttributes, apiKey); + setApiKeyMasked(maskText(apiKey)); + }); } private static String maskText(String text) {