Skip to content

Commit

Permalink
#1132 | CCv2: Added possibility to re-fetch Service details
Browse files Browse the repository at this point in the history
  • Loading branch information
mlytvyn authored May 15, 2024
1 parent a05cc68 commit 402c191
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Show modified time in the Service view [#1127](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1127)
- Show Green deployment information in the Service view [#1129](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1129)
- Show Initial Passwords in the `hcs_admin` Service view [#1130](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1130)
- Added possibility to re-fetch Service details [#1132](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1132)

### Other
- Migrated to `IntelliJ Platform Gradle Plugin 2.beta2` [#1124](https://github.com/epam/sap-commerce-intellij-idea-plugin/issues/1124)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<reference id="ccv2.open.settings.action"/>
<separator/>

<group text="View Options"
<group id="ccv2.toolbar.actions.show" text="View Options"
popup="true"
icon="AllIcons.Actions.Show">
<separator text="Show With Status"/>
Expand Down Expand Up @@ -63,5 +63,10 @@
<reference id="ccv2.open.settings.action"/>
<separator/>
</group>

<group id="ccv2.service.toolbar.actions">
<reference id="ccv2.open.settings.action"/>
<separator/>
</group>
</actions>
</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.intellij.idea.plugin.hybris.settings.components.ApplicationSettingsCo
import com.intellij.idea.plugin.hybris.tools.ccv2.CCv2Service
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2EnvironmentDto
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2EnvironmentStatus
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2ServiceDto
import com.intellij.idea.plugin.hybris.toolwindow.HybrisToolWindowFactory
import com.intellij.idea.plugin.hybris.toolwindow.ccv2.CCv2Tab
import com.intellij.idea.plugin.hybris.toolwindow.ccv2.views.CCv2EnvironmentDetailsView
Expand Down Expand Up @@ -98,6 +99,58 @@ class CCv2FetchEnvironmentAction(
}
}

class CCv2FetchEnvironmentServiceAction(
private val subscription: CCv2Subscription,
private val environment: CCv2EnvironmentDto,
private val service: CCv2ServiceDto,
private val onStartCallback: () -> Unit,
private val onCompleteCallback: (CCv2ServiceDto) -> Unit
) : DumbAwareAction("Fetch Service", null, HybrisIcons.CCV2_FETCH) {

private var fetching = false

override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT

override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
CCv2Service.getInstance(project).fetchEnvironmentServices(
subscription,
environment,
{
fetching = true
e.presentation.text = "Fetching..."

onStartCallback.invoke()
},
{ response ->
invokeLater {
fetching = false
e.presentation.text = "Fetch Environment"

val fetchedService = response
?.find { it.code == service.code }

if (fetchedService != null) {
onCompleteCallback.invoke(fetchedService)
} else {
Notifications.create(
NotificationType.WARNING,
"Unable to fetch service",
"Service ${service.code} is not found."
)
.hideAfter(10)
.notify(project)
}
}
}
)
}

override fun update(e: AnActionEvent) {
e.presentation.isEnabled = !fetching && ApplicationSettingsComponent.getInstance().state.ccv2Subscriptions.isNotEmpty()
}
}

class CCv2ShowEnvironmentDetailsAction(
private val subscription: CCv2Subscription,
private val environment: CCv2EnvironmentDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import com.intellij.ide.HelpTooltip
import com.intellij.idea.plugin.hybris.notifications.Notifications
import com.intellij.idea.plugin.hybris.settings.CCv2Subscription
import com.intellij.idea.plugin.hybris.tools.ccv2.CCv2Service
import com.intellij.idea.plugin.hybris.tools.ccv2.actions.CCv2FetchEnvironmentServiceAction
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2EnvironmentDto
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2ServiceDto
import com.intellij.idea.plugin.hybris.tools.ccv2.dto.CCv2ServiceProperties
import com.intellij.idea.plugin.hybris.ui.Dsl
import com.intellij.notification.NotificationType
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.ide.CopyPasteManager
import com.intellij.openapi.observable.properties.AtomicBooleanProperty
Expand Down Expand Up @@ -75,9 +78,38 @@ class CCv2ServiceDetailsView(
}

init {
installToolbar()
initPanel()
}

private fun installToolbar() {
val toolbar = with(DefaultActionGroup()) {
val actionManager = ActionManager.getInstance()

add(actionManager.getAction("ccv2.service.toolbar.actions"))
add(CCv2FetchEnvironmentServiceAction(
subscription,
environment,
service,
{
},
{
service = it

this@CCv2ServiceDetailsView.remove(rootPanel)
rootPanel = rootPanel()

initPanel()
}
))


actionManager.createActionToolbar("SAP_CX_CCv2_SERVICE_${System.identityHashCode(service)}", this, false)
}
toolbar.targetComponent = this
setToolbar(toolbar.component)
}

private fun initPanel() {
add(rootPanel)

Expand Down

0 comments on commit 402c191

Please sign in to comment.