Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Confirmation dialog adjustments #1331

Closed
wants to merge 4 commits into from

Conversation

Blackbaud-SteveBrush
Copy link
Member

@Blackbaud-SteveBrush Blackbaud-SteveBrush commented Nov 30, 2017

Addresses:

#1330
#1329
#1328
#1324
#1323

  • Created a new event emitter named confirmed which returns an object representing the button clicked.
  • Created a separate config type for the buttons array (so that the buttonType property isn't exposed to the consumer)
  • Updated docs to "deprecate" the closed emitter.


this.confirmService.open(config).closed.subscribe((result: string) => {
this.action = 'You clicked \'' + result + '\'';
instance.confirmed.subscribe((result: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a strong-type we can use for result?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emitter passes a strongly-typed response, but the consumer can use any if they like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very true, I just don't want to encourage it in demo code. Wouldn't using the strongly-typed response be considered a best practice? I know for a fact that people look to the demo code as "the correct way to do things." In that case, it would be nice if the demo code represented best practices.

@@ -0,0 +1,4 @@
export interface SkyConfirmationDialogButtonConfig {
text?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be required since we probably aren't going to have buttons with no text?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are defaults for each of these properties, so they can remain optional for now.

@@ -0,0 +1 @@
export type SkyConfirmationDialogButtonAction = 'ok' | 'yes' | 'no' | 'cancel';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of our confirmation dialogs is going to have a Delete button so I'm a bit torn about these specific actions, but we could easily use something like 'yes' for our usage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These more-or-less serve as "ids" for the various buttons. Open to alternatives...

export class SkyConfirmationDialogButton {
public text?: string;
public action?: SkyConfirmationDialogButtonAction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I feel like text and action are likely things that you'd consider required. Buttons need text, and they need some sort of action associated with them for when they are clicked.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those optional flags were a hold-over from the previous configuration implementation. Good catch.

buttons: [ { text: '1' }, { text: '2' }, { text: '3', autofocus: true } ]
};
buttons: [
{ text: '1' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm setting up buttons like this, how do I know the action that would be associated with each button? Is that set based on type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's based on the number of buttons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which corresponds to the type, yes.

} as SkyConfirmationDialogButton;
}

this.confirmed.emit(result.data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel that confirmed and closed should be completed after emitting a value. They should never fire more than once and should help reduce memory leaks from Subscriptions left open.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.


@Injectable()
export class SkyConfirmationDialogInstance {
public closed = new EventEmitter<string>();
public confirmed = new EventEmitter<SkyConfirmationDialogButton>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know why this exists since you're trying to deprecate closed. I do wonder if people will wonder if this will only fire if the user clicked the 'ok' or 'yes' actions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose this naming convention because it mirror's vanilla JavaScript's confirm("some message") method. We can investigate if there's a better word for it...

@Blackbaud-SteveBrush
Copy link
Member Author

Closing for now; will create a new pull request shortly.

@Blackbaud-SteveBrush Blackbaud-SteveBrush deleted the confirmation-dialog-adjustments branch January 26, 2018 16:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants