Skip to content

Commit

Permalink
[PLAY-1490] Dialog disable rails - Remove duplicate data (#3646)
Browse files Browse the repository at this point in the history
**What does this PR do?** A clear and concise description with your
runway ticket url.
Runway https://runway.powerhrg.com/backlog_items/PLAY-1490

The OG PR #3599

This was reverted because of multiple data declorations

```<%= pb_rails("button", props: { type: "button", data: {"close-dialog": "#{object.id}" }, id: object.cancel_button_id, variant: "link", data: cancel_loading}) do %>```

**But this is how it works**

Adds a prop to the dialog kit that makes the buttons go into a "loading state" when pressed

[screencast-127.0.0.1_3000-2024.08.15-14_05_54.webm](https://github.com/user-attachments/assets/6c9ec27b-d8a8-43cb-8443-fcb0865b2e94)

**How to test?** Steps to confirm the desired behavior:
1. Go to https://pr3646.playbook.beta.gm.powerapp.cloud/kits/dialog/rails#loading
2. Click Open Dialog
3. click Okay
4. Notice the loading state of the buttons and admire how nice they communicate that something is loading and that you can't press the buttons again
  • Loading branch information
markdoeswork authored Sep 6, 2024
1 parent ff15779 commit 126b254
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 4 deletions.
5 changes: 4 additions & 1 deletion playbook/app/pb_kits/playbook/pb_dialog/dialog.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
<% if object.cancel_button && object.confirm_button %>
<%= pb_rails("dialog/dialog_footer", props: {
cancel_button: object.cancel_button,
cancel_button_id: object.cancel_button_id,
confirm_button: object.confirm_button,
id: object.id
confirm_button_id: object.confirm_button_id,
id: object.id,
loading: object.loading
}) %>
<% end %>
Expand Down
3 changes: 3 additions & 0 deletions playbook/app/pb_kits/playbook/pb_dialog/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ class Dialog < Playbook::KitBase
prop :should_close_on_overlay_click, type: Playbook::Props::Boolean, default: true
prop :title
prop :text
prop :loading
prop :confirm_button
prop :confirm_button_id
prop :cancel_button
prop :cancel_button_id
prop :status, type: Playbook::Props::Enum,
values: ["info", "caution", "delete", "error", "success", "default", ""],
default: ""
Expand Down
21 changes: 21 additions & 0 deletions playbook/app/pb_kits/playbook/pb_dialog/dialogHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ const dialogHelper = () => {
const closeTrigger = document.querySelectorAll("[data-close-dialog]");
const dialogs = document.querySelectorAll(".pb_dialog_rails")

const loadingButton = document.querySelector('[data-disable-with="Loading"]');
if (loadingButton) {
loadingButton.addEventListener("click", function() {
const okayLoadingButton = document.querySelector('[data-disable-with="Loading"]');
const cancelButton = document.querySelector('[data-disable-cancel-with="Loading"]');
let currentClass = okayLoadingButton.className;
let cancelClass = cancelButton ? cancelButton.className : "";

let newClass = currentClass.replace("_enabled", "_disabled_loading");
let newCancelClass = cancelClass.replace("_enabled", "_disabled");

// Disable the buttons
okayLoadingButton.disabled = true;
if (cancelButton) cancelButton.disabled = true;

okayLoadingButton.className = newClass;
if (cancelButton) cancelButton.className = newCancelClass;
});
}


openTrigger.forEach((open) => {
open.addEventListener("click", () => {
var openTriggerData = open.dataset.openDialog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
<% if object.confirm_button && object.cancel_button %>
<div class="dialog-pseudo-footer"></div>
<%= pb_rails("flex", props: { classname:object.classname, spacing:"between", padding_x:"sm", padding:"sm", padding_bottom:"sm" }) do %>
<%= pb_rails("button", props: { type: "submit", id: object.confirm_button_id }) do %>
<%= pb_rails("button", props: { type: "submit", id: object.confirm_button_id, data: loading_data,
}) do %>
<%= object.confirm_button %>
<% end %>
<%= pb_rails("button", props: { type: "button", data: {"close-dialog": "#{object.id}" }, id: object.cancel_button_id, variant: "link"}) do %>
<%= pb_rails("button", props: { type: "button", data: {"close-dialog": "#{object.id}", "disable_cancel_with": cancel_loading }, id: object.cancel_button_id, variant: "link" }) do %>
<%= object.cancel_button %>
<% end %>
<% end %>
Expand Down
11 changes: 10 additions & 1 deletion playbook/app/pb_kits/playbook/pb_dialog/dialog_footer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ module Playbook
module PbDialog
class DialogFooter < Playbook::KitBase
prop :cancel_button
prop :cancel_button_id
prop :confirm_button
prop :confirm_button_id
prop :cancel_button_id
prop :loading

def classname
generate_classname("dialog_footer")
end

def cancel_loading
loading ? "Loading" : ""
end

def loading_data
loading ? { disable_with: "Loading" } : {}
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= pb_rails("button", props: { text: "Open Dialog", data: {"open-dialog": "dialog-loading"} }) %>
<%= pb_rails("dialog", props: {
id:"dialog-loading",
size: "sm",
title: "Loading Exmaple",
text: "Make a loading request?",
cancel_button: "Cancel Button",
cancel_button_id: "cancel-button-loading",
confirm_button: "Okay",
confirm_button_id: "confirm-button-loading",
loading: true,
}) %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Pressing the "Okay" button will trigger a loading state where the button content is replaced by a spinner icon and both buttons are disabled.

Currently, the loading state cannot be undone and will require a page refresh to reset the dialog.
1 change: 1 addition & 0 deletions playbook/app/pb_kits/playbook/pb_dialog/docs/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ examples:
- dialog_stacked_alert: Stacked Button Alert
- dialog_full_height: Full Height
- dialog_full_height_placement: Full Height Placement
- dialog_loading: Loading


react:
Expand Down

0 comments on commit 126b254

Please sign in to comment.