Skip to content

Commit

Permalink
Start adding inherits info to renderColumnSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Sep 1, 2024
1 parent 95ea731 commit 2d1601d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ihp-ide/IHP/IDE/SchemaDesigner/View/Layout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ renderColumnSelector tableName columns statements = [hsx|
{forEach columns (\column -> renderColumn (snd column) (fst column) tableName statements)}
</tbody>
</table>

<div>
Inherits: {inherits}
</div>

{suggestedColumnsSection tableName columns}
</section>
{auth}
Expand Down Expand Up @@ -251,6 +256,16 @@ renderColumnSelector tableName columns statements = [hsx|
auth :: Html
auth = renderPolicies tableName statements

inherits = statements
|> find (\case
StatementCreateTable CreateTable { name } | name == tableName -> True
_ -> False)
-- Get the table that this table inherits from
|> \case
Just (StatementCreateTable CreateTable { inherits }) -> inherits
_ -> Nothing


suggestedColumnsSection :: Text -> [(Int, Column)] -> Html
suggestedColumnsSection tableName indexAndColumns = unless isUsersTable [hsx|
<div class="mt-5">
Expand Down Expand Up @@ -411,7 +426,7 @@ renderColumn Column { name, columnType, defaultValue, notNull, isUnique } id tab
[hsx|<a href={EditForeignKeyAction tableName name constraintName referenceTable}>Edit Foreign Key Constraint</a>
<a href={DeleteForeignKeyAction constraintName tableName} class="js-delete">Delete Foreign Key Constraint</a>|]
_ -> [hsx|<a href={NewForeignKeyAction tableName name}>Add Foreign Key Constraint</a>|]

addIndex :: Html
addIndex = unless alreadyHasIndex [hsx|
<form method="POST" action={CreateIndexAction tableName name}>
Expand Down
1 change: 1 addition & 0 deletions ihp-ide/IHP/SchemaCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ hasExplicitOrImplicitDefault column = case column of
_ -> False


findTableByName :: (?schema :: Schema) => Text -> Maybe Statement
findTableByName tableName = ?schema.statements
|> find (\case
StatementCreateTable CreateTable { name } | name == tableName -> True
Expand Down

0 comments on commit 2d1601d

Please sign in to comment.