<commit_before>{-
Copyright 2016 SlamData, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}

module SlamData.FileSystem.Dialog.Component where

import SlamData.Prelude

import Data.Array (singleton)

import Halogen as H
import Halogen.Component.ChildPath as CP
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.HTML.Properties as HP
import Halogen.HTML.Properties.ARIA as ARIA

import Network.HTTP.RequestHeader (RequestHeader)

import SlamData.Dialog.Error.Component as Error
import SlamData.FileSystem.Dialog.Download.Component as Download
import SlamData.FileSystem.Dialog.Explore.Component as Explore
import SlamData.FileSystem.Dialog.Mount.Component (MountSettings)
import SlamData.FileSystem.Dialog.Mount.Component as Mount
import SlamData.FileSystem.Dialog.Rename.Component as Rename
import SlamData.FileSystem.Dialog.Share.Component as Share
import SlamData.FileSystem.Dialog.Component.Message (Message(..))
import SlamData.FileSystem.Resource (Resource, Mount)
import SlamData.Monad (Slam)
import SlamData.Workspace.Deck.Component.CSS as CSS

import Utils.Path (DirPath, FilePath)

data Dialog
  = Error String
  | Share String
  | Rename Resource
  | Mount DirPath String (Maybe MountSettings)
  | Download Resource (Array RequestHeader)
  | Explore FilePath

type State = Maybe Dialog

data Query a
  = Show Dialog a
  | RaiseDismiss a
  | QueryRename (Rename.Query Unit) a
  | SaveMount (Maybe Mount → a)
  | HandleChild Message a
  | AddDirsToRename (Array Resource) a

type ChildQuery
  = Error.Query
  ⨁ Share.Query
  ⨁ Rename.Query
  ⨁ Download.Query
  ⨁ Mount.Query
  ⨁ Explore.Query
  ⨁ Const Void

type ChildSlot = Unit ⊹ Unit ⊹ Unit ⊹ Unit ⊹ Unit ⊹ Unit ⊹ Void

component ∷ H.Component HH.HTML Query Unit Message Slam
component =
  H.parentComponent
    { initialState: const Nothing
    , render
    , eval
    , receiver: const Nothing
    }

render ∷ State → H.ParentHTML Query ChildQuery ChildSlot Slam
render state =
  HH.div_
    [ HH.div
        [ HP.classes $ [ CSS.dialogBackdrop ] ⊕ (guard (isNothing state) $> CSS.invisible)
        , HE.onMouseDown (HE.input_ RaiseDismiss)
        , ARIA.hidden $ show $ isNothing state
        ]
        []
    , HH.div
        [ HP.classes $ [] ⊕ (guard (isNothing state) $> CSS.invisible)
        , ARIA.hidden $ show $ isNothing state
        ]
        $ maybe [] (singleton <<< dialog) state
    ]
  where
  dialog = case _ of
    Error str →
      HH.slot' CP.cp1 unit Error.component str (HE.input_ RaiseDismiss)
    Share str →
      HH.slot' CP.cp2 unit Share.component str (HE.input_ RaiseDismiss)
    Rename res →
      HH.slot' CP.cp3 unit Rename.component res (HE.input HandleChild)
    Download resource headers →
      HH.slot' CP.cp4 unit Download.component { resource, headers } (HE.input_ RaiseDismiss)
    Mount parent name settings →
      HH.slot' CP.cp5 unit Mount.component { parent, name, settings } (HE.input HandleChild)
    Explore fp →
      HH.slot' CP.cp6 unit Explore.component fp (HE.input_ RaiseDismiss)

eval ∷ Query ~> H.ParentDSL State Query ChildQuery ChildSlot Message Slam
eval = case _ of
  QueryRename q next → do
    H.query' CP.cp3 unit q
    pure next<commit_msg>Handle more messages from FS dialogs<commit_after>{-
Copyright 2016 SlamData, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}

module SlamData.FileSystem.Dialog.Component where

import SlamData.Prelude

import Data.Array (singleton)

import Halogen as H
import Halogen.Component.ChildPath as CP
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.HTML.Properties as HP
import Halogen.HTML.Properties.ARIA as ARIA

import Network.HTTP.RequestHeader (RequestHeader)

import SlamData.Dialog.Error.Component as Error
import SlamData.FileSystem.Dialog.Download.Component as Download
import SlamData.FileSystem.Dialog.Explore.Component as Explore
import SlamData.FileSystem.Dialog.Mount.Component (MountSettings)
import SlamData.FileSystem.Dialog.Mount.Component as Mount
import SlamData.FileSystem.Dialog.Rename.Component as Rename
import SlamData.FileSystem.Dialog.Share.Component as Share
import SlamData.FileSystem.Dialog.Component.Message (Message(..))
import SlamData.FileSystem.Resource (Resource, Mount)
import SlamData.Monad (Slam)
import SlamData.Workspace.Deck.Component.CSS as CSS

import Utils.Path (DirPath, FilePath)

data Dialog
  = Error String
  | Share String
  | Rename Resource
  | Mount DirPath String (Maybe MountSettings)
  | Download Resource (Array RequestHeader)
  | Explore FilePath

type State = Maybe Dialog

data Query a
  = Show Dialog a
  | RaiseDismiss a
  | QueryRename (Rename.Query Unit) a
  | SaveMount (Maybe Mount → a)
  | HandleChild Message a
  | AddDirsToRename (Array Resource) a

type ChildQuery
  = Error.Query
  ⨁ Share.Query
  ⨁ Rename.Query
  ⨁ Download.Query
  ⨁ Mount.Query
  ⨁ Explore.Query
  ⨁ Const Void

type ChildSlot = Unit ⊹ Unit ⊹ Unit ⊹ Unit ⊹ Unit ⊹ Unit ⊹ Void

component ∷ H.Component HH.HTML Query Unit Message Slam
component =
  H.parentComponent
    { initialState: const Nothing
    , render
    , eval
    , receiver: const Nothing
    }

render ∷ State → H.ParentHTML Query ChildQuery ChildSlot Slam
render state =
  HH.div_
    [ HH.div
        [ HP.classes $ [ CSS.dialogBackdrop ] ⊕ (guard (isNothing state) $> CSS.invisible)
        , HE.onMouseDown (HE.input_ RaiseDismiss)
        , ARIA.hidden $ show $ isNothing state
        ]
        []
    , HH.div
        [ HP.classes $ [] ⊕ (guard (isNothing state) $> CSS.invisible)
        , ARIA.hidden $ show $ isNothing state
        ]
        $ maybe [] (singleton <<< dialog) state
    ]
  where
  dialog = case _ of
    Error str →
      HH.slot' CP.cp1 unit Error.component str (HE.input_ RaiseDismiss)
    Share str →
      HH.slot' CP.cp2 unit Share.component str (HE.input HandleChild)
    Rename res →
      HH.slot' CP.cp3 unit Rename.component res (HE.input HandleChild)
    Download resource headers →
      HH.slot' CP.cp4 unit Download.component { resource, headers } (HE.input HandleChild)
    Mount parent name settings →
      HH.slot' CP.cp5 unit Mount.component { parent, name, settings } (HE.input HandleChild)
    Explore fp →
      HH.slot' CP.cp6 unit Explore.component fp (HE.input HandleChild)

eval ∷ Query ~> H.ParentDSL State Query ChildQuery ChildSlot Message Slam
eval = case _ of
  QueryRename q next → do
    H.query' CP.cp3 unit q
    pure next
{'fraction_non_alphanumeric': 0.07941455481772598, 'fraction_numerical': 0.004065591543569589, 'mean_word_length': 3.5054945054945055, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2485368', 'n_tokens_mistral': 2321, 'n_tokens_neox': 2245, 'n_words': 794}