Skip to content

Commit d0e8573

Browse files
feat(SHAPE-8085): apply review feedback
1 parent 4d14031 commit d0e8573

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

packages/demo/src/components/PromptAI.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { Button, MenuItem, Stack, TextField, Typography } from '@mui/material'
1+
import {
2+
Button,
3+
Checkbox,
4+
FormControl,
5+
FormLabel,
6+
MenuItem,
7+
Stack,
8+
TextField,
9+
Typography,
10+
} from '@mui/material'
211
import { useState } from 'react'
312
import {
413
isPromptAIPayloadValid,
@@ -14,24 +23,27 @@ export const PromptAI: PluginComponent = (props) => {
1423
const [promptAction, setPromptAction] = useState<PromptAIAction>('prompt')
1524
const [promptLanguage, setPromptLanguage] = useState<string>()
1625
const [promptTone, setPromptTone] = useState<string>()
17-
const [promptOutput, setPromptOutput] = useState<string>()
26+
const [promptAIGeneratedText, setPromptAIGeneratedText] = useState<string>()
27+
const [promptBasedOnCurrentStory, setPromptBasedOnCurrentStory] =
28+
useState<boolean>(false)
1829

1930
const onSubmit = async () => {
2031
const payload = {
2132
action: promptAction,
2233
text: promptQuestion,
2334
language: promptLanguage,
2435
tone: promptTone,
36+
basedOnCurrentStory: promptBasedOnCurrentStory,
2537
}
2638

2739
if (!isPromptAIPayloadValid(payload)) {
2840
console.error('Invalid Prompt AI payload')
2941
return
3042
}
3143

32-
const output = await actions.promptAI(payload)
44+
const promptAIGeneratedText = await actions.promptAI(payload)
3345

34-
setPromptOutput(output)
46+
setPromptAIGeneratedText(promptAIGeneratedText)
3547
}
3648

3749
return (
@@ -70,7 +82,17 @@ export const PromptAI: PluginComponent = (props) => {
7082
label="Tone (optional)"
7183
onChange={(e) => setPromptTone(e.target.value)}
7284
/>
73-
<Typography>Output: {promptOutput}</Typography>
85+
<FormControl>
86+
<FormLabel htmlFor="based-on-current-story-checkbox">
87+
Based on the current story:
88+
</FormLabel>
89+
<Checkbox
90+
id="based-on-current-story-checkbox"
91+
value={promptBasedOnCurrentStory}
92+
onChange={(e) => setPromptBasedOnCurrentStory(e.target.checked)}
93+
/>
94+
</FormControl>
95+
<Typography>AI Generated Text: {promptAIGeneratedText}</Typography>
7496
<Button
7597
variant="outlined"
7698
color="secondary"

packages/field-plugin/src/messaging/pluginMessage/containerToPluginMessage/PromptAIResponseMessage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import { isMessageToPlugin, type MessageToPlugin } from './MessageToPlugin'
55
* The object returned when calling the "prompt-ai" action.
66
*/
77
export type PromptAIResponseMessage = MessageToPlugin<'prompt-ai'> & {
8-
output: string
8+
aiGeneratedText: string
99
}
1010

1111
export const isPromptAIMessage = (
1212
data: unknown,
1313
): data is PromptAIResponseMessage =>
1414
isMessageToPlugin(data) &&
1515
data.action === 'prompt-ai' &&
16-
hasKey(data, 'output') &&
17-
typeof data.output === 'string'
16+
hasKey(data, 'aiGeneratedText') &&
17+
typeof data.aiGeneratedText === 'string'
1818

1919
export const getResponseFromPromptAIMessage = (
2020
message: PromptAIResponseMessage,
2121
): string => {
22-
const { output } = message
23-
return output
22+
const { aiGeneratedText } = message
23+
return aiGeneratedText
2424
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { hasKey } from '../../../utils'
22

33
export type MessageToContainer<Event extends string> = {
4-
action: 'plugin-changed'
4+
action: 'plugin-changed' | 'prompt-ai'
55
uid: string
66
event: Event
77
callbackId?: string

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ export const promptAIActionsList: PromptAIAction[] = [
3636
export type PromptAIPayload = {
3737
action: PromptAIAction
3838
text: string
39-
// todo: pass the storyId to the container when accepted by the API
40-
// storyId?: number
39+
basedOnCurrentStory?: boolean
4140
language?: string
4241
textLength?: string
4342
tone?: string

0 commit comments

Comments
 (0)