Skip to content

Commit

Permalink
Merge branch 'master' of github.com:digitallyinduced/ihp
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Aug 9, 2023
2 parents a400c04 + 7c3963a commit 29ec434
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion IHP/Controller/Param.hs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ instance (FillParams rest record
{-# INLINE fill #-}

ifValid :: (HasField "meta" model ModelSupport.MetaBag) => (Either model model -> IO r) -> model -> IO r
ifValid branch model = branch $! if isEmpty model.meta.annotations
ifValid branch model = branch $! if ModelSupport.isValid model
then Right model
else Left model
{-# INLINE ifValid #-}
Expand Down
2 changes: 1 addition & 1 deletion IHP/IDE/CodeGen/ViewGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ buildPlan' schema config =
indexView = [trimming|
${viewHeader}

data IndexView = IndexView { ${pluralVariableName} :: [${singularName}] ${importPagination} }
data IndexView = IndexView { ${pluralVariableName} :: [${singularName}]${importPagination} }

instance View IndexView where
html IndexView { .. } = [hsx|
Expand Down
13 changes: 13 additions & 0 deletions IHP/ModelSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,3 +1010,16 @@ onlyWhereReferences field referenced records = filter (\record -> get field reco
-- See 'onlyWhere' for more details.
onlyWhereReferencesMaybe :: forall record fieldName value referencedRecord. (KnownSymbol fieldName, HasField fieldName record (Maybe value), Eq value, HasField "id" referencedRecord value) => Proxy fieldName -> referencedRecord -> [record] -> [record]
onlyWhereReferencesMaybe field referenced records = filter (\record -> get field record == Just referenced.id) records

-- | Returns True when a record has no validation errors attached from a previous validation call
--
-- Example:
--
-- > isValidProject :: Project -> Bool
-- > isValidProject project =
-- > project
-- > |> validateField #name isNonEmpty
-- > |> isValid
--
isValid :: forall record. (HasField "meta" record MetaBag) => record -> Bool
isValid record = isEmpty record.meta.annotations
2 changes: 1 addition & 1 deletion IHP/SchemaMigration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ runMigration migration@Migration { revision, migrationFile } = do

let fullSql = [trimming|
BEGIN;
${migrationSql}
${migrationSql};
INSERT INTO schema_migrations (revision) VALUES (?);
COMMIT;
|]
Expand Down
Loading

0 comments on commit 29ec434

Please sign in to comment.