Skip to content

Commit

Permalink
cleanup 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Knuchel committed Jan 2, 2024
1 parent 24d9104 commit 1634271
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 121 deletions.
2 changes: 1 addition & 1 deletion frontend/src/Components/Organisms/TableRow.elm
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ update wrap toggleDropdown showToast now project sources openedDropdown msg mode
sqlQuery =
DbQuery.incomingRows dbSrc.db.kind relations { table = model.table, primaryKey = model.primaryKey }
in
( model, Extra.batch [ toggleDropdown dropdown |> T.send, Ports.runDatabaseQuery (dbPrefix ++ "/" ++ String.fromInt model.id ++ "/" ++ column.pathStr) dbSrc.db.url sqlQuery ] )
( model, Extra.cmdL [ toggleDropdown dropdown |> T.send, Ports.runDatabaseQuery (dbPrefix ++ "/" ++ String.fromInt model.id ++ "/" ++ column.pathStr) dbSrc.db.url sqlQuery ] )
)

else
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Slices/DataExplorer.elm
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ update wrap showToast project sources msg model =
, source = source |> Maybe.orElse model.source |> Maybe.orElse (dbSources |> List.head)
, queryEditor = query |> Maybe.map (.sql >> Editor.init) |> Maybe.withDefault model.queryEditor
}
, Extra.batch
, Extra.cmdL
(Track.dataExplorerOpened sources source query project
:: focusMainInput tab
:: (Maybe.map2 (\src q -> RunQuery src q |> wrap |> T.send) source query |> Maybe.toList)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Slices/DataExplorerDetails.elm
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ init project id source query =
DbQuery.findRow source.db.kind query
in
( { id = id, source = source, query = query, state = StateLoading, expanded = Set.empty }
, Extra.batch [ Ports.runDatabaseQuery (dbPrefix ++ "/" ++ String.fromInt id) source.db.url sqlQuery, Track.dataExplorerDetailsOpened source sqlQuery project ]
, Extra.cmdL [ Ports.runDatabaseQuery (dbPrefix ++ "/" ++ String.fromInt id) source.db.url sqlQuery, Track.dataExplorerDetailsOpened source sqlQuery project ]
)


Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Slices/DataExplorerQuery.elm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ dbPrefix =
init : ProjectInfo -> Id -> DbSourceInfo -> SqlQueryOrigin -> ( Model, Extra msg )
init project id source query =
( { id = id, source = source, query = query, state = StateRunning }
, Extra.batch [ Ports.runDatabaseQuery (dbPrefix ++ "/" ++ String.fromInt id) source.db.url query, Track.dataExplorerQueryOpened source query project ]
, Extra.cmdL [ Ports.runDatabaseQuery (dbPrefix ++ "/" ++ String.fromInt id) source.db.url query, Track.dataExplorerQueryOpened source query project ]
)


Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Components/Slices/ExportDialogBody.elm
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ getOutput wrap urlInfos erd input format =

AllTables ->
if format /= AML && format /= JSON && not sqlExportAllowed then
Extra.batch [ GotOutput "" "plan_limit" |> wrap |> T.send, Track.planLimit .sqlExport (Just erd) ]
Extra.cmdL [ GotOutput "" "plan_limit" |> wrap |> T.send, Track.planLimit .sqlExport (Just erd) ]

else
erd |> Erd.toSchema |> generateTables format |> (\( output, ext ) -> output |> GotOutput (erd.project.name ++ "." ++ ext) |> wrap |> Extra.msg)

CurrentLayout ->
if format /= AML && format /= JSON && not sqlExportAllowed then
Extra.batch [ GotOutput "" "plan_limit" |> wrap |> T.send, Track.planLimit .sqlExport (Just erd) ]
Extra.cmdL [ GotOutput "" "plan_limit" |> wrap |> T.send, Track.planLimit .sqlExport (Just erd) ]

else
erd
Expand Down
16 changes: 0 additions & 16 deletions frontend/src/Libs/List.elm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module Libs.List exposing
, mapBy
, mapByT
, mapByTE
, mapByTL
, mapLast
, mapT
, mapTL
Expand Down Expand Up @@ -338,21 +337,6 @@ mapByT matcher value f list =
|> Tuple.mapSecond (List.filterMap identity)


mapByTL : (a -> b) -> b -> (a -> ( a, List t )) -> List a -> ( List a, List t )
mapByTL matcher value f list =
list
|> List.map
(\a ->
if matcher a == value then
f a

else
( a, [] )
)
|> List.unzip
|> Tuple.mapSecond (List.concatMap identity)


mapByTE : (a -> b) -> b -> (a -> ( a, Extra msg )) -> List a -> ( List a, Extra msg )
mapByTE matcher value f list =
list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PagesComponents.Organization_.Project_.Models.ErdColumnProps exposing (ErdColumnProps, ErdColumnPropsFlat, ErdColumnPropsNested(..), children, createAll, createChildren, filter, find, flatten, getIndex, initAll, insertAt, map, mapAll, mapAt, mapAtTL, member, nest, remove, removeWithIndex, unpackAll)
module PagesComponents.Organization_.Project_.Models.ErdColumnProps exposing (ErdColumnProps, ErdColumnPropsFlat, ErdColumnPropsNested(..), children, createAll, createChildren, filter, find, flatten, getIndex, initAll, insertAt, map, mapAll, mapAt, mapAtTE, member, nest, remove, removeWithIndex, unpackAll)

import Dict
import Libs.List as List
Expand All @@ -10,6 +10,7 @@ import Models.Project.ColumnPath as ColumnPath exposing (ColumnPath)
import Models.Project.ProjectSettings as ProjectSettings exposing (ProjectSettings)
import PagesComponents.Organization_.Project_.Models.ErdRelation exposing (ErdRelation)
import PagesComponents.Organization_.Project_.Models.ErdTable exposing (ErdTable)
import PagesComponents.Organization_.Project_.Updates.Extra as Extra exposing (Extra)


type alias ErdColumnProps =
Expand Down Expand Up @@ -192,10 +193,10 @@ mapAt path f columns =
path |> Maybe.mapOrElse (\p -> columns |> List.map (mapChildren (mapAt (p.tail |> Nel.fromList) f))) (f columns)


mapAtTL : Maybe ColumnPath -> (List ErdColumnProps -> ( List ErdColumnProps, List a )) -> List ErdColumnProps -> ( List ErdColumnProps, List a )
mapAtTL path f columns =
mapAtTE : Maybe ColumnPath -> (List ErdColumnProps -> ( List ErdColumnProps, Extra a )) -> List ErdColumnProps -> ( List ErdColumnProps, Extra a )
mapAtTE path f columns =
-- apply `f` on columns under the given path
path |> Maybe.mapOrElse (\p -> columns |> List.mapTL (mapChildrenT (mapAtTL (p.tail |> Nel.fromList) f))) (f columns)
path |> Maybe.mapOrElse (\p -> columns |> List.mapT (mapChildrenT (mapAtTE (p.tail |> Nel.fromList) f)) |> Tuple.mapSecond Extra.concat) (f columns)


mapAll : (Maybe ColumnPath -> List ErdColumnProps -> List ErdColumnProps) -> List ErdColumnProps -> List ErdColumnProps
Expand Down
50 changes: 30 additions & 20 deletions frontend/src/PagesComponents/Organization_/Project_/Updates.elm
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ import PagesComponents.Organization_.Project_.Updates.Notes exposing (handleNote
import PagesComponents.Organization_.Project_.Updates.Project exposing (createProject, moveProject, triggerSaveProject, updateProject)
import PagesComponents.Organization_.Project_.Updates.ProjectSettings exposing (handleProjectSettings)
import PagesComponents.Organization_.Project_.Updates.Source as Source
import PagesComponents.Organization_.Project_.Updates.Table exposing (goToTable, hideColumn, hideColumns, hideRelatedTables, hideTable, hoverColumn, hoverNextColumn, mapTablePropOrSelected, mapTablePropOrSelectedTL, showAllTables, showColumn, showColumns, showRelatedTables, showTable, showTables, sortColumns, toggleNestedColumn, unHideTable)
import PagesComponents.Organization_.Project_.Updates.Table exposing (goToTable, hideColumn, hideColumns, hideRelatedTables, hideTable, hoverColumn, hoverNextColumn, mapTablePropOrSelected, mapTablePropOrSelectedTE, showAllTables, showColumn, showColumns, showRelatedTables, showTable, showTables, sortColumns, toggleNestedColumn, unHideTable)
import PagesComponents.Organization_.Project_.Updates.TableRow exposing (deleteTableRow, mapTableRowOrSelected, moveToTableRow, showTableRow, unDeleteTableRow)
import PagesComponents.Organization_.Project_.Updates.Tags exposing (handleTags)
import PagesComponents.Organization_.Project_.Updates.Utils exposing (setDirty, setDirtyHCmdM, setDirtyM, setHDirty)
import PagesComponents.Organization_.Project_.Updates.Utils exposing (setDirty, setDirtyM)
import PagesComponents.Organization_.Project_.Updates.VirtualRelation exposing (handleVirtualRelation)
import PagesComponents.Organization_.Project_.Views as Views
import PagesComponents.Organization_.Project_.Views.Modals.NewLayout as NewLayout
Expand Down Expand Up @@ -100,7 +100,7 @@ update urlLayout zone now urlInfos organizations projects msg model =
( model |> mapNavbar (mapSearch (setText search >> setActive 0)), Extra.none )

SearchClicked kind table ->
( model, Extra.batch [ ShowTable table Nothing "search" |> T.send, Track.searchClicked kind model.erd ] )
( model, Extra.cmdL [ ShowTable table Nothing "search" |> T.send, Track.searchClicked kind model.erd ] )

TriggerSaveProject ->
model |> triggerSaveProject urlInfos organizations
Expand Down Expand Up @@ -153,14 +153,24 @@ update urlLayout zone now urlInfos organizations projects msg model =
model |> mapErdMT (hideRelatedTables now id) |> setDirtyM

ToggleTableCollapse id ->
let
collapsed : Bool
collapsed =
model.erd |> Maybe.andThen (Erd.currentLayout >> .tables >> List.findBy .id id) |> Maybe.mapOrElse (.props >> .collapsed) False
in
model
|> mapErdMTM (\erd -> erd |> Erd.mapCurrentLayoutTWithTime now (mapTablesT (mapTablePropOrSelected erd.settings.defaultSchema id (mapProps (setCollapsed (not collapsed))))))
|> setDirtyHCmdM [ ( ToggleTableCollapse id, ToggleTableCollapse id ) ]
|> mapErdMTM
(\erd ->
erd
|> Erd.mapCurrentLayoutTWithTime now
(mapTablesT
(\tables ->
let
collapsed : Bool
collapsed =
tables |> List.findBy .id id |> Maybe.mapOrElse (.props >> .collapsed) False |> not
in
tables |> mapTablePropOrSelected erd.settings.defaultSchema id (mapProps (setCollapsed collapsed))
)
)
)
|> setDirtyM
|> Extra.addHistoryT ( ToggleTableCollapse id, ToggleTableCollapse id )

ShowColumn index column ->
model |> mapErdMT (showColumn now index column) |> setDirtyM
Expand Down Expand Up @@ -240,35 +250,35 @@ update urlLayout zone now urlInfos organizations projects msg model =
model.erd |> Erd.getProjectRefM urlInfos
in
if model.erd |> Erd.canChangeColor then
model |> mapErdMTM (\erd -> erd |> Erd.mapCurrentLayoutTWithTime now (mapTablesT (mapTablePropOrSelectedTL erd.settings.defaultSchema extendToSelected id (\t -> t |> mapPropsT (mapColorT (\c -> ( color, [ ( TableColor t.id c False, TableColor t.id color False ) ] ))))))) |> setDirtyM
model |> mapErdMTM (\erd -> erd |> Erd.mapCurrentLayoutTWithTime now (mapTablesT (mapTablePropOrSelectedTE erd.settings.defaultSchema extendToSelected id (\t -> t |> mapPropsT (mapColorT (\c -> ( color, Extra.history ( TableColor t.id c False, TableColor t.id color False ) ))))))) |> setDirtyM

else
( model, Extra.batch [ ProPlan.colorsModalBody project ProPlanColors ProPlan.colorsInit |> CustomModalOpen |> T.send, Track.planLimit .tableColor model.erd ] )
( model, Extra.cmdL [ ProPlan.colorsModalBody project ProPlanColors ProPlan.colorsInit |> CustomModalOpen |> T.send, Track.planLimit .tableColor model.erd ] )

MoveColumn column position ->
model
|> mapErdMT
|> mapErdMTM
(\erd ->
erd
|> Erd.mapCurrentLayoutTLWithTime now
|> Erd.mapCurrentLayoutTWithTime now
(mapTablesT
(List.mapByTL .id
(List.mapByTE .id
column.table
(mapColumnsT
(ErdColumnProps.mapAtTL
(ErdColumnProps.mapAtTE
(column.column |> ColumnPath.parent)
(\cols ->
(cols |> List.findIndexBy .name (column.column |> Nel.last))
|> Maybe.filter (\pos -> pos /= position)
|> Maybe.map (\pos -> ( cols |> List.moveIndex pos position, [ ( MoveColumn column pos, msg ) ] ))
|> Maybe.withDefault ( cols, [] )
|> Maybe.map (\pos -> ( cols |> List.moveIndex pos position, Extra.history ( MoveColumn column pos, msg ) ))
|> Maybe.withDefault ( cols, Extra.none )
)
)
)
)
)
)
|> setHDirty
|> setDirtyM

HoverTable ( table, col ) on ->
( model |> setHoverTable (B.cond on (Just ( table, col )) (col |> Maybe.map (\_ -> ( table, Nothing )))) |> mapErdM (\e -> e |> Erd.mapCurrentLayoutWithTime now (mapTables (hoverColumn ( table, col ) on e))), Extra.none )
Expand Down Expand Up @@ -360,7 +370,7 @@ update urlLayout zone now urlInfos organizations projects msg model =
model |> handleFindPath message

SchemaAnalysisMsg SAOpen ->
( model |> setSchemaAnalysis (Just { id = Conf.ids.schemaAnalysisDialog, opened = "" }), Extra.batch [ T.sendAfter 1 (ModalOpen Conf.ids.schemaAnalysisDialog), Track.dbAnalysisOpened model.erd ] )
( model |> setSchemaAnalysis (Just { id = Conf.ids.schemaAnalysisDialog, opened = "" }), Extra.cmdL [ T.sendAfter 1 (ModalOpen Conf.ids.schemaAnalysisDialog), Track.dbAnalysisOpened model.erd ] )

SchemaAnalysisMsg (SASectionToggle section) ->
( model |> mapSchemaAnalysisM (mapOpened (\opened -> B.cond (opened == section) "" section)), Extra.none )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PagesComponents.Organization_.Project_.Updates.Extra exposing (Extra, addCmd, addCmdT, batch, cmd, cmdM, cmdT, combine, concat, defaultT, dropHistory, history, historyL, historyM, msg, msgM, msgR, new, newL, newM, none)
module PagesComponents.Organization_.Project_.Updates.Extra exposing (Extra, addCmdT, addHistoryT, cmd, cmdL, cmdM, cmdT, combine, concat, defaultT, dropHistory, history, historyL, historyM, msg, msgM, msgR, new, newL, newM, none)

import Task

Expand All @@ -7,44 +7,44 @@ type alias Extra msg =
( Cmd msg, List ( msg, msg ) )


none : Extra msg
none =
( Cmd.none, [] )


new : Cmd msg -> ( msg, msg ) -> Extra msg
new c h =
( c, [ h ] )


newM : Cmd msg -> Maybe ( msg, msg ) -> Extra msg
newM c hM =
( c, hM |> Maybe.map (\h -> [ h ]) |> Maybe.withDefault [] )
newM c h =
h |> Maybe.map (new c) |> Maybe.withDefault none


newL : Cmd msg -> List ( msg, msg ) -> Extra msg
newL c h =
( c, h )


none : Extra msg
none =
( Cmd.none, [] )


cmd : Cmd msg -> Extra msg
cmd c =
( c, [] )


cmdM : Maybe (Cmd msg) -> Extra msg
cmdM cM =
cM |> Maybe.map (\c -> ( c, [] )) |> Maybe.withDefault none
cmdM c =
c |> Maybe.map cmd |> Maybe.withDefault none


cmdT : ( a, Cmd msg ) -> ( a, Extra msg )
cmdT ( a, c ) =
( a, ( c, [] ) )
cmdL : List (Cmd msg) -> Extra msg
cmdL c =
( Cmd.batch c, [] )


batch : List (Cmd msg) -> Extra msg
batch cs =
( Cmd.batch cs, [] )
cmdT : ( a, Cmd msg ) -> ( a, Extra msg )
cmdT ( a, c ) =
( a, cmd c )


msg : msg -> Extra msg
Expand All @@ -53,13 +53,13 @@ msg m =


msgM : Maybe msg -> Extra msg
msgM mM =
mM |> Maybe.map msg |> Maybe.withDefault none
msgM m =
m |> Maybe.map msg |> Maybe.withDefault none


msgR : Result e msg -> Extra msg
msgR mM =
mM |> Result.map msg |> Result.withDefault none
msgR m =
m |> Result.map msg |> Result.withDefault none


history : ( msg, msg ) -> Extra msg
Expand All @@ -68,38 +68,38 @@ history h =


historyM : Maybe ( msg, msg ) -> Extra msg
historyM hM =
( Cmd.none, hM |> Maybe.map (\h -> [ h ]) |> Maybe.withDefault [] )
historyM h =
h |> Maybe.map history |> Maybe.withDefault none


historyL : List ( msg, msg ) -> Extra msg
historyL hL =
( Cmd.none, hL )


addCmd : Cmd msg -> Extra msg -> Extra msg
addCmd c2 ( c, h ) =
( Cmd.batch [ c, c2 ], h )
historyL h =
( Cmd.none, h )


addCmdT : Cmd msg -> ( a, Extra msg ) -> ( a, Extra msg )
addCmdT c2 ( a, ( c, h ) ) =
( a, ( Cmd.batch [ c, c2 ], h ) )


addHistoryT : ( msg, msg ) -> ( a, Extra msg ) -> ( a, Extra msg )
addHistoryT h2 ( a, ( c, h ) ) =
( a, ( c, h ++ [ h2 ] ) )


dropHistory : Extra msg -> Extra msg
dropHistory ( c, _ ) =
( c, [] )


defaultT : ( a, Maybe (Extra msg) ) -> ( a, Extra msg )
defaultT ( a, extraM ) =
( a, extraM |> Maybe.withDefault none )
defaultT ( a, e ) =
( a, e |> Maybe.withDefault none )


combine : Extra msg -> Extra msg -> Extra msg
combine ( aCmd, aH ) ( bCmd, bH ) =
( Cmd.batch [ aCmd, bCmd ], aH ++ bH )
combine ( cmdA, hA ) ( cmdB, hB ) =
( Cmd.batch [ cmdA, cmdB ], hA ++ hB )


concat : List (Extra msg) -> Extra msg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ handleFindPath msg model =
}
)
|> mapErdM (mapSettings ProjectSettings.fillFindPath)
, Extra.batch [ T.sendAfter 1 (ModalOpen Conf.ids.findPathDialog), Track.findPathOpened model.erd ]
, Extra.cmdL [ T.sendAfter 1 (ModalOpen Conf.ids.findPathDialog), Track.findPathOpened model.erd ]
)

FPToggleSettings ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ setGroupColor now urlInfos index color model =
model |> mapErdMTM (Erd.mapCurrentLayoutTMWithTime now (mapGroupsT (List.mapAtT index (mapColorT (\c -> ( color, Extra.history ( GroupMsg (GSetColor index c), GroupMsg (GSetColor index color) ) )))))) |> Extra.defaultT

else
( model, Extra.batch [ ProPlan.colorsModalBody project ProPlanColors ProPlan.colorsInit |> CustomModalOpen |> T.send, Track.planLimit .tableColor model.erd ] )
( model, Extra.cmdL [ ProPlan.colorsModalBody project ProPlanColors ProPlan.colorsInit |> CustomModalOpen |> T.send, Track.planLimit .tableColor model.erd ] )


saveGroup : Time.Posix -> GroupEdit -> Model x -> ( Model x, Extra Msg )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ handleHelp : HelpMsg -> Model x -> ( Model x, Extra Msg )
handleHelp msg model =
case msg of
HOpen section ->
( { model | help = Just { id = Conf.ids.helpDialog, openedSection = section } }, Extra.batch [ T.sendAfter 1 (ModalOpen Conf.ids.helpDialog), Track.docOpened "navbar_top" model.erd ] )
( { model | help = Just { id = Conf.ids.helpDialog, openedSection = section } }, Extra.cmdL [ T.sendAfter 1 (ModalOpen Conf.ids.helpDialog), Track.docOpened "navbar_top" model.erd ] )

HClose ->
( { model | help = Nothing }, Extra.none )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ createMemo now position urlInfos erd model =
)

else
( model, Extra.batch [ erd |> Erd.getProjectRef urlInfos |> ProPlan.memosModalBody |> CustomModalOpen |> T.send, Track.planLimit .memos (Just erd) ] )
( model, Extra.cmdL [ erd |> Erd.getProjectRef urlInfos |> ProPlan.memosModalBody |> CustomModalOpen |> T.send, Track.planLimit .memos (Just erd) ] )


editMemo : Bool -> Memo -> Model x -> ( Model x, Extra Msg )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ moveProject : ProjectStorage -> Model -> ( Model, Extra Msg )
moveProject storage model =
if model.conf.save then
( model
, Extra.batch
, Extra.cmdL
(model.erd
|> Maybe.map Erd.unpack
|> Maybe.mapOrElse
Expand Down
Loading

0 comments on commit 1634271

Please sign in to comment.