Skip to content

Commit

Permalink
Merge pull request #161 from picortex/master-dev-anderson
Browse files Browse the repository at this point in the history
Master dev anderson
  • Loading branch information
andylamax authored Oct 22, 2021
2 parents 88cfdcc + bdb36f1 commit 1dbabb6
Show file tree
Hide file tree
Showing 43 changed files with 385 additions and 76 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
## PiMonitor Client SDK Core

- [[PM124]](https://github.com/picortex/bitframe/issues/124) Removed onUserLoggedIn method from SignInViewModel
- [[PM141]](https://github.com/picortex/bitframe/issues/141) Created a Register business form
- [[PM141]](https://github.com/picortex/bitframe/issues/141) Created a Register business form
- [[PM140]](https://github.com/picortex/bitframe/issues/140) Make the register business form be invitational
- [[PM023]](https://github.com/picortex/bitframe/issues/23) Register a business
- [[PM017]](https://github.com/picortex/bitframe/issues/17) A Monitor can create a business, in his scope

# 0.0.30

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.js.JsExport

abstract class SignInService(
open val bus: EventBus,
open val config: ServiceConfig
protected open val config: ServiceConfig
) {
val session: Live<Session> = Live(Session.Unknown)
val currentSession get() = session.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import kotlin.jvm.JvmSynthetic
class TestClientConfiguration @JvmOverloads private constructor(
override val appId: String,
/** The time (in milliseconds) a client would take to simulate fake activity */
val simulationTime: Int = DEFAULT_SIMULATION_TIME,
val simulationTime: Long = DEFAULT_SIMULATION_TIME,
override val scope: CoroutineScope,
) : ClientConfiguration(appId, scope) {
companion object {
const val DEFAULT_SIMULATION_TIME = 0
const val DEFAULT_SIMULATION_TIME: Long = 0
private val cachedConfigs = mutableMapOf<String, TestClientConfiguration>()

@JvmSynthetic
operator fun invoke(
appId: String,
simulationTime: Int = DEFAULT_SIMULATION_TIME,
simulationTime: Long = DEFAULT_SIMULATION_TIME,
scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
): TestClientConfiguration = cachedConfigs.getOrPut(appId) {
TestClientConfiguration(appId, simulationTime, scope)
Expand All @@ -33,7 +33,7 @@ class TestClientConfiguration @JvmOverloads private constructor(
@JvmOverloads
fun of(
appId: String,
simulationTime: Int = DEFAULT_SIMULATION_TIME,
simulationTime: Long = DEFAULT_SIMULATION_TIME,
scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
) = invoke(appId, simulationTime, scope)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.coroutines.SupervisorJob
import kotlin.jvm.JvmField

open class InMemoryDaoConfig(
val simulationTime: Int,
val simulationTime: Long,
override val scope: CoroutineScope = CoroutineScope(SupervisorJob())
) : DaoConfig {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@file:JsExport

package bitframe.presenters.fields

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

@Serializable
data class BooleanInputField(
val label: String,
var value: Boolean? = null
)
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
package pimonitor.evaluation.business

import logging.console
import pimonitor.PiMonitorService
import pimonitor.evaluation.business.forms.CreateBusinessState
import pimonitor.evaluation.business.exports.CreateBusinessScope
import pimonitor.evaluation.business.forms.CreateBusinessState.*
import react.Props
import react.RBuilder
import react.fc
import react.useEffectOnce
import reakt.ErrorBox
import reakt.LoadingBox
import reakt.SuccessBox
import useViewModelState
import pimonitor.evaluation.business.forms.CreateBusinessIntent as Intent

private external interface AddBusinessProps : Props {
var uid: String?
var scope: AddBusinessScope
var scope: CreateBusinessScope
}

private val AddBusiness = fc<AddBusinessProps> { props ->
val scope = props.scope
val vm = scope.viewModel
useEffectOnce {
scope.showForm(props.uid)
}
useEffectOnce { scope.showForm(props.uid) }
when (val state = useViewModelState(vm)) {
is Loading -> LoadingBox(state.message)
is Form -> CreateBusinessForm(
state = state,
onSubmit = {
console.log(it)
}
onSubmit = { vm.post(Intent.SubmitForm(it)) }
)
is Success -> SuccessBox(state.message)
is Failure -> ErrorBox(state.cause)
}
}

internal fun RBuilder.AddBusiness(service: PiMonitorService, uid: String? = null) = child(AddBusiness) {
attrs.scope = AddBusinessScope(service)
attrs.scope = CreateBusinessScope(service)
attrs.uid = uid
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ package pimonitor.evaluation.business
import kotlinx.css.JustifyContent
import kotlinx.css.justifyContent
import pimonitor.PiMonitorService
import pimonitor.monitors.Session
import pimonitor.evaluation.business.exports.BusinessesScope
import react.Props
import react.RBuilder
import react.fc
import react.router.dom.routeLink
import react.useEffectOnce
import reakt.ContainedButton
import reakt.FlexBox
import reakt.LoadingBox
import reakt.SuccessBox
import reakt.*
import styled.css
import styled.styledDiv
import useLive
import useViewModelState

private external interface BusinessContainerProps : Props {
Expand All @@ -25,11 +21,11 @@ private external interface BusinessContainerProps : Props {
private val BusinessContainer = fc<BusinessContainerProps> { props ->
val scope = props.scope
val viewModel = scope.viewModel
val monitor = when (val session = useLive(scope.service.monitors.session)) {
Session.Unknown -> null
is Session.Active -> session.monitor
}
useEffectOnce { scope.loadBusiness() }
val loadBusinesses = scope.loadBusinesses
val useBusinessAddedEvent = scope.useBusinessAddedEvent
val monitor = scope.service.monitors.currentMonitorOrNull
useBusinessAddedEvent { loadBusinesses() }
useEffectOnce { loadBusinesses() }
when (val state = useViewModelState(viewModel)) {
is BusinessesState.Loading -> LoadingBox(state.message)
is BusinessesState.Businesses -> styledDiv {
Expand All @@ -44,6 +40,7 @@ private val BusinessContainer = fc<BusinessContainerProps> { props ->
}
is BusinessesState.BusinessForm -> AddBusiness(scope.service)
is BusinessesState.Success -> SuccessBox(state.message)
is BusinessesState.Failure -> ErrorBox(state.cause)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal fun RBuilder.BusinessList(
data,
columns = listOf(
Column("name") { it.name },
Column("email") { it.contacts.first().email.value },
Column("contact") { it.contacts.first().name },
Column("email") { it.contacts.first().email.value },
RenderColumn("actions") {
Grid(cols = "1fr 1fr") {
ContainedButton("View") {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ class AddBusinessTest : AcceptanceTest() {
name = "Jane Doe", email = "[email protected]", password = "janedoe"
)
val dashboard = openSignUpScreen().signUp(params).expectToBeSigningUp()
val details = CreateMonitoredBusinessParams(
businessName = "PiCortex",
contactName = "Mohammed Majapa",
contactEmail = "[email protected]"
)
val businesses = dashboard.selectBusinesses()
businesses.clickCreateButton().apply {
enter(details)
submitByPressingEnter()
for (i in 1..5) {
val details = CreateMonitoredBusinessParams(
businessName = "PiCortex - $i",
contactName = "Mohammed Majapa - $i",
contactEmail = "mmajapa$i@gmail.com"
)
businesses.clickCreateButton().apply {
enter(details)
submitByPressingEnter()
}
businesses.expectToHaveBusinessWithName(details.businessName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

package pimonitor.evaluation.business.exports

import later.then
import pimonitor.evaluation.businesses.BusinessesService

class BusinessesServiceWrapper(service: BusinessesService) {
val loadBusinesses: () -> Unit = { service.all() }
val loadBusinesses = { service.all().then { it.toTypedArray() } }
val create = { params: CreateBusinessFormParams -> service.create(params.toParams()) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@file:JsExport

package pimonitor.evaluation.business.exports

external interface CreateBusinessFormParams {
var businessName: String
var contactName: String
var contactEmail: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pimonitor.evaluation.business.exports

import pimonitor.monitored.CreateMonitoredBusinessParams

fun CreateBusinessFormParams.toParams() = CreateMonitoredBusinessParams(
businessName, contactName, contactEmail
)
2 changes: 1 addition & 1 deletion pi-monitor/pi-monitor-client/sdks/full/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ kotlin {
js(IR) {
val main by compilations
main.outputModuleName = "pi-monitor-client-sdk-full"
browserLib()
library()
binaries.library()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package pimonitor.evaluation.business.forms

import bitframe.presenters.fields.BooleanInputField
import bitframe.presenters.fields.ButtonInputField
import bitframe.presenters.fields.TextInputField
import kotlin.js.JsExport
Expand All @@ -12,5 +13,6 @@ data class CreateBusinessFields internal constructor(
val businessName: TextInputField,
val contactName: TextInputField,
val contactEmail: TextInputField,
val sendInvite: BooleanInputField?,
val submitButton: ButtonInputField
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package pimonitor.evaluation.business.forms

import bitframe.presenters.fields.BooleanInputField
import bitframe.presenters.fields.ButtonInputField
import bitframe.presenters.fields.TextInputField
import pimonitor.monitors.Monitor
import pimonitor.evaluation.business.forms.CreateBusinessIntent as Intent

internal fun AddBusinessFormFields() = CreateBusinessFields(
inviterIntroduction = null,
Expand All @@ -19,6 +21,10 @@ internal fun AddBusinessFormFields() = CreateBusinessFields(
label = "Contact Email",
hint = "[email protected]"
),
sendInvite = BooleanInputField(
label = "Ask to share reports",
value = true
),
submitButton = ButtonInputField(text = "Submit")
)

Expand All @@ -37,5 +43,13 @@ internal fun InviteBusinessFormFields(inviter: Monitor) = CreateBusinessFields(
label = "Your Email",
hint = "[email protected]"
),
sendInvite = null,
submitButton = ButtonInputField(text = "Submit")
)

internal fun CreateBusinessFields.copy(i: Intent.SubmitForm) = copy(
businessName = businessName.copy(value = i.params.businessName),
contactName = contactName.copy(value = i.params.contactName),
contactEmail = contactEmail.copy(value = i.params.contactEmail),
sendInvite = sendInvite?.copy(value = i.params.sendInvite)
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package pimonitor.evaluation.business.forms

import pimonitor.monitored.CreateMonitoredBusinessParams

sealed class CreateBusinessIntent {
data class ShowForm(val inviteId: String?) : CreateBusinessIntent()
data class SubmitForm(val params: CreateMonitoredBusinessParams) : CreateBusinessIntent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@ import bitframe.presenters.feedbacks.FormFeedback
import kotlin.js.JsExport

sealed class CreateBusinessState {
data class Loading(val message: String) : CreateBusinessState()
data class Form(val fields: CreateBusinessFields, val status: FormFeedback?) : CreateBusinessState()
data class Failure(val cause: Throwable, val message: String = cause.message ?: "Unknown error") : CreateBusinessState()
data class Loading(
val message: String
) : CreateBusinessState() {
val loading = true
}

data class Form(
val fields: CreateBusinessFields,
val status: FormFeedback?
) : CreateBusinessState()

data class Failure(
val cause: Throwable,
val message: String = cause.message ?: "Unknown error"
) : CreateBusinessState() {
val failure = true
}

data class Success(
val message: String
) : CreateBusinessState() {
val success = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@file:JsExport

package pimonitor.evaluation.business.forms

import kotlin.js.JsExport
import pimonitor.evaluation.business.forms.CreateBusinessIntent as Intent

internal fun CreateBusinessState.copy(i: Intent.SubmitForm) = if (this is CreateBusinessState.Form) {
CreateBusinessState.Form(fields = fields.copy(i), status)
} else {
this
}
Loading

0 comments on commit 1dbabb6

Please sign in to comment.