Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Workflow Button element #136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ import { Modal, Section, bold, link } from 'slack-block-builder';

`Elements` – UI elements that are used to capture user interaction.

`Bits` – These are composition objects and other bits and pieces from Slack's docs. Included are `Attachment`, `Options`, `OptionGroup`, and `ConfirmationDialog`. They felt like they were deserving of their own category.
`Bits` – These are composition objects and other bits and pieces from Slack's docs. Included are `Attachment`, `Options`, `OptionGroup`,`ConfirmationDialog`, and `Workflow`. They felt like they were deserving of their own category.

`Utilities` – A group of utility functions. See [Utility Functions](#utility-functions).

Expand Down Expand Up @@ -158,9 +158,11 @@ Below is a list of supported objects and how to access them in **Block Builder**
| Select Menus | Element | :white_check_mark: | `Elements.[Type]Select()`
| Multi-Select Menus | Element | :white_check_mark: | `Elements.[Type]MultiSelect()`
| URL Input | Element | :white_check_mark: | `Elements.NumberInput()`
| Workflow Button | Element | :white_check_mark: | `Elements.WorkflowButton()`
| Option | Composition Object | :white_check_mark: | `Bits.Option()`
| Confirm Dialog | Composition Object | :white_check_mark: | `Bits.ConfirmationDialog()`
| Option Group | Composition Object | :white_check_mark: | `Bits.OptionGroup()`
| Workflow | Composition Object | :white_check_mark: | `Bits.Workflow()`
| Attachment | Legacy Feature | :white_check_mark: | `Bits.Attachment()`

### Creating a Simple Interactive Message
Expand Down
4 changes: 4 additions & 0 deletions docs-generator/mappers/map-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default (type: string, capitalize = false): string => {
return type.replace('Builder', '');
}

if (type === 'TriggerObject') {
return 'TriggerObject';
}

if (type === 'T') {
return 'T'; // Means it is a generic and should be replaced when class mapped with methods
}
Expand Down
2 changes: 2 additions & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@
* [URL Input](elements/url-input.md "Block Builder – URL Input – Maintainable JavaScript Code for Slack Block Kit")
* [User Multi-Select](elements/user-multi-select.md "Block Builder – User Multi-Select – Maintainable JavaScript Code for Slack Block Kit")
* [User Select](elements/user-select.md "Block Builder – User Select – Maintainable JavaScript Code for Slack Block Kit")
* [Workflow Button](elements/workflow-button.md "Block Builder – Workflow Button – Maintainable JavaScript Code for Slack Block Kit")

* **Bit References**
* [Introduction](bits/introduction.md "Block Builder – Bits – Introduction – Maintainable JavaScript Code for Slack Block Kit")
* [Attachment](bits/attachment.md "Block Builder – Attachment – Maintainable JavaScript Code for Slack Block Kit")
* [Confirmation Dialog](bits/confirmation-dialog.md "Block Builder – Confirmation Dialog – Maintainable JavaScript Code for Slack Block Kit")
* [Option](bits/option.md "Block Builder – Option – Maintainable JavaScript Code for Slack Block Kit")
* [Option Group](bits/option-group.md "Block Builder – Option Group – Maintainable JavaScript Code for Slack Block Kit")
* [Workflow](bits/workflow.md "Block Builder – Workflow – Maintainable JavaScript Code for Slack Block Kit")

* **Component References**
* [Paginator](components/paginator.md "Block Builder – Paginator – Maintainable JavaScript Code for Slack Block Kit")
Expand Down
2 changes: 1 addition & 1 deletion docs/bits/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is the one category of objects that differs from those laid out in the [Slack Block Kit](https://api.slack.com/block-kit) documentation.

The `Bits` object in **Block Builder** contains various bits and pieces from the Slack Block Kit documentation. More specifically, **Attachment**, **Options**, **Option Groups**, and **Confirmation Dialogs**.
The `Bits` object in **Block Builder** contains various bits and pieces from the Slack Block Kit documentation. More specifically, **Attachment**, **Options**, **Option Groups**, **Confirmation Dialogs**, and **Workflow**.

### Accessing Bits in Block Builder

Expand Down
49 changes: 49 additions & 0 deletions docs/bits/workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow

?> **Note:** This document is a reference to the `WorkflowBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the Workflow docs](https://api.slack.com/reference/block-kit/composition-objects#workflow) on Slack's doc site.

### Creating an Instance

The function that creates a new instance of `WorkflowBuilder` is available as both a top-level import and as a member of its 'category', `Bits`:

```javascript
import { Workflow } from 'slack-block-builder';

const myObj = Workflow(params?);

```

```javascript
import { Bits } from 'slack-block-builder';

const myObj = Bits.Workflow(params?);
```

### Params

Each instance of the `WorkflowBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer:

`trigger` – *TriggerObject*


?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below.

### Setter Methods

All setter methods return `this`, the instance of `WorkflowBuilder` on which it is called.

```javascript
WorkflowBuilder.trigger(TriggerObject);
```

A trigger object that contains information about a workflow's trigger.

### Other Methods

The `WorkflowBuilder` object also has other methods available:

```javascript
WorkflowBuilder.end();
```

Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object.
78 changes: 78 additions & 0 deletions docs/elements/workflow-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# WorkflowButton

?> **Note:** This document is a reference to the `WorkflowButtonBuilder` object in **Block Builder**. For more information on how this carries over to the Slack API, view the [the WorkflowButton docs](https://api.slack.com/reference/block-kit/block-elements#workflow_button) on Slack's doc site.

### Creating an Instance

The function that creates a new instance of `WorkflowButtonBuilder` is available as both a top-level import and as a member of its 'category', `Elements`:

```javascript
import { WorkflowButton } from 'slack-block-builder';

const myObj = WorkflowButton(params?);

```

```javascript
import { Elements } from 'slack-block-builder';

const myObj = Elements.WorkflowButton(params?);
```

### Params

Each instance of the `WorkflowButtonBuilder` object has chainable setter methods for the object's properties. However, properties with primitive values can optionally be passed to the instantiating function, should you prefer:

`accessibilityLabel` – *String*

`actionId` – *String*

`text` – *String*


?> **Note:** For an explanation of any one of the parameters, see its corresponding setter method below.

### Setter Methods

All setter methods return `this`, the instance of `WorkflowButtonBuilder` on which it is called.

```javascript
WorkflowButtonBuilder.danger(boolean?);
```

For a button element, this changes the color to red. For confirmation dialogs, this sets the main button in the bottom right corner to red, indicating that an action is potentially destructive. Defaults to `true`.
```javascript
WorkflowButtonBuilder.primary(boolean?);
```

For a button element, this changes the color to green. For confirmation dialogs, this sets the main button in the bottom right corner to green, which is meant to confirm the action. Defaults to `true`.
```javascript
WorkflowButtonBuilder.accessibilityLabel(string);
```

A label for longer descriptive text about a button element. This label will be read out by screen readers instead of the button text object.
```javascript
WorkflowButtonBuilder.actionId(string);
```

Sets a string to be an identifier for the action taken by the user. It is sent back to your app in the interaction payload when the element is interacted or when the view is submitted.
```javascript
WorkflowButtonBuilder.text(string);
```

Sets the text displayed for buttons, headers, confirmation dialogs, sections, context blocks, and options.
```javascript
WorkflowButtonBuilder.workflow(Workflow);
```

Sets a workflow object that contains details about the workflow that will run when the button is clicked.

### Other Methods

The `WorkflowButtonBuilder` object also has other methods available:

```javascript
WorkflowButtonBuilder.end();
```

Performs no alterations to the object on which it is called. It is meant to simulate a closing HTML tag for those who prefer to have an explicit end declared for an object.
2 changes: 2 additions & 0 deletions docs/support.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ Below is a list of supported components and how to access them in **Block Builde
| Select Menus | Element | **Yes** | `Elements.[Type]Select()` |
| Multi-Select Menus | Element | **Yes** | `Elements.[Type]MultiSelect()` |
| URL Input | Element | **Yes** | `Elements.URLInput()` | [View Docs](/elements/url-input.md)
| Workflow Button | Element | **Yes** | `Elements.WorkflowButton()` | [View Docs](/elements/workflow-button.md)
| Attachment | Legacy Feature | **Yes** | `Bits.Attachment()` | [View Docs](/bits/attachment.md)
| Confirmation Dialog | Composition Object | **Yes** | `Bits.ConfirmationDialog()` | [View Docs](/bits/confirmation-dialog.md)
| Option | Composition Object | **Yes** | `Bits.Option()` | [View Docs](/bits/option.md)
| Option Group | Composition Object | **Yes** | `Bits.OptionGroup()` | [View Docs](/bits/option-group.md)
| Workflow | Composition Object | **Yes** | `Bits.Workflow()` | [View Docs](/bits/workflow.md)

15 changes: 15 additions & 0 deletions src/bits/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AttachmentBuilder, AttachmentParams } from './attachment';
import { ConfirmationDialogBuilder, ConfirmationDialogParams } from './confirmation-dialog';
import { OptionBuilder, OptionParams } from './option';
import { OptionGroupBuilder, OptionGroupParams } from './option-group';
import { WorkflowBuilder, WorkflowParams } from './workflow';

export type {
AttachmentBuilder,
Expand All @@ -14,6 +15,8 @@ export type {
OptionParams,
OptionGroupBuilder,
OptionGroupParams,
WorkflowBuilder,
WorkflowParams,
};

/**
Expand Down Expand Up @@ -70,11 +73,23 @@ export function OptionGroup(params?: OptionGroupParams): OptionGroupBuilder {
return new OptionGroupBuilder(params);
}

/**
* @param {Object} [params] Parameters passed to the constructor.
* @param {string} [params.trigger] Sets the trigger object that contains information about a workflow's trigger.
*
* {@link https://api.slack.com/reference/block-kit/composition-objects#workflow|View in Slack API Documentation}
*/

export function Workflow(params?: WorkflowParams): WorkflowBuilder {
return new WorkflowBuilder(params);
}

const bits = {
Attachment,
ConfirmationDialog,
Option,
OptionGroup,
Workflow,
};

// Strange export. I know. For IDE highlighting purposes.
Expand Down
36 changes: 36 additions & 0 deletions src/bits/workflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { BitBuilderBase } from '../internal/base';
import { SlackDto } from '../internal/dto';
import { applyMixins, getTriggerObject } from '../internal/helpers';
import {
End,
Trigger,
} from '../internal/methods';
import type { TriggerObject } from '../internal/objects';

export interface WorkflowParams {
trigger?: TriggerObject;
}

export interface WorkflowBuilder extends End,
Trigger {
}

/**
* @@link https://api.slack.com/reference/block-kit/composition-objects#workflow
* @@displayName Workflow
*/

export class WorkflowBuilder extends BitBuilderBase {
/** @internal */

public build(): Readonly<SlackDto> {
return this.getResult(SlackDto, {
trigger: getTriggerObject(this.props.trigger),
});
}
}

applyMixins(WorkflowBuilder, [
End,
Trigger,
]);
18 changes: 18 additions & 0 deletions src/elements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { TimePickerBuilder, TimePickerParams } from './timepicker';
import { URLInputBuilder, URLInputParams } from './url-input';
import { UserMultiSelectBuilder, UserMultiSelectParams } from './user-multi-select';
import { UserSelectBuilder, UserSelectParams } from './user-select';
import { WorkflowButtonBuilder, WorkflowButtonParams } from './workflow-button';

export type {
ButtonBuilder,
Expand Down Expand Up @@ -71,6 +72,8 @@ export type {
UserSelectParams,
FileInputBuilder,
FileInputParams,
WorkflowButtonBuilder,
WorkflowButtonParams,
};

/**
Expand Down Expand Up @@ -375,6 +378,20 @@ export function UserSelect(params?: UserSelectParams): UserSelectBuilder {
return new UserSelectBuilder(params);
}

/**
* @param {Object} [params] Parameters passed to the constructor.
* @param {string} [params.accessibilityLabel] Sets a longer descriptive text that will be read out by screen readers instead of the button text object.
* @param {string} [params.actionId] Sets a string to be an identifier for the source of an action in interaction payloads.
* @param {string} [params.text] Sets the display text for the button.
* @param {string} [params.trigger] Sets a trigger object that contains information about a workflow's trigger.
*
* {@link https://api.slack.com/reference/block-kit/block-elements#workflow_button|View in Slack API Documentation}
*/

export function WorkflowButton(params?: WorkflowButtonParams): WorkflowButtonBuilder {
return new WorkflowButtonBuilder(params);
}

const elements = {
Button,
ChannelMultiSelect,
Expand All @@ -399,6 +416,7 @@ const elements = {
UserMultiSelect,
UserSelect,
FileInput,
WorkflowButton,
};

// Strange export. I know. For IDE highlighting purposes.
Expand Down
55 changes: 55 additions & 0 deletions src/elements/workflow-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ElementBuilderBase } from '../internal/base';
import { ElementType } from '../internal/constants';
import { SlackElementDto } from '../internal/dto';
import { applyMixins, getPlainTextObject, getBuilderResult } from '../internal/helpers';
import {
AccessibilityLabel,
ActionId,
Danger,
End,
Primary,
Text,
Workflow,
} from '../internal/methods';

export interface WorkflowButtonParams {
accessibilityLabel?: string;
actionId?: string;
text?: string;
}

export interface WorkflowButtonBuilder extends AccessibilityLabel,
ActionId,
Danger,
End,
Primary,
Text,
Workflow {
}

/**
* @@link https://api.slack.com/reference/block-kit/block-elements#workflow_button
* @@displayName WorkflowButton
*/

export class WorkflowButtonBuilder extends ElementBuilderBase {
/** @internal */

public build(): Readonly<SlackElementDto> {
return this.getResult(SlackElementDto, {
type: ElementType.WorkflowButton,
text: getPlainTextObject(this.props.text),
workflow: getBuilderResult(this.props.workflow),
});
}
}

applyMixins(WorkflowButtonBuilder, [
AccessibilityLabel,
ActionId,
Danger,
End,
Primary,
Text,
Workflow,
]);
1 change: 1 addition & 0 deletions src/internal/constants/element-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export enum ElementType {
EmailInput = 'email_text_input',
NumberInput = 'number_input',
FileInput = 'file_input',
WorkflowButton = 'workflow_button',
}
3 changes: 3 additions & 0 deletions src/internal/constants/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@ export enum Prop {
VideoUrl = 'videoUrl',
MaxFiles = 'maxFiles',
Filetypes = 'filetypes',
Workflow = 'workflow',
Trigger = 'trigger',
CustomizableInputParameters = 'customizableInputParameters',
}
Loading