Skip to content

Commit 3b7a643

Browse files
Separate metadata count query (#1840)
* Seperate metadata count query * Update styles * update snapshots * Update src/browser/modules/DBMSInfo/DBMSInfo.tsx Co-authored-by: Oskar Damkjaer <[email protected]> * Update src/shared/modules/dbMeta/dbMetaDuck.ts Co-authored-by: Oskar Damkjaer <[email protected]> * remove console.log * change name of function * fix spelling Co-authored-by: Oskar Damkjaer <[email protected]>
1 parent 1188f7f commit 3b7a643

File tree

6 files changed

+203
-45
lines changed

6 files changed

+203
-45
lines changed

src/browser/components/TabNavigation/Navigation.tsx

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ interface NavigationState {
6666
transitionState: DrawerTransitionState
6767
closingDrawerName: string | null
6868
guideWidth: number
69+
isResizing: boolean
6970
}
7071

7172
class Navigation extends Component<NavigationProps, NavigationState> {
7273
state: NavigationState = {
7374
transitionState: this.props.selectedDrawerName ? Open : Closed,
7475
closingDrawerName: null,
75-
guideWidth: LARGE_DRAWER_WIDTH
76+
guideWidth: LARGE_DRAWER_WIDTH,
77+
isResizing: false
7678
}
7779

7880
componentDidUpdate(
@@ -180,10 +182,10 @@ class Navigation extends Component<NavigationProps, NavigationState> {
180182
const drawerWidth = guideDrawerSelected
181183
? this.state.guideWidth
182184
: STANDARD_DRAWER_WIDTH
183-
const useFullWidth =
185+
const isOpenOrOpening =
184186
this.state.transitionState === Open ||
185187
this.state.transitionState === Opening
186-
const width = useFullWidth ? drawerWidth : 0
188+
const width = isOpenOrOpening ? drawerWidth : 0
187189

188190
return (
189191
<StyledSidebar>
@@ -192,32 +194,43 @@ class Navigation extends Component<NavigationProps, NavigationState> {
192194
<StyledBottomNav>{bottomNavItemsList}</StyledBottomNav>
193195
</StyledTabsWrapper>
194196

195-
<Resizable
196-
minWidth={guideDrawerSelected ? STANDARD_DRAWER_WIDTH : 0}
197-
maxWidth={'70vw'}
198-
size={{ width: width, height: '100%' }}
199-
onResizeStop={(_e, _direction, _ref, d) => {
200-
this.setState({ guideWidth: this.state.guideWidth + d.width })
197+
<StyledDrawer
198+
onTransitionEnd={this.onTransitionEnd}
199+
style={{
200+
width: this.state.isResizing ? 'unset' : width
201201
}}
202-
enable={{
203-
top: false,
204-
right: guideDrawerSelected,
205-
bottom: false,
206-
left: false,
207-
topRight: false,
208-
bottomRight: false,
209-
bottomLeft: false,
210-
topLeft: false
211-
}}
212-
style={{ zIndex: 100 }}
213202
>
214-
<StyledDrawer onTransitionEnd={this.onTransitionEnd}>
203+
<Resizable
204+
minWidth={guideDrawerSelected ? STANDARD_DRAWER_WIDTH : 0}
205+
maxWidth={'70vw'}
206+
size={{ width: width, height: '100%' }}
207+
onResizeStart={() => {
208+
this.setState({ isResizing: true })
209+
}}
210+
onResizeStop={(_e, _direction, _ref, d) => {
211+
this.setState({
212+
guideWidth: this.state.guideWidth + d.width,
213+
isResizing: false
214+
})
215+
}}
216+
enable={{
217+
top: false,
218+
right: guideDrawerSelected,
219+
bottom: false,
220+
left: false,
221+
topRight: false,
222+
bottomRight: false,
223+
bottomLeft: false,
224+
topLeft: false
225+
}}
226+
style={{ zIndex: 100 }}
227+
>
215228
{drawerIsVisible &&
216229
getContentToShow(
217230
this.props.selectedDrawerName || this.state.closingDrawerName
218231
)}
219-
</StyledDrawer>
220-
</Resizable>
232+
</Resizable>
233+
</StyledDrawer>
221234
</StyledSidebar>
222235
)
223236
}

src/browser/modules/DBMSInfo/DBMSInfo.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { UserDetails } from './UserDetails'
2828
import {
2929
Drawer,
3030
DrawerBody,
31+
DrawerExternalLink,
3132
DrawerHeader
3233
} from 'browser-components/drawer/drawer-styled'
3334
import {
@@ -37,8 +38,14 @@ import {
3738
} from 'shared/modules/commands/commandsDuck'
3839
import { getUseDb } from 'shared/modules/connections/connectionsDuck'
3940
import { getCurrentUser } from 'shared/modules/currentUser/currentUserDuck'
40-
import { getDatabases } from 'shared/modules/dbMeta/dbMetaDuck'
41+
import {
42+
forceCount,
43+
getCountAutomaticRefreshLoading,
44+
getCountAutomaticRefreshEnabled,
45+
getDatabases
46+
} from 'shared/modules/dbMeta/dbMetaDuck'
4147
import { getGraphStyleData } from 'shared/modules/grass/grassDuck'
48+
import { Button } from '@neo4j-ndl/react'
4249

4350
export function DBMSInfo(props: any): JSX.Element {
4451
const moreStep = 50
@@ -77,6 +84,23 @@ export function DBMSInfo(props: any): JSX.Element {
7784
selectedDb={useDb}
7885
onChange={onDbSelect}
7986
/>
87+
{!props.countAutoRefreshing && (
88+
<>
89+
<p>
90+
Automatic updates of node and relationship counts have been
91+
disabled for performance reasons, likely due to{' '}
92+
<DrawerExternalLink href="https://neo4j.com/docs/cypher-manual/current/access-control/limitations/#access-control-limitations-db-operations">
93+
RBAC configuration.
94+
</DrawerExternalLink>
95+
</p>
96+
<Button
97+
loading={props.countLoading}
98+
onClick={() => props.forceCount()}
99+
>
100+
Refresh counts
101+
</Button>
102+
</>
103+
)}
80104
<LabelItems
81105
count={nodes}
82106
labels={labels.slice(0, maxLabelsCount)}
@@ -115,12 +139,16 @@ export function DBMSInfo(props: any): JSX.Element {
115139
const mapStateToProps = (state: any) => {
116140
const useDb = getUseDb(state)
117141
const databases = getDatabases(state)
142+
const countAutoRefreshing = getCountAutomaticRefreshEnabled(state)
143+
const countLoading = getCountAutomaticRefreshLoading(state)
118144
return {
119145
graphStyleData: getGraphStyleData(state),
120146
meta: state.meta,
121147
user: getCurrentUser(state),
122148
useDb,
123-
databases
149+
databases,
150+
countAutoRefreshing,
151+
countLoading
124152
}
125153
}
126154
const mapDispatchToProps = (dispatch: any, ownProps: any) => {
@@ -129,6 +157,9 @@ const mapDispatchToProps = (dispatch: any, ownProps: any) => {
129157
const action = executeCommand(cmd, { source: commandSources.button })
130158
ownProps.bus.send(action.type, action)
131159
},
160+
forceCount: () => {
161+
dispatch(forceCount())
162+
},
132163
onDbSelect: (dbName: any) =>
133164
dispatch(executeCommand(`:${useDbCommand} ${dbName || ''}`), {
134165
source: commandSources.button

src/shared/modules/dbMeta/__snapshots__/dbMetaDuck.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
exports[`hydrating state can CLEAR to reset state 1`] = `
44
Object {
5+
"countAutomaticRefresh": Object {
6+
"enabled": true,
7+
"loading": false,
8+
},
59
"databases": Array [],
610
"functions": Array [],
711
"labels": Array [],
@@ -62,6 +66,10 @@ Object {
6266

6367
exports[`hydrating state should merge inital state and state on load 1`] = `
6468
Object {
69+
"countAutomaticRefresh": Object {
70+
"enabled": true,
71+
"loading": false,
72+
},
6573
"databases": Array [],
6674
"foo": "bar",
6775
"functions": Array [],

src/shared/modules/dbMeta/dbMetaDuck.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ export const UPDATE_SETTINGS = 'meta/UPDATE_SETTINGS'
3131
export const CLEAR_META = 'meta/CLEAR'
3232
export const FORCE_FETCH = 'meta/FORCE_FETCH'
3333
export const DB_META_DONE = 'meta/DB_META_DONE'
34+
export const DB_META_COUNT_DONE = 'meta/DB_META_COUNT_DONE'
35+
export const DB_META_FORCE_COUNT = 'meta/DB_FORCE_COUNT'
36+
export const UPDATE_COUNT_AUTOMATIC_REFRESH =
37+
'meta/UPDATE_COUNT_AUTOMATIC_REFRESH'
3438

3539
export const SYSTEM_DB = 'system'
3640
export const VERSION_FOR_EDITOR_HISTORY_SETTING = '4.3.0'
3741
export const VERSION_FOR_CLUSTER_ROLE_IN_SHOW_DB = '4.3.0'
3842

39-
export const metaQuery = `
43+
export const metaTypesQuery = `
4044
CALL db.labels() YIELD label
4145
RETURN {name:'labels', data:COLLECT(label)[..1000]} AS result
4246
UNION ALL
@@ -45,7 +49,9 @@ RETURN {name:'relationshipTypes', data:COLLECT(relationshipType)[..1000]} AS res
4549
UNION ALL
4650
CALL db.propertyKeys() YIELD propertyKey
4751
RETURN {name:'propertyKeys', data:COLLECT(propertyKey)[..1000]} AS result
48-
UNION ALL
52+
`
53+
54+
export const metaCountQuery = `
4955
MATCH () RETURN { name:'nodes', data:count(*) } AS result
5056
UNION ALL
5157
MATCH ()-[]->() RETURN { name:'relationships', data: count(*)} AS result
@@ -60,6 +66,12 @@ export function fetchMetaData() {
6066
}
6167
}
6268

69+
export function forceCount() {
70+
return {
71+
type: DB_META_FORCE_COUNT
72+
}
73+
}
74+
6375
export const update = (obj: any) => {
6476
return {
6577
type: UPDATE_META,
@@ -82,6 +94,16 @@ export const updateServerInfo = (res: any) => {
8294
}
8395
}
8496

97+
export const updateCountAutomaticRefresh = (countAutomaticRefresh: {
98+
enabled?: boolean
99+
loading?: boolean
100+
}) => {
101+
return {
102+
type: UPDATE_COUNT_AUTOMATIC_REFRESH,
103+
countAutomaticRefresh
104+
}
105+
}
106+
85107
export type Procedure = {
86108
name: string
87109
description: string
@@ -136,7 +158,11 @@ export const initialState = {
136158
},
137159
databases: [],
138160
serverConfigDone: false,
139-
settings: initialClientSettings
161+
settings: initialClientSettings,
162+
countAutomaticRefresh: {
163+
enabled: true,
164+
loading: false
165+
}
140166
}
141167

142168
export type Database = {
@@ -263,6 +289,18 @@ export const getClusterRoleForDb = (state: GlobalState, activeDb: string) => {
263289
}
264290
}
265291

292+
export const getCountAutomaticRefreshEnabled = (
293+
state: GlobalState
294+
): boolean => {
295+
return state[NAME].countAutomaticRefresh.enabled
296+
}
297+
298+
export const getCountAutomaticRefreshLoading = (
299+
state: GlobalState
300+
): boolean => {
301+
return state[NAME].countAutomaticRefresh.loading
302+
}
303+
266304
// Reducers
267305
const dbMetaReducer = (
268306
state = initialState,
@@ -274,6 +312,14 @@ const dbMetaReducer = (
274312
case UPDATE_META:
275313
const { type, ...rest } = action
276314
return { ...state, ...rest }
315+
case UPDATE_COUNT_AUTOMATIC_REFRESH:
316+
return {
317+
...state,
318+
countAutomaticRefresh: {
319+
...state.countAutomaticRefresh,
320+
...action.countAutomaticRefresh
321+
}
322+
}
277323
case UPDATE_SERVER:
278324
const { type: serverType, ...serverRest } = action
279325
const serverState: any = {}

0 commit comments

Comments
 (0)