-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement create * Minor changes
- Loading branch information
Showing
25 changed files
with
234 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
spra-web/src/main/scala/net/wiringbits/spra/ui/web/components/CreateGuesser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.wiringbits.spra.ui.web.components | ||
|
||
import net.wiringbits.spra.api.models.AdminGetTables | ||
import net.wiringbits.spra.ui.web.facades.reactadmin.* | ||
import net.wiringbits.spra.ui.web.models.ColumnType | ||
import net.wiringbits.spra.ui.web.utils.ResponseGuesser | ||
import slinky.core.facade.{Fragment, ReactElement} | ||
import slinky.core.{FunctionalComponent, KeyAddingStage} | ||
|
||
import scala.scalajs.js | ||
|
||
object CreateGuesser { | ||
case class Props(response: AdminGetTables.Response.DatabaseTable) | ||
|
||
def apply(response: AdminGetTables.Response.DatabaseTable): KeyAddingStage = component(Props(response = response)) | ||
|
||
val component: FunctionalComponent[Props] = FunctionalComponent[Props] { props => | ||
val fields = ResponseGuesser.getTypesFromResponse(props.response) | ||
val inputs: Seq[ReactElement] = fields.map { field => | ||
field.isRequiredOnCreate | ||
.map { isRequired => | ||
val required = if isRequired then ReactAdmin.required() else js.undefined | ||
|
||
field.`type` match { | ||
case ColumnType.Date => | ||
DateTimeInput(DateTimeInput.Props(source = field.name, isRequired = isRequired, validate = required)) | ||
case ColumnType.Text => | ||
TextInput(TextInput.Props(source = field.name, isRequired = isRequired, validate = required)) | ||
case ColumnType.Email => | ||
TextInput(TextInput.Props(source = field.name, isRequired = isRequired, validate = required)) | ||
case ColumnType.Image => | ||
ImageField(ImageField.Props(source = field.name, isRequired = isRequired, validate = required)) | ||
case ColumnType.Number => | ||
NumberInput(NumberInput.Props(source = field.name, isRequired = isRequired, validate = required)) | ||
case ColumnType.Reference(reference, source) => | ||
ReferenceInput( | ||
ReferenceInput.Props( | ||
source = field.name, | ||
reference = reference, | ||
children = Seq(SelectInput(SelectInput.Props(optionText = source, disabled = field.disabled))), | ||
isRequired = isRequired, | ||
validate = required | ||
) | ||
) | ||
} | ||
} | ||
.getOrElse(Fragment()) | ||
} | ||
|
||
Create( | ||
Create.Props( | ||
SimpleForm( | ||
SimpleForm.Props(toolbar = Fragment(), children = inputs :+ SaveButton()) | ||
) | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.