From c2945583c6c14987037b171e0355a344e74e1852 Mon Sep 17 00:00:00 2001 From: gabrielgiroe1 Date: Wed, 15 May 2024 12:26:13 +0300 Subject: [PATCH 1/7] Add documentation for passing params to action show page --- docs/3.0/actions.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/3.0/actions.md b/docs/3.0/actions.md index 3f34b10a..54cc2f13 100644 --- a/docs/3.0/actions.md +++ b/docs/3.0/actions.md @@ -103,6 +103,40 @@ def handle(query:, fields:, current_user:, resource:, **args) end ``` +## Passing Params to the Action Show Page +When working with resource index or show views, it's often necessary to pass parameters to an action. + +Example + +Consider the following scenario: + +1. Navigate to http://localhost:3030/admin/resources/users?hey=ya. +2. Attempt to run the dummy action. +You should be able to access the `hey` parameter and retrieve the value `ya`. + +#### Implementation + +To achieve this, we'll utilize the `request.referer` object and extract parameters from the URL. Here is how to do it: + +```ruby +class Action + def fields + field :some_field, as: :hidden, default: -> { + parent_params = URI.parse(request.referer).query.split("&").map { |param| param.split("=")}.to_h.with_indifferent_access + + if parent_params[:hey] == 'ya' + :yes + else + :no + end + } + end +end +``` +Parse the `request.referer` to extract parameters using `URI.parse`. +Split the query string into key-value pairs and convert it into a hash. +Check if the `hey` parameter equals `ya`, and set the default value of `some_field` accordingly. + ## Action responses After an action runs, you may use several methods to respond to the user. For example, you may respond with just a message or with a message and an action. From 1ea4e0ee517adec76031be7c7494171b7ed67d0e Mon Sep 17 00:00:00 2001 From: gabrielgiroe1 Date: Wed, 15 May 2024 12:33:11 +0300 Subject: [PATCH 2/7] Add example --- docs/3.0/actions.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/3.0/actions.md b/docs/3.0/actions.md index 54cc2f13..6b2d5e12 100644 --- a/docs/3.0/actions.md +++ b/docs/3.0/actions.md @@ -106,6 +106,15 @@ end ## Passing Params to the Action Show Page When working with resource index or show views, it's often necessary to pass parameters to an action. +One particular example is when you'd like to populate a field in that action with some particular value based on that param. + +```ruby +class Action + def fields + field :some_field, as: :hidden, default: -> { if previous_param == yes ? :yes : :no} + end +end +``` Example Consider the following scenario: From e20deda4b982b0bf907b4007169530560e68d269 Mon Sep 17 00:00:00 2001 From: Gabi <83423182+gabrielgiroe1@users.noreply.github.com> Date: Wed, 15 May 2024 12:38:01 +0300 Subject: [PATCH 3/7] Update docs/3.0/actions.md Co-authored-by: Adrian Marin --- docs/3.0/actions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/3.0/actions.md b/docs/3.0/actions.md index 6b2d5e12..ee4c58b2 100644 --- a/docs/3.0/actions.md +++ b/docs/3.0/actions.md @@ -125,7 +125,7 @@ You should be able to access the `hey` parameter and retrieve the value `ya`. #### Implementation -To achieve this, we'll utilize the `request.referer` object and extract parameters from the URL. Here is how to do it: +To achieve this, we'll reference the `request.referer` object and extract parameters from the URL. Here is how to do it: ```ruby class Action From 2f53151dacff63426bcb3a68f1e9583cb5034fc8 Mon Sep 17 00:00:00 2001 From: Gabi <83423182+gabrielgiroe1@users.noreply.github.com> Date: Wed, 15 May 2024 12:38:15 +0300 Subject: [PATCH 4/7] Update docs/3.0/actions.md Co-authored-by: Adrian Marin --- docs/3.0/actions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/3.0/actions.md b/docs/3.0/actions.md index ee4c58b2..e544929b 100644 --- a/docs/3.0/actions.md +++ b/docs/3.0/actions.md @@ -104,7 +104,7 @@ end ``` ## Passing Params to the Action Show Page -When working with resource index or show views, it's often necessary to pass parameters to an action. +When navigation to an action from a resource or views, it's sometimes useful to pass parameters to an action. One particular example is when you'd like to populate a field in that action with some particular value based on that param. From cc89abf345a48a1f22920e692fa735de3be88cb9 Mon Sep 17 00:00:00 2001 From: gabrielgiroe1 Date: Wed, 15 May 2024 15:29:56 +0300 Subject: [PATCH 5/7] wip --- docs/3.0/actions.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/3.0/actions.md b/docs/3.0/actions.md index e544929b..a05aaf2b 100644 --- a/docs/3.0/actions.md +++ b/docs/3.0/actions.md @@ -119,7 +119,7 @@ Example Consider the following scenario: -1. Navigate to http://localhost:3030/admin/resources/users?hey=ya. +1. Navigate to https://main.avodemo.com/avo/resources/users?hey=ya. 2. Attempt to run the dummy action. You should be able to access the `hey` parameter and retrieve the value `ya`. @@ -130,9 +130,11 @@ To achieve this, we'll reference the `request.referer` object and extract parame ```ruby class Action def fields + # Accessing the parameters passed from the parent view field :some_field, as: :hidden, default: -> { + # Parsing the request referer to extract parameters parent_params = URI.parse(request.referer).query.split("&").map { |param| param.split("=")}.to_h.with_indifferent_access - + # Checking if the `hei` parameter equals `ya` if parent_params[:hey] == 'ya' :yes else From 4617a78be9e1573111d68e511e07b36282559024 Mon Sep 17 00:00:00 2001 From: gabrielgiroe1 Date: Wed, 15 May 2024 15:33:59 +0300 Subject: [PATCH 6/7] wip --- docs/3.0/actions.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/3.0/actions.md b/docs/3.0/actions.md index a05aaf2b..317d6bb0 100644 --- a/docs/3.0/actions.md +++ b/docs/3.0/actions.md @@ -115,8 +115,6 @@ class Action end end ``` -Example - Consider the following scenario: 1. Navigate to https://main.avodemo.com/avo/resources/users?hey=ya. From 832c9adb01de7b038bbce3c10854fa6a92e4516e Mon Sep 17 00:00:00 2001 From: gabrielgiroe1 Date: Wed, 15 May 2024 16:06:03 +0300 Subject: [PATCH 7/7] wip --- docs/3.0/actions.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/3.0/actions.md b/docs/3.0/actions.md index 317d6bb0..06e5f4b4 100644 --- a/docs/3.0/actions.md +++ b/docs/3.0/actions.md @@ -117,9 +117,11 @@ end ``` Consider the following scenario: -1. Navigate to https://main.avodemo.com/avo/resources/users?hey=ya. -2. Attempt to run the dummy action. -You should be able to access the `hey` parameter and retrieve the value `ya`. +1. Navigate to `https://main.avodemo.com/avo/resources/users`. +2. Add the parameter `hey=ya` to the URL: `https://main.avodemo.com/avo/resources/users?hey=ya` +3. Attempt to run the dummy action. +4. After triggering the action, verify that you can access the `hey` parameter. +5. Ensure that the retrieved value of the `hey` parameter is `ya`. #### Implementation