From 30cbc970de48148de511d0dc60212844eaa38882 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 24 Jul 2022 09:04:15 +0200 Subject: [PATCH] Remove unused. --- src/Form.elm | 99 ------------------------------------------ src/Server/Request.elm | 67 ---------------------------- tests/FormTests.elm | 2 +- 3 files changed, 1 insertion(+), 167 deletions(-) diff --git a/src/Form.elm b/src/Form.elm index 67ceacc7..414ef65e 100644 --- a/src/Form.elm +++ b/src/Form.elm @@ -5,7 +5,6 @@ module Form exposing , renderHtml, renderStyledHtml , FinalForm, withGetMethod , Errors - , parse, runOneOfServerSide, runServerSide , runOneOfServerSideWithServerValidations , AppContext , FieldDefinition(..) @@ -677,34 +676,6 @@ mergeErrors errors1 errors2 = Dict.empty -{-| -} -parse : - AppContext app - -> data - -> Form error (Validation error parsed named) data (Context error data -> view) - -> ( Maybe parsed, FieldErrors error ) -parse app data (Form _ parser _) = - -- TODO Get transition context from `app` so you can check if the current form is being submitted - -- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those? - let - parsed : - { result : ( Validation error parsed named, Dict String (List error) ) - , view : Context error data -> view - , serverValidations : DataSource (List ( String, List error )) - } - parsed = - parser (Just data) thisFormState - - thisFormState : Form.FormState - thisFormState = - app.pageFormState - -- TODO remove hardcoding - |> Dict.get "test" - |> Maybe.withDefault initFormState - in - parsed |> mergeResults |> unwrapValidation - - {-| -} parse2 : AppContext app @@ -747,45 +718,6 @@ insertIfNonempty key values dict = |> Dict.insert key values -{-| -} -runServerSide : - List ( String, String ) - -> Form error (Validation error parsed named) data (Context error data -> view) - -> ( Maybe parsed, FieldErrors error ) -runServerSide rawFormData (Form _ parser _) = - let - parsed : - { result : - ( Validation error parsed named - , Dict String (List error) - ) - , view : Context error data -> view - , serverValidations : DataSource (List ( String, List error )) - } - parsed = - parser Nothing thisFormState - - thisFormState : Form.FormState - thisFormState = - { initFormState - | fields = - rawFormData - |> List.map - (Tuple.mapSecond - (\value -> - { value = value - , status = Form.NotVisited - } - ) - ) - |> Dict.fromList - } - in - parsed - |> mergeResults - |> unwrapValidation - - {-| -} runServerSide2 : List ( String, String ) @@ -906,37 +838,6 @@ unwrapValidation (Pages.Internal.Form.Validation viewField name ( maybeParsed, e ( maybeParsed, errors ) -{-| -} -runOneOfServerSide : - List ( String, String ) - -> List (Form error (Validation error parsed named) data (Context error data -> view)) - -> ( Maybe parsed, FieldErrors error ) -runOneOfServerSide rawFormData parsers = - case parsers of - firstParser :: remainingParsers -> - let - thing : ( Maybe parsed, List ( String, List error ) ) - thing = - runServerSide rawFormData firstParser - |> Tuple.mapSecond - (\errors -> - errors - |> Dict.toList - |> List.filter (Tuple.second >> List.isEmpty >> not) - ) - in - case thing of - ( Just parsed, [] ) -> - ( Just parsed, Dict.empty ) - - _ -> - runOneOfServerSide rawFormData remainingParsers - - [] -> - -- TODO need to pass errors - ( Nothing, Dict.empty ) - - {-| -} runOneOfServerSide2 : List ( String, String ) diff --git a/src/Server/Request.elm b/src/Server/Request.elm index 45eca7bf..967c3ea1 100644 --- a/src/Server/Request.elm +++ b/src/Server/Request.elm @@ -1,7 +1,6 @@ module Server.Request exposing ( Parser , succeed, fromResult, skip - , formData, formDataWithoutServerValidation , rawFormData , method, rawBody, allCookies, rawHeaders, queryParams , requestTime, optionalHeader, expectContentType, expectJsonBody @@ -919,72 +918,6 @@ formDataWithoutServerValidation2 formParsers = ) -{-| -} -formDataWithoutServerValidation : - List (Form.Form error (Validation error combined named) data (Form.Context error data -> viewFn)) - -> Parser (Result { fields : List ( String, String ), errors : Dict String (List error) } combined) -formDataWithoutServerValidation formParsers = - rawFormData - |> andThen - (\rawFormData_ -> - let - ( maybeDecoded, errors ) = - Form.runOneOfServerSide - rawFormData_ - formParsers - in - case ( maybeDecoded, errors |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of - ( Just decoded, Nothing ) -> - succeed (Ok decoded) - - ( _, maybeErrors ) -> - Err - { fields = rawFormData_ - , errors = - maybeErrors - |> Maybe.map List.NonEmpty.toList - |> Maybe.withDefault [] - |> Dict.fromList - } - |> succeed - ) - - -{-| -} -formData : - List (Form.Form error (Validation error combined named) data (Form.Context error data -> viewFn)) - -> Parser (DataSource (Result { fields : List ( String, String ), errors : Dict String (List error) } combined)) -formData formParsers = - rawFormData - |> andThen - (\rawFormData_ -> - let - ( maybeDecoded, errorsDataSource ) = - Form.runOneOfServerSideWithServerValidations - rawFormData_ - formParsers - in - errorsDataSource - |> DataSource.map - (\errors -> - case ( maybeDecoded, errors |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of - ( Just decoded, Nothing ) -> - Ok decoded - - ( _, maybeErrors ) -> - Err - { fields = rawFormData_ - , errors = - maybeErrors - |> Maybe.map List.NonEmpty.toList - |> Maybe.withDefault [] - |> Dict.fromList - } - ) - |> succeed - ) - - {-| -} formData2 : List diff --git a/tests/FormTests.elm b/tests/FormTests.elm index 0b1335bf..ba0890fb 100644 --- a/tests/FormTests.elm +++ b/tests/FormTests.elm @@ -3,7 +3,7 @@ module FormTests exposing (all) import Date exposing (Date) import Dict import Expect -import Form exposing (Form, FormNew) +import Form exposing (FormNew) import Form.Field as Field import Form.Validation as Validation exposing (Validation) import Test exposing (Test, describe, test)