mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-27 19:14:52 +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}>
|
<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>
|
||||||
|
@ -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:
|
||||||
|
@ -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
|
||||||
|
@ -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]
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user