Skip to content

Commit 2bba7da

Browse files
committed
place errors behind feature flag
1 parent 8884ae6 commit 2bba7da

File tree

12 files changed

+382
-213
lines changed

12 files changed

+382
-213
lines changed

src/browser/modules/Stream/CypherFrame/CypherFrame.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
BrowserRequestResult
2929
} from 'shared/modules/requests/requestsDuck'
3030

31+
import { initialState as initialExperimentalFeatureState } from 'shared/modules/experimentalFeatures/experimentalFeaturesDuck'
32+
3133
const createProps = (
3234
status: string,
3335
result: BrowserRequestResult
@@ -63,7 +65,8 @@ describe('CypherFrame', () => {
6365
maxFieldItems: 1000
6466
},
6567
app: {},
66-
connections: {}
68+
connections: {},
69+
experimentalFeatures: initialExperimentalFeatureState
6770
})
6871
}
6972
test('renders accordingly from pending to success to error to success', () => {

src/browser/modules/Stream/CypherFrame/ErrorsView/ErrorsView.test.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,44 @@ import { ErrorsView, ErrorsViewProps } from './ErrorsView'
2525
import { BrowserError } from 'services/exceptions'
2626
import { Provider } from 'react-redux'
2727
import { initialState as initialConnectionsState } from 'shared/modules/connections/connectionsDuck'
28+
import { initialState as initialExperimentalFeatureState } from 'shared/modules/experimentalFeatures/experimentalFeaturesDuck'
2829

2930
const withProvider = (store: any, children: any) => {
3031
return <Provider store={store}>{children}</Provider>
3132
}
3233

33-
const mount = (partOfProps: Partial<ErrorsViewProps>, state?: any) => {
34+
const mount = (props: Partial<ErrorsViewProps>, state?: any) => {
3435
const defaultProps: ErrorsViewProps = {
3536
result: null,
3637
bus: createBus(),
3738
params: {},
3839
executeCmd: jest.fn(),
3940
setEditorContent: jest.fn(),
4041
neo4jVersion: null,
41-
protocolVersion: null
42+
gqlErrorsEnabled: true
4243
}
4344

44-
const props = {
45+
const combinedProps = {
4546
...defaultProps,
46-
...partOfProps
47+
...props
4748
}
4849

49-
state = state ?? {
50-
connections: initialConnectionsState
50+
const initialState = {
51+
connections: initialConnectionsState,
52+
experimentalFeatures: initialExperimentalFeatureState
5153
}
5254

55+
const combinedState = { ...initialState, ...state }
56+
5357
const store = {
5458
subscribe: () => {},
5559
dispatch: () => {},
5660
getState: () => ({
57-
...state
61+
...combinedState
5862
})
5963
}
6064

61-
return render(withProvider(store, <ErrorsView {...props} />))
65+
return render(withProvider(store, <ErrorsView {...combinedProps} />))
6266
}
6367

6468
describe('ErrorsView', () => {
@@ -117,6 +121,11 @@ describe('ErrorsView', () => {
117121
protocolVersion: 5.7
118122
}
119123
}
124+
},
125+
experimentalFeatures: {
126+
enableGqlErrors: {
127+
on: true
128+
}
120129
}
121130
}
122131

@@ -160,6 +169,11 @@ describe('ErrorsView', () => {
160169
protocolVersion: 5.7
161170
}
162171
}
172+
},
173+
experimentalFeatures: {
174+
enableGqlErrors: {
175+
on: true
176+
}
163177
}
164178
}
165179

src/browser/modules/Stream/CypherFrame/ErrorsView/ErrorsView.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,25 @@ import { deepEquals } from 'neo4j-arc/common'
5959
import { getSemanticVersion } from 'shared/modules/dbMeta/dbMetaDuck'
6060
import { SemVer } from 'semver'
6161
import { getProtocolVersion } from 'shared/modules/connections/connectionsDuck'
62-
import { formatError } from '../errorUtils'
62+
import {
63+
formatError,
64+
formatErrorGqlStatusObject,
65+
hasPopulatedGqlFields
66+
} from '../errorUtils'
67+
import {
68+
enableGqlErrors,
69+
showFeature
70+
} from 'shared/modules/experimentalFeatures/experimentalFeaturesDuck'
6371

6472
export type ErrorsViewProps = {
6573
result: BrowserRequestResult
6674
bus: Bus
6775
neo4jVersion: SemVer | null
68-
protocolVersion: number | null
6976
params: Record<string, unknown>
7077
executeCmd: (cmd: string) => void
7178
setEditorContent: (cmd: string) => void
7279
depth?: number
80+
gqlErrorsEnabled: boolean
7381
}
7482

7583
class ErrorsViewComponent extends Component<ErrorsViewProps> {
@@ -87,16 +95,19 @@ class ErrorsViewComponent extends Component<ErrorsViewProps> {
8795
executeCmd,
8896
setEditorContent,
8997
neo4jVersion,
90-
protocolVersion,
91-
depth = 0
98+
depth = 0,
99+
gqlErrorsEnabled
92100
} = this.props
93101

94102
const error = this.props.result as BrowserError
95103
if (!error) {
96104
return null
97105
}
98106

99-
const formattedError = formatError(protocolVersion, error)
107+
const formattedError =
108+
gqlErrorsEnabled && hasPopulatedGqlFields(error)
109+
? formatErrorGqlStatusObject(error)
110+
: formatError(error)
100111

101112
if (!formattedError?.title) {
102113
return null
@@ -168,13 +179,20 @@ class ErrorsViewComponent extends Component<ErrorsViewProps> {
168179
}
169180
}
170181

171-
const mapStateToProps = (state: GlobalState) => {
172-
return {
173-
params: getParams(state),
174-
neo4jVersion: getSemanticVersion(state),
175-
protocolVersion: getProtocolVersion(state)
176-
}
182+
const gqlErrorsEnabled = (state: GlobalState): boolean => {
183+
const featureEnabled = showFeature(state, enableGqlErrors)
184+
const protocolVersion = getProtocolVersion(state)
185+
const protocolVersionSupported =
186+
protocolVersion !== null && protocolVersion >= 5.7
187+
return featureEnabled && protocolVersionSupported
177188
}
189+
190+
const mapStateToProps = (state: GlobalState) => ({
191+
params: getParams(state),
192+
neo4jVersion: getSemanticVersion(state),
193+
gqlErrorsEnabled: gqlErrorsEnabled(state)
194+
})
195+
178196
const mapDispatchToProps = (
179197
_dispatch: Dispatch<Action>,
180198
ownProps: ErrorsViewProps

0 commit comments

Comments
 (0)