Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Fix if stream is unavailable (#7)
Browse files Browse the repository at this point in the history
* update if stream is not available

* updating CHANGELOG and version
  • Loading branch information
InTheCloudDan authored Dec 17, 2020
1 parent f1e9fb4 commit 1f09856
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 39 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

# intellij-plugin-ld Changelog

## [0.1.11-alpha]
### Fixed
- Handling stream connection not being available

### Changed
- Icons for Toggle State have been updated
- DocumentationProvider should work for all languages now, not just JVM

## [0.1.10-alpha]
### Removed
- External Documentation override
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -> https://www.jetbrains.org/intellij/sdk/docs/reference_guide/intellij_artifacts.html
pluginGroup=com.github.intheclouddan.intellijpluginld
pluginName=intellij-plugin-ld
pluginVersion=0.1.10-alpha
pluginVersion=0.1.11-alpha
pluginSinceBuild=201
pluginUntilBuild=203.*
platformType=IC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.github.intheclouddan.intellijpluginld

import com.github.intheclouddan.intellijpluginld.featurestore.FlagConfiguration
import com.github.intheclouddan.intellijpluginld.settings.LaunchDarklyMergedSettings
import com.intellij.lang.documentation.AbstractDocumentationProvider
import com.intellij.lang.documentation.DocumentationProvider
import com.intellij.openapi.components.service
import com.intellij.psi.PsiElement
import com.launchdarkly.api.model.FeatureFlag

class LDDocumentationProvider : AbstractDocumentationProvider() {
class LDDocumentationProvider : DocumentationProvider {

override fun generateDoc(element: PsiElement?, originalElement: PsiElement?): String? {
if (element == null) {
Expand All @@ -17,8 +17,10 @@ class LDDocumentationProvider : AbstractDocumentationProvider() {
val settings = LaunchDarklyMergedSettings.getInstance(element.project)

val flag: FeatureFlag? = getFlags.flags.items.find { it.key == element.text.drop(1).dropLast(1) }
// TODO: gracefully handle API call working and Datastore being unavailable
if (flag != null) {
val env: FlagConfiguration = getFlags.flagConfigs[element.text.drop(1).dropLast(1)]!!
val env: FlagConfiguration = getFlags.flagConfigs[element.text.drop(1).dropLast(1)]
?: FlagConfiguration(flag.key, null, null, listOf(), listOf(), arrayOf(), false, -1)
val result = StringBuilder()
val prereqs = if (env.prerequisites.isNotEmpty()) {
"<b>Prerequisites</b> ${env.prerequisites.size}"
Expand Down Expand Up @@ -48,9 +50,14 @@ class LDDocumentationProvider : AbstractDocumentationProvider() {
buildEnvString += targets
}
result.append("<html>")
if (env.version === -1) {
result.append("<b>FLAG TARGETING INFORMATION IS NOT AVAILABLE. Below Values are placeholders</b><br />")
}
result.append("<img src=\"${LDIcons.FLAG}\"> <b>LaunchDarkly Feature Flag \u2022 ${flag.name ?: flag.key}</b><br />")
result.append("<a href=\"${settings.baseUri}${flag.environments[settings.environment]!!.site.href}\">Open In LaunchDarkly</a><br />")
val enabledIcon = if (env.on) {
val enabledIcon = if (env.version === -1) {
"<img src=\"${LDIcons.TOGGLE_DISCONNECTED}\" alt=\"Disconnected\">"
} else if (env.on) {
"<img src=\"${LDIcons.TOGGLE_ON}\" alt=\"On\">"
} else {
"<img src=\"${LDIcons.TOGGLE_OFF}\" alt=\"Off\">"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.github.intheclouddan.intellijpluginld.notifications.ConfigNotifier
import com.github.intheclouddan.intellijpluginld.settings.LaunchDarklyMergedSettings
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -134,11 +135,14 @@ class FlagStore(private var project: Project) {
try {
val ldProject = LaunchDarklyApiClient.projectInstance(project, settings.authorization).getProject(settings.project)
val myStreamBaseURI = settings.baseUri.replace("app", "stream")
val (store, client) = createClientAndGetStore(ldProject.environments.find { it.key == settings.environment }!!.apiKey, myStreamBaseURI)
flagStore = store!!
flagClient = client
flagTargeting(store)
flagListener(client, store)
invokeLater {
val (store, client) = createClientAndGetStore(ldProject.environments.find { it.key == settings.environment }!!.apiKey, myStreamBaseURI)
flagStore = store!!
flagClient = client
flagTargeting(store)
flagListener(client, store)
}

} catch (err: ApiException) {
val notify = ConfigNotifier()
notify.notify(project, "Project: ${settings.project} Error: $err")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class LDIcons {
@JvmField
val TOGGLE_ON = IconLoader.getIcon("/icons/toggleon.svg", javaClass)

@JvmField
val TOGGLE_DISCONNECTED = IconLoader.getIcon("/icons/toggledisc.svg", javaClass)

@JvmField
val VARIATION = IconLoader.getIcon("/icons/variation.svg", javaClass)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.intheclouddan.intellijpluginld.toolwindow

import com.github.intheclouddan.intellijpluginld.FlagStore
import com.github.intheclouddan.intellijpluginld.LDIcons
import com.github.intheclouddan.intellijpluginld.featurestore.FlagConfiguration
import com.intellij.ide.projectView.PresentationData
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
Expand All @@ -14,7 +15,8 @@ class FlagNodeParent(FFlag: FeatureFlag, private var flags: FeatureFlags, myProj
private var children: MutableList<SimpleNode> = ArrayList()
private val getFlags = myProject.service<FlagStore>()
var flag: FeatureFlag = FFlag
var env = getFlags.flagConfigs[flag.key]!!
var env = getFlags.flagConfigs[flag.key]
?: FlagConfiguration(flag.key, null, null, listOf(), listOf(), arrayOf(), false, -1)
val key: String = flag.key


Expand Down Expand Up @@ -57,9 +59,11 @@ class FlagNodeParent(FFlag: FeatureFlag, private var flags: FeatureFlags, myProj

override fun update(data: PresentationData) {
super.update(data)
env = getFlags.flagConfigs[flag.key]!!
env = getFlags.flagConfigs[flag.key]
?: FlagConfiguration(flag.key, null, null, listOf(), listOf(), arrayOf(), false, -1)
flag = getFlags.flags.items.find { it.key == flag.key }!!
val enabledIcon = if (env.on) LDIcons.TOGGLE_ON else LDIcons.TOGGLE_OFF
// Flag version should only be -1 if we manually created a FlagConfiguration so set icon to warning.
val enabledIcon = if (env.version === -1) LDIcons.TOGGLE_DISCONNECTED else if (env.on) LDIcons.TOGGLE_ON else LDIcons.TOGGLE_OFF
val label = flag.name ?: flag.key
data.presentableText = label
data.setIcon(enabledIcon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class FlagPanel(private val myProject: Project, messageBusService: MessageBusSer
val parent = node as DefaultMutableTreeNode
if (parent.userObject is FlagNodeParent) {
var parentNode = parent.userObject as FlagNodeParent
if (parentNode.key == flag.key && parentNode.flag.version < flag.version) {
if (parentNode.key == flag.key && parentNode.flag.version < flag.version && getFlags.flagConfigs[flag.key] !== null) {
found = true
parentNode = FlagNodeParent(flag, getFlags.flags, myProject)
treeModel.invalidate(TreePath(parent), true)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<projectService serviceImplementation="com.github.intheclouddan.intellijpluginld.toolwindow.FlagToolWindow"/>
<toolWindow id="LaunchDarkly Flags" icon="/icons/flag.svg" anchor="right"
factoryClass="com.github.intheclouddan.intellijpluginld.toolwindow.FlagToolWindowFactory"/>
<documentationProvider implementation="com.github.intheclouddan.intellijpluginld.LDDocumentationProvider"/>
</extensions>

<actions>
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/META-INF/withJavaModule.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<lang.documentationProvider order="FIRST" language="JAVA"
implementationClass="com.github.intheclouddan.intellijpluginld.LDDocumentationProvider"/>
<completion.contributor language="JAVA"
implementationClass="com.github.intheclouddan.intellijpluginld.codeInsight.JavaCompletionContributor"/>
</extensions>
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/icons/flag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/main/resources/icons/flag_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/main/resources/icons/toggledisc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 14 additions & 7 deletions src/main/resources/icons/toggleoff.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 14 additions & 7 deletions src/main/resources/icons/toggleoff_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1f09856

Please sign in to comment.