@sanity/embeddings-index-ui 1.1.6 → 1.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/embeddings-index-ui",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Various Sanity Studio plugins for integrating with the embeddings index API",
5
5
  "keywords": [
6
6
  "sanity",
@@ -21,6 +21,10 @@
21
21
  "types": "./dist/index.d.ts",
22
22
  "source": "./src/index.ts",
23
23
  "require": "./dist/index.js",
24
+ "node": {
25
+ "module": "./dist/index.esm.js",
26
+ "import": "./dist/index.cjs.mjs"
27
+ },
24
28
  "import": "./dist/index.esm.js",
25
29
  "default": "./dist/index.esm.js"
26
30
  },
@@ -3,7 +3,7 @@ import {createContext, PropsWithChildren, useContext, useEffect, useState} from
3
3
  import {Card, Text} from '@sanity/ui'
4
4
  import {useApiClient} from './embeddingsApiHooks'
5
5
 
6
- export type FeatureStatus = 'enabled' | 'disabled' | 'loading'
6
+ export type FeatureStatus = 'enabled' | 'disabled' | 'loading' | 'error'
7
7
  export const FeatureEnabledContext = createContext<FeatureStatus>('loading')
8
8
 
9
9
  export function useIsFeatureEnabled() {
@@ -21,7 +21,7 @@ export function useIsFeatureEnabled() {
21
21
  })
22
22
  .catch((err) => {
23
23
  console.error(err)
24
- setStatus('disabled')
24
+ setStatus('error')
25
25
  })
26
26
  }, [client])
27
27
 
@@ -54,3 +54,11 @@ export function FeatureDisabledNotice(props: {urlSuffix?: string}) {
54
54
  </Card>
55
55
  )
56
56
  }
57
+
58
+ export function FeatureError() {
59
+ return (
60
+ <Card padding={4} border tone="critical">
61
+ An error occurred. See console for details.
62
+ </Card>
63
+ )
64
+ }
@@ -6,27 +6,36 @@ import {EditIndexDialog} from './IndexEditor'
6
6
  import {IndexList} from './IndexList'
7
7
  import {IndexInfo} from './IndexInfo'
8
8
  import {useApiClient} from '../api/embeddingsApiHooks'
9
- import {FeatureDisabledNotice, useIsFeatureEnabled} from '../api/isEnabled'
9
+ import {FeatureDisabledNotice, FeatureError, useIsFeatureEnabled} from '../api/isEnabled'
10
10
 
11
11
  export function EmbeddingsIndexTool() {
12
12
  const featureState = useIsFeatureEnabled()
13
13
  return (
14
- <Card>
14
+ <Card flex={1}>
15
15
  <Flex justify="center" flex={1}>
16
- {featureState == 'disabled' ? (
16
+ {featureState === 'error' ? (
17
+ <Box padding={4}>
18
+ <FeatureError />
19
+ </Box>
20
+ ) : null}
21
+
22
+ {featureState === 'disabled' ? (
17
23
  <Box padding={4}>
18
24
  <FeatureDisabledNotice urlSuffix="?ref=embeddings-tab" />
19
25
  </Box>
20
26
  ) : null}
21
27
 
22
- <Card flex={1} style={{maxWidth: 1200}} padding={5}>
23
- {featureState == 'loading' ? (
24
- <Box padding={2}>
25
- <Spinner />
26
- </Box>
27
- ) : null}
28
- {featureState == 'enabled' ? <Indexes /> : null}
29
- </Card>
28
+ {featureState === 'loading' ? (
29
+ <Box padding={6}>
30
+ <Spinner size={4} />
31
+ </Box>
32
+ ) : null}
33
+
34
+ {featureState === 'enabled' ? (
35
+ <Card flex={1} style={{maxWidth: 1200}} padding={5}>
36
+ <Indexes />
37
+ </Card>
38
+ ) : null}
30
39
  </Flex>
31
40
  </Card>
32
41
  )
@@ -12,7 +12,7 @@ import {useCallback, useEffect, useMemo, useRef, useState} from 'react'
12
12
  import {useDocumentPane} from 'sanity/desk'
13
13
  import {QueryResult} from '../api/embeddingsApi'
14
14
  import {publicId} from '../utils/id'
15
- import {FeatureDisabledNotice, useIsFeatureEnabledContext} from '../api/isEnabled'
15
+ import {FeatureDisabledNotice, FeatureError, useIsFeatureEnabledContext} from '../api/isEnabled'
16
16
  import {EmbeddingsIndexConfig} from '../schemas/typeDefExtensions'
17
17
  import {SemanticSearchAutocomplete} from './SemanticSearchAutocomplete'
18
18
 
@@ -71,6 +71,12 @@ export function SemanticSearchReferenceInput(
71
71
  <FeatureDisabledNotice urlSuffix="?ref=embeddings-ref" />
72
72
  ) : null}
73
73
 
74
+ {semantic && featureState === 'error' ? (
75
+ <Box padding={4}>
76
+ <FeatureError />
77
+ </Box>
78
+ ) : null}
79
+
74
80
  <Box flex={1} style={{maxHeight: 36, overflow: 'hidden'}}>
75
81
  {semantic && featureState == 'enabled' ? (
76
82
  <SemanticSearchInput {...props} indexConfig={config} />