mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-27 02:52:22 +03:00
Added showHeader option to entity list. (#91)
This commit is contained in:
parent
a8915a12c9
commit
fa05eed363
@ -67,7 +67,7 @@ export class {= listName =} extends React.Component {
|
||||
<div className={this.props.className}>
|
||||
<Paper>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableHead{=^ showHeader =} style={{display: 'none'}}{=/ showHeader =}>
|
||||
<TableRow>
|
||||
{=# listFields =}
|
||||
<TableCell width="{= widthAsPercent =}%">{= name =}</TableCell>
|
||||
|
@ -112,6 +112,7 @@ entity-form<Task> NewTaskForm {
|
||||
|
||||
// Entity list definition.
|
||||
entity-list<Task> TaskList {
|
||||
showHeader: false,
|
||||
fields: {
|
||||
description: {
|
||||
// The contract for render is: user must provide a function that:
|
||||
|
@ -26,6 +26,7 @@ data EntityListTemplateData = EntityListTemplateData
|
||||
, _entityName :: !String
|
||||
, _entityClassName :: !String
|
||||
, _entityLowerName :: !String
|
||||
, _listShowHeader :: !Bool
|
||||
, _listFields :: ![ListFieldTemplateData]
|
||||
|
||||
, _entityBeingEditedStateVar :: !String
|
||||
@ -37,6 +38,7 @@ instance ToJSON EntityListTemplateData where
|
||||
, "entityName" .= _entityName td
|
||||
, "entityClassName" .= _entityClassName td
|
||||
, "entityLowerName" .= _entityLowerName td
|
||||
, "showHeader" .= _listShowHeader td
|
||||
, "listFields" .= _listFields td
|
||||
, "entityBeingEditedStateVar" .= _entityBeingEditedStateVar td
|
||||
]
|
||||
@ -69,12 +71,15 @@ createEntityListTemplateData entity entityList =
|
||||
, _entityName = Wasp.entityName entity
|
||||
, _entityClassName = EC.getEntityClassName entity
|
||||
, _entityLowerName = EC.getEntityLowerName entity
|
||||
, _listShowHeader = showHeader
|
||||
, _listFields = map (createListFieldTD entity entityList) $ Wasp.entityFields entity
|
||||
, _entityBeingEditedStateVar = entityLowerName ++ "BeingEdited"
|
||||
}
|
||||
where
|
||||
entityLowerName = EC.getEntityLowerName entity
|
||||
|
||||
showHeader = maybe True id (WEL._showHeader entityList)
|
||||
|
||||
createListFieldTD :: Wasp.Entity -> WEL.EntityList -> Wasp.EntityField -> ListFieldTemplateData
|
||||
createListFieldTD entity entityList entityField = ListFieldTemplateData
|
||||
{ _fieldName = Wasp.entityFieldName entityField
|
||||
|
@ -27,11 +27,13 @@ entityList = do
|
||||
return WEL.EntityList
|
||||
{ WEL._name = listName
|
||||
, WEL._entityName = entityName
|
||||
, WEL._showHeader = maybeGetListOptionShowHeader options
|
||||
, WEL._fields = getFieldsConfig options
|
||||
}
|
||||
|
||||
data EntityListOption
|
||||
= EloFields [WEL.Field]
|
||||
= EloShowHeader Bool
|
||||
| EloFields [WEL.Field]
|
||||
deriving (Show, Eq)
|
||||
|
||||
entityListOptions :: Parser [EntityListOption]
|
||||
@ -41,9 +43,15 @@ entityListOptions = L.commaSep entityListOption
|
||||
|
||||
entityListOption :: Parser EntityListOption
|
||||
entityListOption = choice
|
||||
[ entityListOptionFields
|
||||
[ EloShowHeader <$> P.waspPropertyBool "showHeader"
|
||||
, entityListOptionFields
|
||||
]
|
||||
|
||||
-- * Show header
|
||||
|
||||
maybeGetListOptionShowHeader :: [EntityListOption] -> Maybe Bool
|
||||
maybeGetListOptionShowHeader options = U.headSafe [b | EloShowHeader b <- options]
|
||||
|
||||
-- * Fields
|
||||
|
||||
getFieldsConfig :: [EntityListOption] -> [WEL.Field]
|
||||
|
@ -15,6 +15,7 @@ import qualified Wasp.Entity as Entity
|
||||
data EntityList = EntityList
|
||||
{ _name :: !String -- Name of the list
|
||||
, _entityName :: !String -- Name of the entity the form is linked to
|
||||
, _showHeader :: Maybe Bool -- Should the list header be displayed or not
|
||||
, _fields :: [Field]
|
||||
} deriving (Show, Eq)
|
||||
|
||||
|
@ -60,4 +60,5 @@ formFieldIsDone = GEF.FormFieldTemplateData
|
||||
, GEF._fieldType = Wasp.EftBoolean
|
||||
, GEF._fieldShow = True
|
||||
, GEF._fieldDefaultValue = EF.DefaultValueBool True
|
||||
, GEF._fieldPlaceholder = Nothing
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ spec_parseWasp =
|
||||
, WaspElementEntityList $ EL.EntityList
|
||||
{ EL._name = "TaskList"
|
||||
, EL._entityName = "Task"
|
||||
, EL._showHeader = Just False
|
||||
, EL._fields =
|
||||
[ EL.Field
|
||||
{ EL._fieldName = "description"
|
||||
|
@ -70,6 +70,7 @@ entity-form<Task> CreateTaskForm {
|
||||
}
|
||||
|
||||
entity-list<Task> TaskList {
|
||||
showHeader: false,
|
||||
fields: {
|
||||
description: {
|
||||
render: {=js
|
||||
|
Loading…
Reference in New Issue
Block a user