Skip to content

Commit

Permalink
Merge pull request #2 from voorhoede/fix/reset-values-on-fields
Browse files Browse the repository at this point in the history
Fix/reset values on fields
  • Loading branch information
zowievangeest authored Apr 24, 2023
2 parents eb22bf2 + e50e567 commit a86145c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datocms-plugin-chat-gpt-ai-content-generator",
"version": "1.0.0",
"version": "1.0.1",
"description": "AI assistant to quickly generate realistic content based on keywords using ChatGPT v3 (OpenAI).",
"private": false,
"scripts": {
Expand Down
14 changes: 8 additions & 6 deletions src/entrypoints/FieldExtension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export default function FieldExtension({ ctx }: Props) {
const [usage, setUsage] = useState(usageProps)
const [isGenerated, setIsGenerated] = useState(false)

const fieldId = ctx.field.id
const fieldId = `${ctx.item?.id}-${ctx.field.id}`
const pluginParams = ctx.plugin.attributes.parameters as ConfigParameters
const initialValue =
pluginParams.fields && pluginParams.fields[fieldId as never]
pluginParams.fields && pluginParams.fields[fieldId as never] && ctx.item?.id
? pluginParams.fields[fieldId as never]
: {}

Expand All @@ -57,10 +57,12 @@ export default function FieldExtension({ ctx }: Props) {
onSubmit={async (values: FieldConfigParameters) => {
const fields = { ...pluginParams.fields, [fieldId]: values }

await ctx.updatePluginParameters({
...pluginParams,
fields,
})
if (ctx.item?.id) {
await ctx.updatePluginParameters({
...pluginParams,
fields,
})
}

setIsLoading(true)
setUsage(usageProps)
Expand Down

0 comments on commit a86145c

Please sign in to comment.