-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathserver-error-banner.tsx
More file actions
125 lines (117 loc) · 3.46 KB
/
Copy pathserver-error-banner.tsx
File metadata and controls
125 lines (117 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React from 'react';
import {
Banner,
Button,
Icon,
Link,
css,
spacing,
useDrawerActions,
} from '@mongodb-js/compass-components';
import {
useSearchActivationProgramP1,
useTelemetry,
} from '@mongodb-js/compass-telemetry/provider';
import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
import { buildProjectSettingsUrl } from '@mongodb-js/atlas-service/provider';
import {
isSearchIndexDefinitionError,
isRerankNotEnabledError,
getVoyageProjectRateLimitInfo,
type SearchExtensionType,
} from '../utils/search-stage-errors';
import RateLimitExceededBanner from './rate-limit-exceeded-banner';
import { bannerButtonStyles } from './banner-button-styles';
const RERANK_DOCS_URL =
'https://www.mongodb.com/docs/vector-search/query/aggregation-stages/rerank/#navigate-to-the-project-settings-page';
const bannerStyles = css({
textAlign: 'left',
});
const bannerContentStyles = css({
display: 'flex',
alignItems: 'center',
gap: spacing[200],
});
type ServerErrorBannerProps = {
message: string;
searchIndexName: string | null;
onEditSearchIndexClick?: (indexName: string) => void;
searchExtensionType?: SearchExtensionType | null;
dataTestId?: string;
};
export default function ServerErrorBanner({
message,
searchIndexName,
onEditSearchIndexClick,
searchExtensionType,
dataTestId = 'server-error-banner',
}: ServerErrorBannerProps) {
const { enableSearchActivationProgramP1 } = useSearchActivationProgramP1();
const { openDrawer } = useDrawerActions();
const track = useTelemetry();
const { atlasMetadata } = useConnectionInfo();
const rerankNotEnabled = isRerankNotEnabledError(message);
const projectSettingsHref = rerankNotEnabled
? atlasMetadata
? buildProjectSettingsUrl({
projectId: atlasMetadata.projectId,
highlight: 'nativeReranking',
})
: RERANK_DOCS_URL
: null;
const rateLimitInfo = getVoyageProjectRateLimitInfo(message);
if (rateLimitInfo) {
return (
<RateLimitExceededBanner
rateLimitInfo={rateLimitInfo}
searchExtensionType={searchExtensionType}
dataTestId={dataTestId}
/>
);
}
return (
<Banner variant="danger" data-testid={dataTestId} className={bannerStyles}>
{rerankNotEnabled ? (
<>
<strong>Native reranking not enabled</strong>
<br />
<div className={bannerContentStyles}>
<span>Enable native reranking in project settings.</span>
{projectSettingsHref && (
<Button
size="xsmall"
href={projectSettingsHref}
target="_blank"
rightGlyph={<Icon glyph="OpenNewTab" />}
className={bannerButtonStyles}
>
Project Settings
</Button>
)}
</div>
</>
) : (
message
)}
{enableSearchActivationProgramP1 &&
searchIndexName &&
isSearchIndexDefinitionError(message) &&
onEditSearchIndexClick && (
<>
{' '}
<Link
onClick={() => {
track('Search Index Edit Link Clicked', {
context: 'Server Error Banner',
});
openDrawer('compass-indexes-drawer');
onEditSearchIndexClick(searchIndexName);
}}
>
Edit Search Index
</Link>
</>
)}
</Banner>
);
}