From 2d1601dc65a727ba1fc1da305831dd8fc4b6f50a Mon Sep 17 00:00:00 2001 From: Amitai Burstein Date: Sun, 1 Sep 2024 11:20:59 +0300 Subject: [PATCH] Start adding inherits info to renderColumnSelector --- ihp-ide/IHP/IDE/SchemaDesigner/View/Layout.hs | 17 ++++++++++++++++- ihp-ide/IHP/SchemaCompiler.hs | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ihp-ide/IHP/IDE/SchemaDesigner/View/Layout.hs b/ihp-ide/IHP/IDE/SchemaDesigner/View/Layout.hs index 2105f17cc..5f955a134 100644 --- a/ihp-ide/IHP/IDE/SchemaDesigner/View/Layout.hs +++ b/ihp-ide/IHP/IDE/SchemaDesigner/View/Layout.hs @@ -222,6 +222,11 @@ renderColumnSelector tableName columns statements = [hsx| {forEach columns (\column -> renderColumn (snd column) (fst column) tableName statements)} + +
+ Inherits: {inherits} +
+ {suggestedColumnsSection tableName columns} {auth} @@ -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|
@@ -411,7 +426,7 @@ renderColumn Column { name, columnType, defaultValue, notNull, isUnique } id tab [hsx|Edit Foreign Key Constraint Delete Foreign Key Constraint|] _ -> [hsx|Add Foreign Key Constraint|] - + addIndex :: Html addIndex = unless alreadyHasIndex [hsx|
diff --git a/ihp-ide/IHP/SchemaCompiler.hs b/ihp-ide/IHP/SchemaCompiler.hs index 8a93145df..6ed84595e 100644 --- a/ihp-ide/IHP/SchemaCompiler.hs +++ b/ihp-ide/IHP/SchemaCompiler.hs @@ -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