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}> <div className={this.props.className}>
<Paper> <Paper>
<Table> <Table>
<TableHead> <TableHead{=^ showHeader =} style={{display: 'none'}}{=/ showHeader =}>
<TableRow> <TableRow>
{=# listFields =} {=# listFields =}
<TableCell width="{= widthAsPercent =}%">{= name =}</TableCell> <TableCell width="{= widthAsPercent =}%">{= name =}</TableCell>

View File

@ -112,6 +112,7 @@ entity-form<Task> NewTaskForm {
// Entity list definition. // Entity list definition.
entity-list<Task> TaskList { entity-list<Task> TaskList {
showHeader: false,
fields: { fields: {
description: { description: {
// The contract for render is: user must provide a function that: // The contract for render is: user must provide a function that:

View File

@ -26,6 +26,7 @@ data EntityListTemplateData = EntityListTemplateData
, _entityName :: !String , _entityName :: !String
, _entityClassName :: !String , _entityClassName :: !String
, _entityLowerName :: !String , _entityLowerName :: !String
, _listShowHeader :: !Bool
, _listFields :: ![ListFieldTemplateData] , _listFields :: ![ListFieldTemplateData]
, _entityBeingEditedStateVar :: !String , _entityBeingEditedStateVar :: !String
@ -37,6 +38,7 @@ instance ToJSON EntityListTemplateData where
, "entityName" .= _entityName td , "entityName" .= _entityName td
, "entityClassName" .= _entityClassName td , "entityClassName" .= _entityClassName td
, "entityLowerName" .= _entityLowerName td , "entityLowerName" .= _entityLowerName td
, "showHeader" .= _listShowHeader td
, "listFields" .= _listFields td , "listFields" .= _listFields td
, "entityBeingEditedStateVar" .= _entityBeingEditedStateVar td , "entityBeingEditedStateVar" .= _entityBeingEditedStateVar td
] ]
@ -69,12 +71,15 @@ createEntityListTemplateData entity entityList =
, _entityName = Wasp.entityName entity , _entityName = Wasp.entityName entity
, _entityClassName = EC.getEntityClassName entity , _entityClassName = EC.getEntityClassName entity
, _entityLowerName = EC.getEntityLowerName entity , _entityLowerName = EC.getEntityLowerName entity
, _listShowHeader = showHeader
, _listFields = map (createListFieldTD entity entityList) $ Wasp.entityFields entity , _listFields = map (createListFieldTD entity entityList) $ Wasp.entityFields entity
, _entityBeingEditedStateVar = entityLowerName ++ "BeingEdited" , _entityBeingEditedStateVar = entityLowerName ++ "BeingEdited"
} }
where where
entityLowerName = EC.getEntityLowerName entity entityLowerName = EC.getEntityLowerName entity
showHeader = maybe True id (WEL._showHeader entityList)
createListFieldTD :: Wasp.Entity -> WEL.EntityList -> Wasp.EntityField -> ListFieldTemplateData createListFieldTD :: Wasp.Entity -> WEL.EntityList -> Wasp.EntityField -> ListFieldTemplateData
createListFieldTD entity entityList entityField = ListFieldTemplateData createListFieldTD entity entityList entityField = ListFieldTemplateData
{ _fieldName = Wasp.entityFieldName entityField { _fieldName = Wasp.entityFieldName entityField

View File

@ -27,11 +27,13 @@ entityList = do
return WEL.EntityList return WEL.EntityList
{ WEL._name = listName { WEL._name = listName
, WEL._entityName = entityName , WEL._entityName = entityName
, WEL._showHeader = maybeGetListOptionShowHeader options
, WEL._fields = getFieldsConfig options , WEL._fields = getFieldsConfig options
} }
data EntityListOption data EntityListOption
= EloFields [WEL.Field] = EloShowHeader Bool
| EloFields [WEL.Field]
deriving (Show, Eq) deriving (Show, Eq)
entityListOptions :: Parser [EntityListOption] entityListOptions :: Parser [EntityListOption]
@ -41,9 +43,15 @@ entityListOptions = L.commaSep entityListOption
entityListOption :: Parser EntityListOption entityListOption :: Parser EntityListOption
entityListOption = choice entityListOption = choice
[ entityListOptionFields [ EloShowHeader <$> P.waspPropertyBool "showHeader"
, entityListOptionFields
] ]
-- * Show header
maybeGetListOptionShowHeader :: [EntityListOption] -> Maybe Bool
maybeGetListOptionShowHeader options = U.headSafe [b | EloShowHeader b <- options]
-- * Fields -- * Fields
getFieldsConfig :: [EntityListOption] -> [WEL.Field] getFieldsConfig :: [EntityListOption] -> [WEL.Field]

View File

@ -15,6 +15,7 @@ import qualified Wasp.Entity as Entity
data EntityList = EntityList data EntityList = EntityList
{ _name :: !String -- Name of the list { _name :: !String -- Name of the list
, _entityName :: !String -- Name of the entity the form is linked to , _entityName :: !String -- Name of the entity the form is linked to
, _showHeader :: Maybe Bool -- Should the list header be displayed or not
, _fields :: [Field] , _fields :: [Field]
} deriving (Show, Eq) } deriving (Show, Eq)

View File

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

View File

@ -91,6 +91,7 @@ spec_parseWasp =
, WaspElementEntityList $ EL.EntityList , WaspElementEntityList $ EL.EntityList
{ EL._name = "TaskList" { EL._name = "TaskList"
, EL._entityName = "Task" , EL._entityName = "Task"
, EL._showHeader = Just False
, EL._fields = , EL._fields =
[ EL.Field [ EL.Field
{ EL._fieldName = "description" { EL._fieldName = "description"

View File

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