<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.Workspace.Deck.Dialog.Rename.Component where

import SlamData.Prelude

import Halogen as H
import Halogen.CustomProps as CP
import Halogen.HTML.Events as HE
import Halogen.HTML as HH
import Halogen.HTML.Properties as HP
import Halogen.HTML.Properties.ARIA as ARIA
import Halogen.Themes.Bootstrap3 as B

import SlamData.Monad (Slam)

type State = { newName ∷ String }

data Query a = SetNewName String a | Rename String a | Dismiss a

comp ∷ H.Component State Query Slam
comp = H.component { render, eval }

render ∷ State → H.ComponentHTML Query
render { newName } =
  HH.div [ HP.classes [ HH.ClassName "deck-dialog-rename" ] ]
    [ HH.h4_ [ HH.text  "Rename deck" ]
    , HH.div [ HP.classes [ HH.ClassName "deck-dialog-body" ] ]
        [ HH.form
          [ CP.nonSubmit ]
          [ HH.div
              [ HP.classes [ B.formGroup ]
              ]
              [ HH.input
                  [ HE.onValueInput $ HE.input SetNewName
                  , HP.value newName
                  , HP.type_ HP.InputText
                  , HP.classes [ B.formControl ]
                  , ARIA.label "Deck name"
                  ]
              ]
          ]
        ]
    , HH.div [ HP.classes [ HH.ClassName "deck-dialog-footer" ] ]
        [ HH.button
            [ HP.classes [ B.btn, B.btnDefault ]
            , HE.onClick (HE.input_ Dismiss)
            , HP.type_ HP.ButtonButton
            ]
            [ HH.text "Dismiss" ]
        , HH.button
            [ HP.classes [ B.btn, B.btnPrimary ]
            , HE.onClick (HE.input_ $ Rename newName)
            , HP.type_ HP.ButtonButton
            ]
            [ HH.text "Save"
            ]
        ]
    ]

eval ∷ Query ~> H.ComponentDSL State Query Slam
eval (SetNewName string next) = H.modify (_ { newName = string }) $> next
eval (Rename string next) = pure next
eval (Dismiss next) = pure next<commit_msg>Update Dialog.Rename component<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.Workspace.Deck.Dialog.Rename.Component where

import SlamData.Prelude

import Halogen as H
import Halogen.HTML.Events as HE
import Halogen.HTML as HH
import Halogen.HTML.Properties as HP
import Halogen.HTML.Properties.ARIA as ARIA
import Halogen.Themes.Bootstrap3 as B

import SlamData.Monad (Slam)
import Utils.DOM as DOM

type State = { name ∷ String }

data Query a
  = UpdateName String a
  | PreventDefault DOM.Event a
  | Save a
  | Cancel a

data Message
  = Dismiss
  | Rename String

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

render ∷ State → H.ComponentHTML Query
render { name } =
  HH.div [ HP.classes [ HH.ClassName "deck-dialog-rename" ] ]
    [ HH.h4_ [ HH.text  "Rename deck" ]
    , HH.div [ HP.classes [ HH.ClassName "deck-dialog-body" ] ]
        [ HH.form
          [ HE.onSubmit (HE.input PreventDefault) ]
          [ HH.div
              [ HP.classes [ B.formGroup ]
              ]
              [ HH.input
                  [ HE.onValueInput (HE.input UpdateName)
                  , HP.value name
                  , HP.type_ HP.InputText
                  , HP.classes [ B.formControl ]
                  , ARIA.label "Deck name"
                  ]
              ]
          ]
        ]
    , HH.div [ HP.classes [ HH.ClassName "deck-dialog-footer" ] ]
        [ HH.button
            [ HP.classes [ B.btn, B.btnDefault ]
            , HE.onClick (HE.input_ Cancel)
            , HP.type_ HP.ButtonButton
            ]
            [ HH.text "Dismiss" ]
        , HH.button
            [ HP.classes [ B.btn, B.btnPrimary ]
            , HE.onClick (HE.input_ Save)
            , HP.type_ HP.ButtonButton
            ]
            [ HH.text "Save"
            ]
        ]
    ]

eval ∷ Query ~> H.ComponentDSL State Query Message Slam
eval = case _ of
  UpdateName name next →
    H.modify _ { name = name } $> next
  PreventDefault ev next →
    H.liftEff (DOM.preventDefault ev) $> next
  Save next → do
    H.raise ∘ Rename =<< H.gets _.name
    pure next
  Cancel next →
    H.raise Dismiss $> next
{'fraction_non_alphanumeric': 0.0894897182025895, 'fraction_numerical': 0.003808073115003808, 'mean_word_length': 2.0434530706836616, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '133914', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1557, 'n_words': 506}