Added showHeader option to entity list. (#91)

This commit is contained in:
Matija Sosic 2020-02-05 13:46:48 +01:00 committed by GitHub
parent a8915a12c9
commit fa05eed363
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 3 deletions

View File

@ -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>

View File

@ -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:

View File

@ -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

View File

@ -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]

View File

@ -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)

View File

@ -60,4 +60,5 @@ formFieldIsDone = GEF.FormFieldTemplateData
, GEF._fieldType = Wasp.EftBoolean
, GEF._fieldShow = True
, GEF._fieldDefaultValue = EF.DefaultValueBool True
, GEF._fieldPlaceholder = Nothing
}

View File

@ -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"

View File

@ -70,6 +70,7 @@ entity-form<Task> CreateTaskForm {
}
entity-list<Task> TaskList {
showHeader: false,
fields: {
description: {
render: {=js