Skip to content

Commit c403917

Browse files
committed
fix: show filter before projection in index form
1 parent 0b84d80 commit c403917

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/embeddingsIndexDashboard/IndexEditor.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,21 @@ export function IndexEditor(props: {
141141
/>
142142
<IndexFormInput label="Dataset" index={index} prop="dataset" onChange={setIndex} readOnly />
143143
<IndexFormInput
144-
label="Projection"
145-
placeholder={defaultIndex.projection}
144+
label="Filter"
145+
description="Must be a valid GROQ filter"
146+
placeholder={defaultIndex.filter}
146147
index={index}
147-
prop="projection"
148+
prop="filter"
148149
onChange={setIndex}
149150
readOnly={readOnly}
150151
type="textarea"
151152
/>
152153
<IndexFormInput
153-
label="Filter"
154-
placeholder={defaultIndex.filter}
154+
label="Projection"
155+
description="Must be a valid GROQ projection, starting { and ending with }"
156+
placeholder={defaultIndex.projection}
155157
index={index}
156-
prop="filter"
158+
prop="projection"
157159
onChange={setIndex}
158160
readOnly={readOnly}
159161
type="textarea"

src/embeddingsIndexDashboard/IndexFormInput.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
import {NamedIndex} from '../api/embeddingsApi'
22
import {Dispatch, FormEvent, SetStateAction, useCallback, useId} from 'react'
3-
import {Label, Stack, TextArea, TextInput} from '@sanity/ui'
3+
import {Box, Label, Stack, TextArea, TextInput, Text} from '@sanity/ui'
44

55
export interface IndexFormInputProps {
66
index: Partial<NamedIndex>
77
prop: keyof NamedIndex
88
label: string
9+
description?: string
910
onChange: Dispatch<SetStateAction<Partial<NamedIndex>>>
1011
readOnly: boolean
1112
placeholder?: string
1213
type?: 'text' | 'textarea'
1314
}
1415

1516
export function IndexFormInput(props: IndexFormInputProps) {
16-
const {label, index, prop, onChange, readOnly, placeholder, type} = props
17+
const {label, description, index, prop, onChange, readOnly, placeholder, type} = props
1718
const handleChange = useCallback(
1819
(propValue: string) => onChange((current) => ({...current, [prop]: propValue})),
1920
[onChange, prop],
2021
)
2122
return (
2223
<FormInput
2324
label={label}
25+
description={description}
2426
onChange={handleChange}
2527
value={index[prop] ?? ''}
2628
readOnly={readOnly}
@@ -32,6 +34,7 @@ export function IndexFormInput(props: IndexFormInputProps) {
3234

3335
interface FormInputProps {
3436
label: string
37+
description?: string
3538
onChange: (value: string) => void
3639
value: string
3740
readOnly: boolean
@@ -40,7 +43,7 @@ interface FormInputProps {
4043
}
4144

4245
function FormInput(props: FormInputProps) {
43-
const {label, onChange, value, readOnly, placeholder, type = 'text'} = props
46+
const {label, description, onChange, value, readOnly, placeholder, type = 'text'} = props
4447
const id = useId()
4548
const handleChange = useCallback(
4649
(e: FormEvent<HTMLInputElement | HTMLTextAreaElement>) => onChange(e.currentTarget.value),
@@ -51,6 +54,13 @@ function FormInput(props: FormInputProps) {
5154
<Label muted htmlFor={id}>
5255
<label htmlFor={id}>{label}</label>
5356
</Label>
57+
{description && (
58+
<Box>
59+
<Text size={1} muted>
60+
{description}
61+
</Text>
62+
</Box>
63+
)}
5464
{type === 'text' ? (
5565
<TextInput
5666
id={id}

0 commit comments

Comments
 (0)