@sanity/embeddings-index-ui 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +15 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +14 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/embeddingsApi.ts +1 -1
- package/src/embeddingsIndexDashboard/QueryIndex.tsx +2 -1
- package/src/preview/DocumentPreview.tsx +7 -11
- package/src/referenceInput/SemanticSearchReferenceInput.tsx +4 -3
package/package.json
CHANGED
package/src/api/embeddingsApi.ts
CHANGED
|
@@ -92,10 +92,11 @@ export function ResultList(props: {results: QueryResult[]; query: string}) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
function ResultEntry(props: {result: QueryResult}) {
|
|
95
|
+
const value = props.result.value
|
|
95
96
|
return (
|
|
96
97
|
<Flex gap={4} align="center">
|
|
97
98
|
<Box flex={1}>
|
|
98
|
-
<DocumentPreview documentId={
|
|
99
|
+
<DocumentPreview documentId={value.documentId} schemaTypeName={value.type} button />
|
|
99
100
|
</Box>
|
|
100
101
|
<Box>
|
|
101
102
|
<Text muted size={1}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {CSSProperties,
|
|
1
|
+
import {CSSProperties, useMemo} from 'react'
|
|
2
2
|
import {useMemoObservable} from 'react-rx'
|
|
3
3
|
import {
|
|
4
4
|
DefaultPreview,
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
SanityDefaultPreview,
|
|
8
8
|
SanityDocument,
|
|
9
9
|
SchemaType,
|
|
10
|
-
useClient,
|
|
11
10
|
useDocumentPreviewStore,
|
|
12
11
|
useSchema,
|
|
13
12
|
} from 'sanity'
|
|
@@ -17,6 +16,7 @@ import {ErrorOutlineIcon} from '@sanity/icons'
|
|
|
17
16
|
|
|
18
17
|
interface ResultPreviewProps {
|
|
19
18
|
documentId: string
|
|
19
|
+
schemaTypeName: string
|
|
20
20
|
button?: boolean
|
|
21
21
|
style?: CSSProperties
|
|
22
22
|
}
|
|
@@ -24,18 +24,13 @@ interface ResultPreviewProps {
|
|
|
24
24
|
export function DocumentPreview({
|
|
25
25
|
documentId,
|
|
26
26
|
style,
|
|
27
|
+
schemaTypeName,
|
|
27
28
|
...buttonProps
|
|
28
29
|
}: ResultPreviewProps & ButtonProps) {
|
|
29
|
-
const client = useClient({apiVersion: '2023-06-06'})
|
|
30
|
-
const [type, setType] = useState<string | undefined>(undefined)
|
|
31
30
|
const schema = useSchema()
|
|
32
|
-
const schemaType =
|
|
31
|
+
const schemaType = schemaTypeName ? schema.get(schemaTypeName) : undefined
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
client.fetch<string>(`* [_id==$id]._type`, {id: documentId}).then(setType)
|
|
36
|
-
}, [documentId, client])
|
|
37
|
-
|
|
38
|
-
if (!type) {
|
|
33
|
+
if (!schemaTypeName) {
|
|
39
34
|
return (
|
|
40
35
|
<Card style={{minHeight: '36px'}}>
|
|
41
36
|
<DefaultPreview
|
|
@@ -58,7 +53,7 @@ export function DocumentPreview({
|
|
|
58
53
|
media={() => <ErrorOutlineIcon />}
|
|
59
54
|
title={
|
|
60
55
|
<>
|
|
61
|
-
Unknown type <code>{
|
|
56
|
+
Unknown type <code>{schemaTypeName ?? 'N/A'}</code> for {documentId}
|
|
62
57
|
</>
|
|
63
58
|
}
|
|
64
59
|
/>
|
|
@@ -69,6 +64,7 @@ export function DocumentPreview({
|
|
|
69
64
|
return (
|
|
70
65
|
<DocumentPreviewInner
|
|
71
66
|
documentId={documentId}
|
|
67
|
+
schemaTypeName={schemaTypeName}
|
|
72
68
|
schemaType={schemaType}
|
|
73
69
|
style={style}
|
|
74
70
|
{...buttonProps}
|
|
@@ -116,7 +116,7 @@ function SemanticSearchInput(props: ObjectInputProps) {
|
|
|
116
116
|
|
|
117
117
|
queryIndex(
|
|
118
118
|
{
|
|
119
|
-
query: queryString,
|
|
119
|
+
query: queryString.trim().length ? queryString : JSON.stringify(docRef.current) ?? '',
|
|
120
120
|
indexName,
|
|
121
121
|
maxResults,
|
|
122
122
|
filter: {
|
|
@@ -194,7 +194,7 @@ function SemanticSearchInput(props: ObjectInputProps) {
|
|
|
194
194
|
id={id}
|
|
195
195
|
ref={autocompleteRef}
|
|
196
196
|
data-testid="semantic-autocomplete"
|
|
197
|
-
placeholder="Type to search"
|
|
197
|
+
placeholder="Type to search..."
|
|
198
198
|
openButton={openButtonConfig}
|
|
199
199
|
onFocus={handleFocus}
|
|
200
200
|
onChange={handleChange}
|
|
@@ -210,11 +210,12 @@ function SemanticSearchInput(props: ObjectInputProps) {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
function AutocompleteOption(props: Option) {
|
|
213
|
+
const value = props.result.value
|
|
213
214
|
return (
|
|
214
215
|
<Button mode="bleed" padding={1} style={{width: '100%'}}>
|
|
215
216
|
<Flex gap={2} align="center">
|
|
216
217
|
<Box flex={1}>
|
|
217
|
-
<DocumentPreview documentId={
|
|
218
|
+
<DocumentPreview documentId={value.documentId} schemaTypeName={value.type} />
|
|
218
219
|
</Box>
|
|
219
220
|
<Box padding={2}>
|
|
220
221
|
<Text size={1} muted title={'Relevance'}>
|