Skip to content

Commit db1def4

Browse files
Avoid running SHOW ALIASES to show only non-composite aliases in database dropdown (#1964)
* Revert "show only non-composite aliases in drop down (#1947)" This reverts commit 5a96987. * filter out composite aliases
1 parent 53514c9 commit db1def4

File tree

6 files changed

+39
-103
lines changed

6 files changed

+39
-103
lines changed

src/browser/modules/DBMSInfo/DBMSInfo.tsx

+3-14
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ import {
4242
forceCount,
4343
getCountAutomaticRefreshLoading,
4444
getCountAutomaticRefreshEnabled,
45-
getUniqueDatabases,
46-
getAliases
45+
getUniqueDatbases
4746
} from 'shared/modules/dbMeta/dbMetaDuck'
4847
import { getGraphStyleData } from 'shared/modules/grass/grassDuck'
4948
import { Button } from '@neo4j-ndl/react'
@@ -74,22 +73,14 @@ export function DBMSInfo(props: any): JSX.Element {
7473
nodes,
7574
relationships
7675
} = props.meta
77-
const {
78-
user,
79-
onItemClick,
80-
onDbSelect,
81-
useDb,
82-
uniqueDatabases = [],
83-
aliases
84-
} = props
76+
const { user, onItemClick, onDbSelect, useDb, uniqueDatabases = [] } = props
8577

8678
return (
8779
<Drawer id="db-drawer">
8880
<DrawerHeader>Database Information</DrawerHeader>
8981
<DrawerBody>
9082
<DatabaseSelector
9183
uniqueDatabases={uniqueDatabases}
92-
aliases={aliases}
9384
selectedDb={useDb ?? ''}
9485
onChange={onDbSelect}
9586
/>
@@ -150,16 +141,14 @@ const mapStateToProps = (state: any) => {
150141
const countAutoRefreshing = getCountAutomaticRefreshEnabled(state)
151142
const countLoading = getCountAutomaticRefreshLoading(state)
152143

153-
const uniqueDatabases = getUniqueDatabases(state)
154-
const aliases = getAliases(state)
144+
const uniqueDatabases = getUniqueDatbases(state)
155145

156146
return {
157147
graphStyleData: getGraphStyleData(state),
158148
meta: state.meta,
159149
user: getCurrentUser(state),
160150
useDb,
161151
uniqueDatabases,
162-
aliases,
163152
countAutoRefreshing,
164153
countLoading
165154
}

src/browser/modules/DBMSInfo/DatabaseSelector.test.tsx

+4-22
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ describe('DatabaseSelector', () => {
4545

4646
// When
4747
const { container } = render(
48-
<DatabaseSelector
49-
selectedDb=""
50-
uniqueDatabases={databases}
51-
aliases={[]}
52-
/>
48+
<DatabaseSelector selectedDb="" uniqueDatabases={databases} />
5349
)
5450

5551
// Then
@@ -62,11 +58,7 @@ describe('DatabaseSelector', () => {
6258

6359
// When
6460
const { getByDisplayValue, queryByDisplayValue, rerender } = render(
65-
<DatabaseSelector
66-
uniqueDatabases={databases}
67-
selectedDb={selected}
68-
aliases={[]}
69-
/>
61+
<DatabaseSelector uniqueDatabases={databases} selectedDb={selected} />
7062
)
7163

7264
// Then
@@ -76,11 +68,7 @@ describe('DatabaseSelector', () => {
7668
// When
7769
selected = 'molly'
7870
rerender(
79-
<DatabaseSelector
80-
uniqueDatabases={databases}
81-
selectedDb={selected}
82-
aliases={[]}
83-
/>
71+
<DatabaseSelector uniqueDatabases={databases} selectedDb={selected} />
8472
)
8573

8674
// Then
@@ -90,11 +78,7 @@ describe('DatabaseSelector', () => {
9078
// When
9179
selected = ''
9280
rerender(
93-
<DatabaseSelector
94-
uniqueDatabases={databases}
95-
selectedDb={selected}
96-
aliases={[]}
97-
/>
81+
<DatabaseSelector uniqueDatabases={databases} selectedDb={selected} />
9882
)
9983

10084
// Then select db text should be shown
@@ -113,7 +97,6 @@ describe('DatabaseSelector', () => {
11397
uniqueDatabases={databases}
11498
selectedDb=""
11599
onChange={onChange}
116-
aliases={[]}
117100
/>
118101
)
119102
const select = getByTestId(testId)
@@ -143,7 +126,6 @@ describe('DatabaseSelector', () => {
143126
selectedDb=""
144127
uniqueDatabases={databases}
145128
onChange={onChange}
146-
aliases={[]}
147129
/>
148130
)
149131
const select = getByTestId(testId)

src/browser/modules/DBMSInfo/DatabaseSelector.tsx

+21-20
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
DrawerSubHeader
2727
} from 'browser-components/drawer/drawer-styled'
2828
import { escapeCypherIdentifier } from 'services/utils'
29-
import { Alias, Database } from 'shared/modules/dbMeta/dbMetaDuck'
29+
import { Database } from 'shared/modules/dbMeta/dbMetaDuck'
3030

3131
const Select = styled.select`
3232
width: 100%;
@@ -43,12 +43,10 @@ type DatabaseSelectorProps = {
4343
uniqueDatabases?: Database[]
4444
selectedDb: string
4545
onChange?: (dbName: string) => void
46-
aliases: Alias[]
4746
}
4847
export const DatabaseSelector = ({
4948
uniqueDatabases = [],
5049
selectedDb,
51-
aliases,
5250
onChange = () => undefined
5351
}: DatabaseSelectorProps): JSX.Element | null => {
5452
if (uniqueDatabases.length === 0) {
@@ -66,23 +64,26 @@ export const DatabaseSelector = ({
6664
uniqueDatabases.find(db => db.home) ||
6765
uniqueDatabases.find(db => db.default)
6866

69-
const aliasList = aliases.flatMap(alias => {
70-
const aliasedDb = uniqueDatabases.find(db => db.name === alias.database)
71-
72-
// Don't show composite aliases since they can't be queried directly
73-
if (alias.composite) {
74-
return []
75-
}
76-
77-
if (aliasedDb === undefined) {
78-
return []
79-
}
80-
81-
return {
82-
name: alias.name,
83-
status: aliasedDb.status
84-
}
85-
})
67+
const aliasList = uniqueDatabases.flatMap(db =>
68+
db.aliases
69+
? db.aliases
70+
.map(alias => ({
71+
databaseName: db.name,
72+
name: alias,
73+
status: db.status
74+
}))
75+
.filter(
76+
// If the alias points to a composite database and the alias is listed as
77+
// one of the constituents, we don't want to show it as it's not directly queryable
78+
alias =>
79+
!uniqueDatabases.some(
80+
db =>
81+
db.type === 'composite' &&
82+
db.constituents?.includes(alias.name)
83+
)
84+
)
85+
: []
86+
)
8687

8788
const databasesAndAliases = [...aliasList, ...uniqueDatabases].sort((a, b) =>
8889
a.name.localeCompare(b.name)

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

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
exports[`hydrating state can CLEAR to reset state 1`] = `
44
Object {
5-
"aliases": Array [],
65
"countAutomaticRefresh": Object {
76
"enabled": true,
87
"loading": false,
@@ -70,7 +69,6 @@ Object {
7069

7170
exports[`hydrating state should merge inital state and state on load 1`] = `
7271
Object {
73-
"aliases": Array [],
7472
"countAutomaticRefresh": Object {
7573
"enabled": true,
7674
"loading": false,

src/shared/modules/dbMeta/dbMetaDuck.ts

+10-22
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20+
import { uniq } from 'lodash-es'
21+
import { QueryResult } from 'neo4j-driver'
22+
import { SemVer, coerce, gte } from 'semver'
23+
import { isConfigValFalsy } from 'services/bolt/boltHelpers'
24+
import { GlobalState } from 'shared/globalState'
25+
import { APP_START } from 'shared/modules/app/appDuck'
26+
import { FIRST_MULTI_DB_SUPPORT } from '../features/versionedFeatures'
2027
import {
28+
extractServerInfo,
2129
extractTrialStatus,
2230
extractTrialStatusOld,
2331
versionHasEditorHistorySetting
2432
} from './utils'
25-
import { isConfigValFalsy } from 'services/bolt/boltHelpers'
26-
import { GlobalState } from 'shared/globalState'
27-
import { APP_START } from 'shared/modules/app/appDuck'
28-
import { extractServerInfo } from './utils'
29-
import { coerce, SemVer, gte } from 'semver'
30-
import { QueryResult } from 'neo4j-driver'
31-
import { uniq } from 'lodash-es'
32-
import { FIRST_MULTI_DB_SUPPORT } from '../features/versionedFeatures'
3333

3434
export const UPDATE_META = 'meta/UPDATE_META'
3535
export const PARSE_META = 'meta/PARSE_META'
@@ -206,7 +206,6 @@ export const initialState = {
206206
storeSize: null
207207
},
208208
databases: [],
209-
aliases: [],
210209
serverConfigDone: false,
211210
settings: initialClientSettings,
212211
countAutomaticRefresh: {
@@ -227,17 +226,10 @@ export type Database = {
227226
home?: boolean // introduced in neo4j 4.3
228227
aliases?: string[] // introduced in neo4j 4.4
229228
type?: 'system' | 'composite' | 'standard' // introduced in neo4j 5
229+
constituents?: string[] // introduced in neo4j 5
230230
status: string
231231
}
232232

233-
export const ALIAS_COMPOSITE_FIELD_FIRST_VERSION = '5.11.0'
234-
export type Alias = {
235-
name: string
236-
database: string
237-
location: string
238-
composite?: string | null // introduced in neo4j 5.11
239-
}
240-
241233
// Selectors
242234
export function findDatabaseByNameOrAlias(
243235
state: GlobalState,
@@ -258,7 +250,7 @@ export function findDatabaseByNameOrAlias(
258250
)
259251
}
260252

261-
export function getUniqueDatabases(state: GlobalState): Database[] {
253+
export function getUniqueDatbases(state: GlobalState): Database[] {
262254
const uniqueDatabaseNames = uniq(
263255
state[NAME].databases.map((db: Database) => db.name)
264256
)
@@ -344,10 +336,6 @@ export const getMetricsPrefix = (state: GlobalState): string =>
344336

345337
export const getDatabases = (state: any): Database[] =>
346338
(state[NAME] || initialState).databases
347-
348-
export const getAliases = (state: any): null | Alias[] =>
349-
(state[NAME] || initialState).aliases
350-
351339
export const getActiveDbName = (state: any) =>
352340
((state[NAME] || {}).settings || {})['dbms.active_database']
353341

src/shared/modules/dbMeta/dbMetaEpics.ts

+1-23
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,6 @@ async function databaseList(store: any) {
135135
} catch {}
136136
}
137137

138-
async function aliasList(store: any) {
139-
try {
140-
const hasMultidb = supportsMultiDb(store.getState())
141-
if (!hasMultidb) {
142-
return
143-
}
144-
145-
const res = await bolt.backgroundWorkerlessRoutedRead(
146-
'SHOW ALIASES FOR DATABASE',
147-
{ useDb: SYSTEM_DB },
148-
store
149-
)
150-
151-
if (!res) return
152-
153-
const aliases = res.records.map((record: any) => record.toObject())
154-
155-
store.dispatch(update({ aliases }))
156-
} catch {}
157-
}
158-
159138
async function getLabelsAndTypes(store: any) {
160139
const db = getCurrentDatabase(store.getState())
161140

@@ -416,8 +395,7 @@ async function pollDbMeta(store: any) {
416395
await Promise.all([
417396
getFunctionsAndProcedures(store),
418397
clusterRole(store),
419-
databaseList(store),
420-
aliasList(store)
398+
databaseList(store)
421399
])
422400
}
423401

0 commit comments

Comments
 (0)