Commit 17a1160
authored
feat: new MessageActions component (#2543)
## The Problem(s)
`MessageActions`/`MessageOptions`/`MessageActionsBox` are a poorly
designed set of components which we were trying to patch over the time
with things like `CustomMessageActionsList` but with each new patchy
addition, the component set got heavier and worse to navigate in when it
came to customization.
- `messageActions` prop on `MessageList` and `VirtualizedMessageList`
components allow for key/handler customization:
```tsx
{ "Custom Action": () => doThing() }
```
Solution like this falls face first when integrators need to access
`MessageContext` or use translations for different languages (the key is
used as button text).
- Solution to patch those shortcomings was to introduce
`CustomMessageActionsList` which allows to render custom buttons within
actions dropdown but... when buttons are rendered conditionally, the
"..." is still rendered and upon clicking on it, it opens up an empty
actions dropdown. This solution also does not allow to adjust "quick
actions" (like reply or react).
## Steps Taken
1. pre-define default set of actions with buttons as components with own
logic and click handlers, separate into "quick" and "dropdown" types
2. define default filter which takes care of user capabilities and
whether the actions are allowed within reply type of a message (and some
other stuff based on message type or status)
3. allow integrators to override the default set and to override the
default filter function, alow reusing defaults too
```
access action set -> filter action set based on filter function criteria -> separate into quick and dropdown -> render
```
## From Integrator's POV
```tsx
import { Channel, } from 'stream-chat-react';
import {
MessageActions,
defaultMessageActionSet,
DefaultDropdownActionButton,
} from 'stream-chat-react/experimental';
const CustomMessageActions = () => {
const customFilter = () => {
/*...*/
};
return (
<MessageActions
// though not recommended, it's completely possible to disable default filter...
disableBaseMessageActionSetFilter
messageActionSet={[
...defaultMessageActionSet,
{
type: 'myCustomTypeDropdown',
placement: 'dropdown',
// we can enforce non-null return type (at least through TS)
Component: () => <DefaultDropdownActionButton>🚀 Custom</DefaultDropdownActionButton>,
},
{
type: 'myCustomTypeQuick',
placement: 'quick',
Component: () => <button>a</button>,
},
// ...and apply custom filter here with access to CustomMessageActions scope (contexts + other hooks)
].filter(customFilter)}
/>
);
};
<Channel MessageActions={CustomMessageActions}>...</Channel>;
```

## Next Steps
- [x] review and release
- [ ] allow overriding certain components within default
`MessageActions_UNSTABLE`
- [ ] tests1 parent 19486fa commit 17a1160
File tree
31 files changed
+436
-18
lines changed- scripts
- src
- components
- Channel
- ChatAutoComplete
- MessageActions
- Message
- Reactions
- Threads/hooks
- context
- experimental
- MessageActions
- hooks
- i18n
31 files changed
+436
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
53 | 65 | | |
54 | 66 | | |
55 | 67 | | |
| |||
70 | 82 | | |
71 | 83 | | |
72 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
73 | 88 | | |
74 | 89 | | |
75 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
1226 | 1227 | | |
1227 | 1228 | | |
1228 | 1229 | | |
| 1230 | + | |
1229 | 1231 | | |
1230 | 1232 | | |
1231 | 1233 | | |
| |||
1275 | 1277 | | |
1276 | 1278 | | |
1277 | 1279 | | |
| 1280 | + | |
1278 | 1281 | | |
1279 | 1282 | | |
1280 | 1283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | | - | |
| 14 | + | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 98 | + | |
101 | 99 | | |
102 | 100 | | |
103 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
73 | 77 | | |
74 | 78 | | |
75 | | - | |
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
79 | | - | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| |||
171 | 173 | | |
172 | 174 | | |
173 | 175 | | |
174 | | - | |
| 176 | + | |
175 | 177 | | |
176 | 178 | | |
177 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| |||
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
23 | | - | |
24 | 21 | | |
25 | 22 | | |
26 | 23 | | |
| |||
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
45 | | - | |
| 42 | + | |
46 | 43 | | |
47 | 44 | | |
48 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
0 commit comments