Skip to content

Commit 6184a4a

Browse files
committed
chore: update basic part information
1 parent ee804a5 commit 6184a4a

File tree

1 file changed

+24
-71
lines changed

1 file changed

+24
-71
lines changed

src/pages/form-part/basic-part.tsx

Lines changed: 24 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { cn } from '@/lib/utils';
2222
import { Card } from '@/components/ui/card';
2323
import { BasicSwaggerSchema } from '@/utils/form/form.helper';
24+
import { licenses } from '@/utils/license';
2425

2526
interface SetValue {
2627
form: UseFormReturn<BasicSwaggerSchema>;
@@ -153,91 +154,43 @@ const BasicPartForm: React.FC<SetValue> = ({ form }) => {
153154
<div className="flex gap-2">
154155
<FormField
155156
control={form.control}
156-
name={`license.name`}
157+
name="license.name"
157158
render={({ field }) => (
158159
<FormItem className="flex-1">
159160
<FormLabel>OpenAPI License</FormLabel>
160161
<Select
161-
onValueChange={field.onChange}
162-
defaultValue={field.value}
162+
onValueChange={(jsonValue) => {
163+
const selected = JSON.parse(jsonValue);
164+
field.onChange(selected.name);
165+
form.setValue('license.url', selected.url);
166+
}}
167+
value={
168+
licenses.find((l) => l.name === field.value)
169+
? JSON.stringify({
170+
name: field.value,
171+
url: form.getValues('license.url'),
172+
})
173+
: undefined
174+
}
163175
>
164176
<FormControl>
165177
<SelectTrigger>
166178
<SelectValue placeholder="Select a OpenAPI License" />
167179
</SelectTrigger>
168180
</FormControl>
169181
<SelectContent>
170-
<SelectItem value="GNU AGPLv3">GNU AGPLv3</SelectItem>
171-
<SelectItem value="GNU GPLv3">GNU GPLv3</SelectItem>
172-
<SelectItem value="GNU LGPLv3">GNU LGPLv3</SelectItem>
173-
<SelectItem value="Mozilla Public License 2.0">
174-
Mozilla Public License 2.0
175-
</SelectItem>
176-
<SelectItem value="Apache License 2.0">
177-
Apache License 2.0
178-
</SelectItem>
179-
<SelectItem value="MIT License">
180-
MIT License
181-
</SelectItem>
182-
<SelectItem value="Boost Software License 1.0">
183-
Boost Software License 1.0
184-
</SelectItem>
185-
<SelectItem value="The Unlicense">
186-
The Unlicense
187-
</SelectItem>
182+
{licenses.map((license) => (
183+
<SelectItem
184+
key={license.name}
185+
value={JSON.stringify(license)}
186+
>
187+
{license.name}
188+
</SelectItem>
189+
))}
188190
</SelectContent>
189191
</Select>
190192
<FormDescription>
191-
Select your copyright type.
192-
</FormDescription>
193-
<FormMessage />
194-
</FormItem>
195-
)}
196-
/>
197-
<FormField
198-
control={form.control}
199-
name={`license.url`}
200-
render={({ field }) => (
201-
<FormItem className="flex-1">
202-
<FormLabel>OpenAPI License</FormLabel>
203-
<Select
204-
onValueChange={field.onChange}
205-
defaultValue={field.value}
206-
>
207-
<FormControl>
208-
<SelectTrigger>
209-
<SelectValue placeholder="Select a OpenAPI License URL" />
210-
</SelectTrigger>
211-
</FormControl>
212-
<SelectContent>
213-
<SelectItem value="https://www.gnu.org/licenses/agpl-3.0.txt">
214-
GNU AGPLv3
215-
</SelectItem>
216-
<SelectItem value="https://www.gnu.org/licenses/gpl-3.0-standalone.html">
217-
GNU GPLv3
218-
</SelectItem>
219-
<SelectItem value="https://www.gnu.org/licenses/lgpl-3.0-standalone.html">
220-
GNU LGPLv3
221-
</SelectItem>
222-
<SelectItem value="https://www.mozilla.org/en-US/MPL/2.0/">
223-
Mozilla Public License 2.0
224-
</SelectItem>
225-
<SelectItem value="https://www.apache.org/licenses/LICENSE-2.0">
226-
Apache License 2.0
227-
</SelectItem>
228-
<SelectItem value="https://opensource.org/license/mit">
229-
MIT License
230-
</SelectItem>
231-
<SelectItem value="https://www.boost.org/LICENSE_1_0.txt">
232-
Boost Software License 1.0
233-
</SelectItem>
234-
<SelectItem value="https://unlicense.org/">
235-
The Unlicense
236-
</SelectItem>
237-
</SelectContent>
238-
</Select>
239-
<FormDescription>
240-
Select your copyright type.
193+
Selecting a license also sets its URL.
241194
</FormDescription>
242195
<FormMessage />
243196
</FormItem>

0 commit comments

Comments
 (0)