Skip to content

Commit

Permalink
categorized columntypes in IDE dropdown and fixed bug in telemetry WS…
Browse files Browse the repository at this point in the history
…L detector for WSL2
  • Loading branch information
fegu committed Jan 11, 2021
1 parent acdaf21 commit d34ef6e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
51 changes: 30 additions & 21 deletions IHP/IDE/SchemaDesigner/View/Columns/Edit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,38 +113,47 @@ instance View EditColumnView where
typeSelector :: Maybe PostgresType -> [Text] -> Html
typeSelector postgresType enumNames = [hsx|
<select id="typeSelector" name="columnType" class="form-control select2-simple">
{option selected "TEXT" "Text"}
{option selected "INT" "Int"}
{option selected "UUID" "UUID"}
{option selected "BOOLEAN" "Bool"}
{option selected "TIMESTAMP WITH TIME ZONE" "Timestamp (UTCTime)"}
{option selected "TIMESTAMP WITHOUT TIME ZONE" "Timestamp (LocalTime)"}
{option selected "REAL" "Float"}
{option selected "DOUBLE PRECISION" "Double"}
{option selected "POINT" "Point"}
{option selected "DATE" "Date"}
{option selected "BYTEA" "Binary"}
{option selected "Time" "Time"}
{option selected "SERIAL" "Serial"}
{option selected "BIGSERIAL" "Bigserial"}
{option selected "SMALLINT" "Int (16bit)"}
{option selected "BIGINT" "Int (64bit)"}
{option selected "JSONB" "JSON"}
{forEach enumNames renderEnumType}
<optgroup label="Common Types">
{option isSelected "TEXT" "Text"}
{option isSelected "INT" "Int"}
{option isSelected "UUID" "UUID"}
{option isSelected "BOOLEAN" "Bool"}
{option isSelected "DATE" "Date / Day"}
{option isSelected "TIMESTAMP WITHOUT TIME ZONE" "Timestamp (LocalTime)"}
{option isSelected "SERIAL" "Serial"}
</optgroup>
{customenums enumNames}
<optgroup label="Other Types">
{option isSelected "TIMESTAMP WITH TIME ZONE" "Timestamp (UTCTime)"}
{option isSelected "REAL" "Float"}
{option isSelected "DOUBLE PRECISION" "Double"}
{option isSelected "POINT" "Point"}
{option isSelected "BYTEA" "Binary"}
{option isSelected "Time" "Time"}
{option isSelected "BIGSERIAL" "Bigserial"}
{option isSelected "SMALLINT" "Int (16bit)"}
{option isSelected "BIGINT" "Int (64bit)"}
{option isSelected "JSONB" "JSON"}
</optgroup>
</select>
|]
where
selected :: Maybe Text
selected = fmap Compiler.compilePostgresType postgresType
isSelected :: Maybe Text
isSelected = fmap Compiler.compilePostgresType postgresType

renderEnumType enum = option selected enum enum
renderEnumType enum = option isSelected enum enum
option :: Maybe Text -> Text -> Text -> Html
option selected value text = case selected of
Nothing -> [hsx|<option value={value}>{text}</option>|]
Just selection ->
if selection == value || selection == value <> "[]"
then [hsx|<option value={value} selected="selected">{text}</option>|]
else [hsx|<option value={value}>{text}</option>|]
customenums [] = [hsx| |]
customenums xs = [hsx| <optgroup label="Custom Enums">
{forEach xs renderEnumType}
</optgroup>
|]

defaultSelector :: Maybe Expression -> Html
defaultSelector defValue = [hsx|
Expand Down
2 changes: 1 addition & 1 deletion IHP/Telemetry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ getTelemetryInfo = do
isWindows :: IO Bool
isWindows = do
p <- TIO.readFile "/proc/version"
pure $ T.isInfixOf "Microsoft" p
pure $ T.isInfixOf "microsoft" (T.toLower p) -- WSL1 is Microsoft, WSL2 is microsoft

-- | The project id is a an anonymous identifier to keep track of distinct projects.
--
Expand Down

0 comments on commit d34ef6e

Please sign in to comment.