Skip to content

Commit

Permalink
Moved TaskManager component to scommons-react-redux module
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Sep 9, 2019
1 parent 164b6a5 commit f60eca5
Show file tree
Hide file tree
Showing 11 changed files with 1,515 additions and 1,920 deletions.
2,829 changes: 1,413 additions & 1,416 deletions docs/showcase/assets/scommons-client-showcase-opt.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package scommons.client.showcase

import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.ReactDOM
import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.scalajs.reactjs.redux.ReactRedux._
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import io.github.shogowada.scalajs.reactjs.redux.{ReactRedux, Redux}
import io.github.shogowada.scalajs.reactjs.redux.Redux
import io.github.shogowada.scalajs.reactjs.router.WithRouter
import io.github.shogowada.scalajs.reactjs.router.dom.RouterDOM._
import org.scalajs.dom
import scommons.client.app._
import scommons.client.task.{TaskManager, TaskManagerProps}
import scommons.client.ui.Buttons
import scommons.client.ui.popup.raw.NativeReactModal
import scommons.react._

object ShowcaseMain {

Expand All @@ -37,45 +32,12 @@ object ShowcaseMain {
<.Provider(^.store := store)(
<.HashRouter()(
<(WithRouter(AppMainPanel()))(^.wrapped := appMainPanelProps)(
<(RouteController()).empty,
<(TaskController()).empty
<(ShowcaseRouteController()).empty,
<(ShowcaseTaskController()).empty
)
)
),
mountNode
)
}
}

object RouteController {

def apply(): ReactClass = reactClass

private lazy val reactClass = ReactRedux.connectAdvanced(
(dispatch: Dispatch) => {

(state: ShowcaseState, _: Props[Unit]) => {
AppBrowseControllerProps(
List(Buttons.REFRESH, Buttons.ADD, Buttons.REMOVE, Buttons.EDIT),
ShowcaseReducer.getTreeRoots(state),
dispatch,
Set(ShowcaseReducer.widgetsNode.path)
)
}
}
)(AppBrowseController())
}

object TaskController {

def apply(): ReactClass = reactClass

private lazy val reactClass = ReactRedux.connectAdvanced(
(_: Dispatch) => {

(state: ShowcaseState, _: Props[Unit]) => {
TaskManagerProps(state.currentTask)
}
}
)(TaskManager())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package scommons.client.showcase

import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.client.app.{AppBrowseController, AppBrowseControllerProps}
import scommons.client.ui.Buttons
import scommons.react.UiComponent
import scommons.react.redux.BaseStateController

object ShowcaseRouteController extends BaseStateController[ShowcaseState, AppBrowseControllerProps] {

lazy val uiComponent: UiComponent[AppBrowseControllerProps] = AppBrowseController

def mapStateToProps(dispatch: Dispatch, state: ShowcaseState, props: Props[Unit]): AppBrowseControllerProps = {
AppBrowseControllerProps(
List(Buttons.REFRESH, Buttons.ADD, Buttons.REMOVE, Buttons.EDIT),
ShowcaseReducer.getTreeRoots(state),
dispatch,
Set(ShowcaseReducer.widgetsNode.path)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package scommons.client.showcase

import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.client.app.AppTaskManagerUi
import scommons.react.UiComponent
import scommons.react.redux.BaseStateController
import scommons.react.redux.task.{TaskManager, TaskManagerProps}

object ShowcaseTaskController extends BaseStateController[ShowcaseState, TaskManagerProps] {

lazy val uiComponent: UiComponent[TaskManagerProps] = {
TaskManager.uiComponent = AppTaskManagerUi
TaskManager.errorHandler = AppTaskManagerUi.errorHandler
TaskManager
}

def mapStateToProps(dispatch: Dispatch, state: ShowcaseState, props: Props[Unit]): TaskManagerProps = {
TaskManagerProps(state.currentTask)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ object PopupsDemo extends FunctionComponent[Unit] {
if (state.showError) Some(
<(ErrorPopup())(^.wrapped := ErrorPopupProps(
error = "Some error occurred",
exception = new Exception(),
details = Some("Some\n\terror\n\t\tdetails"),
onClose = { () =>
setState(_.copy(showError = false))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package scommons.client.task
package scommons.client.app

import scommons.api.ApiResponse
import scommons.client.ui.popup._
import scommons.react._
import scommons.react.redux.task.TaskManagerUiProps

case class TaskManagerUiProps(showLoading: Boolean,
status: Option[String],
onHideStatus: () => Unit,
error: Option[String],
errorDetails: Option[String],
onCloseErrorPopup: () => Unit)
import scala.util.{Success, Try}

object TaskManagerUi extends FunctionComponent[TaskManagerUiProps] {
/**
* Displays status of running tasks.
*/
object AppTaskManagerUi extends FunctionComponent[TaskManagerUiProps] {

var errorHandler: PartialFunction[Try[_], (Option[String], Option[String])] = {
case Success(result) => result match {
case res: ApiResponse if res.status.nonSuccessful =>
(Some(res.status.error.getOrElse("Non-successful response")), res.status.details)
case _ =>
(None, None)
}
}

protected def render(compProps: Props): ReactElement = {
val props = compProps.wrapped
Expand Down
95 changes: 0 additions & 95 deletions ui/src/main/scala/scommons/client/task/TaskManager.scala

This file was deleted.

59 changes: 0 additions & 59 deletions ui/src/main/scala/scommons/client/ui/popup/ErrorPopup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ case class ErrorPopupProps(error: String,
onClose: () => Unit,
details: Option[String] = None)

object ErrorPopupProps {

def apply(error: String,
exception: Throwable,
onClose: () => Unit): ErrorPopupProps = {

ErrorPopupProps(error, onClose, Some(ErrorPopup.printStackTrace(exception)))
}
}

object ErrorPopup extends FunctionComponent[ErrorPopupProps] {

private case class ErrorPopupState(showDetails: Boolean = false,
Expand Down Expand Up @@ -65,53 +55,4 @@ object ErrorPopup extends FunctionComponent[ErrorPopupProps] {
private def getFullText(props: ErrorPopupProps): String = {
HTML.makeHtmlText(s"${props.error}\n\n${props.details.getOrElse("")}")
}

def printStackTrace(x: Throwable): String = {
val sb = new StringBuilder(x.toString)
val trace = x.getStackTrace
for (t <- trace) {
sb.append("\n\tat&nbsp").append(t)
}

val cause = x.getCause
if (cause != null) {
printStackTraceAsCause(sb, cause, trace)
}

sb.toString
}

/**
* Print stack trace as a cause for the specified stack trace.
*/
private def printStackTraceAsCause(sb: StringBuilder,
cause: Throwable,
causedTrace: Array[StackTraceElement]): Unit = {

// Compute number of frames in common between this and caused
val trace = cause.getStackTrace
var m = trace.length - 1
var n = causedTrace.length - 1
while (m >= 0 && n >= 0 && trace(m) == causedTrace(n)) {
m -= 1
n -= 1
}

val framesInCommon = trace.length - 1 - m
sb.append("\nCaused by: " + cause)

for (i <- 0 to m) {
sb.append("\n\tat&nbsp").append(trace(i))
}

if (framesInCommon != 0) {
sb.append("\n\t...&nbsp").append(framesInCommon).append("&nbspmore")
}

// Recurse if we have a cause
val ourCause = cause.getCause
if (ourCause != null) {
printStackTraceAsCause(sb, ourCause, trace)
}
}
}
Loading

0 comments on commit f60eca5

Please sign in to comment.