Skip to content

Commit 3f85b24

Browse files
feat(SHAPE-8085): apply review feedback
1 parent f8fd00b commit 3f85b24

File tree

7 files changed

+54
-63
lines changed

7 files changed

+54
-63
lines changed

packages/demo/src/components/PromptAI.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
Button,
33
Checkbox,
44
FormControl,
5-
FormLabel,
5+
FormControlLabel,
66
MenuItem,
77
Stack,
88
TextField,
@@ -84,13 +84,15 @@ export const PromptAI: PluginComponent = (props) => {
8484
onChange={(e) => setPromptTone(e.target.value)}
8585
/>
8686
<FormControl>
87-
<FormLabel htmlFor="based-on-current-story-checkbox">
88-
Based on the current story:
89-
</FormLabel>
90-
<Checkbox
91-
id="based-on-current-story-checkbox"
92-
value={promptBasedOnCurrentStory}
93-
onChange={(e) => setPromptBasedOnCurrentStory(e.target.checked)}
87+
<FormControlLabel
88+
label="Based on the current story"
89+
control={
90+
<Checkbox
91+
value={promptBasedOnCurrentStory}
92+
onChange={(e) => setPromptBasedOnCurrentStory(e.target.checked)}
93+
/>
94+
}
95+
sx={{ ml: '-9px' }}
9496
/>
9597
</FormControl>
9698
<Typography>

packages/field-plugin/src/createFieldPlugin/createPluginActions/createPluginActions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ describe('createPluginActions', () => {
260260
expect(postToContainer).toHaveBeenLastCalledWith(
261261
expect.objectContaining({
262262
event: 'promptAI',
263-
payload: promptAIPayload,
263+
promptAIPayload,
264264
} satisfies Partial<PluginPromptAIMessage>),
265265
)
266266
})

packages/field-plugin/src/createFieldPlugin/createPluginActions/createPluginActions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import {
88
getUserContextMessage,
99
heightChangeMessage,
1010
modalChangeMessage,
11-
OnAssetSelectMessage,
12-
OnContextRequestMessage,
13-
OnUserContextRequestMessage,
14-
OnLoadedMessage,
15-
OnStateChangeMessage,
16-
OnUnknownPluginMessage,
1711
pluginLoadedMessage,
1812
getPluginPromptAIMessage,
1913
valueChangeMessage,
20-
OnPromptAIMessage,
14+
type OnAssetSelectMessage,
15+
type OnContextRequestMessage,
16+
type OnUserContextRequestMessage,
17+
type OnLoadedMessage,
18+
type OnStateChangeMessage,
19+
type OnUnknownPluginMessage,
20+
type OnPromptAIMessage,
2121
type PromptAIPayload,
2222
} from '../../messaging'
2323
import { FieldPluginActions, Initialize } from '../FieldPluginActions'

packages/field-plugin/src/createFieldPlugin/createPluginActions/createPluginMessageListener/handlePluginMessage.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ describe('handlePluginMessage', () => {
160160
expect(callbacks.onLoaded).not.toHaveBeenCalled()
161161
expect(callbacks.onStateChange).not.toHaveBeenCalled()
162162
expect(callbacks.onContextRequest).not.toHaveBeenCalled()
163-
expect(callbacks.onAssetSelect).not.toHaveBeenCalledWith(data)
164-
expect(callbacks.onPromptAI).toHaveBeenCalled()
163+
expect(callbacks.onAssetSelect).not.toHaveBeenCalled()
164+
expect(callbacks.onPromptAI).toHaveBeenCalledWith(data)
165165
expect(callbacks.onUnknownMessage).not.toHaveBeenCalled()
166166
})
167167
})

packages/field-plugin/src/messaging/pluginMessage/pluginToContainerMessage/PromptAIMessage.test.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const stub: PluginPromptAIMessage = {
1111
action: 'prompt-ai',
1212
event: 'promptAI',
1313
uid,
14-
payload: {
14+
promptAIPayload: {
1515
action: 'prompt',
1616
text: 'Some text to prompt',
1717
},
@@ -36,7 +36,7 @@ describe('PromptAIMessage', () => {
3636
}),
3737
).toEqual(false)
3838
})
39-
it('has a payload', () => {
39+
it('has a promptAIPayload', () => {
4040
expect(
4141
isPluginPromptAIMessage({
4242
...stub,
@@ -45,15 +45,15 @@ describe('PromptAIMessage', () => {
4545
expect(
4646
isPluginPromptAIMessage({
4747
...stub,
48-
payload: undefined,
48+
promptAIPayload: undefined,
4949
}),
5050
).toEqual(false)
5151
})
52-
it('has the payload all required fields', () => {
52+
it('has the promptAIPayload all required fields', () => {
5353
expect(
5454
isPluginPromptAIMessage({
5555
...stub,
56-
payload: {
56+
promptAIPayload: {
5757
action: '',
5858
},
5959
}),
@@ -62,7 +62,7 @@ describe('PromptAIMessage', () => {
6262
expect(
6363
isPluginPromptAIMessage({
6464
...stub,
65-
payload: {
65+
promptAIPayload: {
6666
text: '',
6767
},
6868
}),
@@ -71,7 +71,7 @@ describe('PromptAIMessage', () => {
7171
expect(
7272
isPluginPromptAIMessage({
7373
...stub,
74-
payload: {
74+
promptAIPayload: {
7575
action: 'prompt',
7676
text: 'random text',
7777
},
@@ -81,7 +81,7 @@ describe('PromptAIMessage', () => {
8181
expect(
8282
isPluginPromptAIMessage({
8383
...stub,
84-
payload: {
84+
promptAIPayload: {
8585
action: 'prompt',
8686
text: 123,
8787
},
@@ -91,7 +91,7 @@ describe('PromptAIMessage', () => {
9191
expect(
9292
isPluginPromptAIMessage({
9393
...stub,
94-
payload: {
94+
promptAIPayload: {
9595
action: null,
9696
text: 123,
9797
},
@@ -101,19 +101,19 @@ describe('PromptAIMessage', () => {
101101
expect(
102102
isPluginPromptAIMessage({
103103
...stub,
104-
payload: {
104+
promptAIPayload: {
105105
action: null,
106106
text: null,
107107
},
108108
}),
109109
).toEqual(false)
110110
})
111-
it('has the payload a language in case of translation', () => {
111+
it('has the promptAIPayload a language in case of translation', () => {
112112
expect(
113113
isPluginPromptAIMessage({
114114
...stub,
115-
payload: {
116-
...stub.payload,
115+
promptAIPayload: {
116+
...stub.promptAIPayload,
117117
action: 'translate',
118118
},
119119
}),
@@ -122,20 +122,20 @@ describe('PromptAIMessage', () => {
122122
expect(
123123
isPluginPromptAIMessage({
124124
...stub,
125-
payload: {
126-
...stub.payload,
125+
promptAIPayload: {
126+
...stub.promptAIPayload,
127127
action: 'translate',
128128
language: 'en',
129129
},
130130
}),
131131
).toEqual(true)
132132
})
133-
it('has the payload a tone in case of tone adjustment', () => {
133+
it('has the promptAIPayload a tone in case of tone adjustment', () => {
134134
expect(
135135
isPluginPromptAIMessage({
136136
...stub,
137-
payload: {
138-
...stub.payload,
137+
promptAIPayload: {
138+
...stub.promptAIPayload,
139139
action: 'adjust-tone',
140140
},
141141
}),
@@ -144,8 +144,8 @@ describe('PromptAIMessage', () => {
144144
expect(
145145
isPluginPromptAIMessage({
146146
...stub,
147-
payload: {
148-
...stub.payload,
147+
promptAIPayload: {
148+
...stub.promptAIPayload,
149149
action: 'adjust-tone',
150150
tone: 'academic',
151151
},
@@ -156,13 +156,13 @@ describe('PromptAIMessage', () => {
156156
describe('constructor', () => {
157157
it('includes the uid', () => {
158158
expect(
159-
getPluginPromptAIMessage(stub.payload, { uid, callbackId }),
159+
getPluginPromptAIMessage(stub.promptAIPayload, { uid, callbackId }),
160160
).toHaveProperty('uid', uid)
161161
})
162-
it('includes the payload was added to the message', () => {
162+
it('includes the promptAIPayload', () => {
163163
expect(
164-
getPluginPromptAIMessage(stub.payload, { uid, callbackId }),
165-
).toHaveProperty('payload')
164+
getPluginPromptAIMessage(stub.promptAIPayload, { uid, callbackId }),
165+
).toHaveProperty('promptAIPayload')
166166
})
167167
})
168168
})

packages/field-plugin/src/messaging/pluginMessage/pluginToContainerMessage/PromptAIMessage.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,7 @@ import {
44
type MessageToContainer,
55
} from './MessageToContainer'
66

7-
export type PromptAIAction =
8-
| 'prompt'
9-
| 'complete'
10-
| 'shorten'
11-
| 'extend'
12-
| 'rephrase'
13-
| 'summarize'
14-
| 'simplify'
15-
| 'translate'
16-
| 'tldr'
17-
| 'adjust-tone'
18-
| 'emojify'
19-
| 'fix_spelling_and_grammar'
20-
21-
export const promptAIActionsList: PromptAIAction[] = [
7+
export const promptAIActionsList = [
228
'prompt',
239
'complete',
2410
'shorten',
@@ -31,7 +17,9 @@ export const promptAIActionsList: PromptAIAction[] = [
3117
'adjust-tone',
3218
'emojify',
3319
'fix_spelling_and_grammar',
34-
]
20+
] as const
21+
22+
export type PromptAIAction = (typeof promptAIActionsList)[number]
3523

3624
export type PromptAIPayload = {
3725
action: PromptAIAction
@@ -48,16 +36,16 @@ export type PluginPromptAIMessage = Omit<
4836
'action'
4937
> & {
5038
action: 'prompt-ai'
51-
payload: PromptAIPayload
39+
promptAIPayload: PromptAIPayload
5240
}
5341

5442
export const isPluginPromptAIMessage = (
5543
obj: unknown,
5644
): obj is PluginPromptAIMessage =>
5745
isMessageToContainer(obj) &&
5846
obj.event === 'promptAI' &&
59-
hasKey(obj, 'payload') &&
60-
isPromptAIPayloadValid(obj.payload as PromptAIPayload)
47+
hasKey(obj, 'promptAIPayload') &&
48+
isPromptAIPayloadValid(obj.promptAIPayload as PromptAIPayload)
6149

6250
export const isPromptAIPayloadValid = (promptAIPayload: PromptAIPayload) =>
6351
promptAIPayload !== null &&
@@ -83,5 +71,5 @@ export const getPluginPromptAIMessage = (
8371
action: 'prompt-ai',
8472
event: 'promptAI',
8573
...options,
86-
payload: { ...message },
74+
promptAIPayload: { ...message },
8775
})

packages/lib-helpers/test/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ const getContainer = (sendToFieldPlugin: (data: unknown) => void) => {
117117
callbackId: data.callbackId,
118118
aiResponse: {
119119
ok: true,
120-
answer: 'Fake AI answer for the prompt: ' + data.payload.text,
120+
answer:
121+
'Fake AI answer for the prompt: ' + data.promptAIPayload.text,
121122
},
122123
})
123124
} else if (isGetUserContextMessage(data)) {

0 commit comments

Comments
 (0)