diff --git a/src/browser/components/ManualLink.tsx b/src/browser/components/ManualLink.tsx index 8037268b62c..1d35c623c6f 100644 --- a/src/browser/components/ManualLink.tsx +++ b/src/browser/components/ManualLink.tsx @@ -60,21 +60,31 @@ const isPageOld = ( chapter: string, page: string, neo4jVersion: string | null -) => - chapter === 'cypher-manual' && - oldPages[page] && - neo4jVersion && - semver.satisfies(neo4jVersion, '<4.0.0-alpha.1') +) => { + if (chapter !== 'cypher-manual' || !oldPages[page] || !neo4jVersion) + return false + const cleanedVersion = semver.clean(neo4jVersion, true) + return ( + cleanedVersion && + semver.valid(cleanedVersion) && + semver.satisfies(cleanedVersion, '<4.0.0-alpha.1') + ) +} const isPageNew = ( chapter: string, page: string, neo4jVersion: string | null -) => - chapter === 'cypher-manual' && - newPages[page] && - ((neo4jVersion && semver.satisfies(neo4jVersion, '>=4.3')) || - neo4jVersion === null) // if no version is available, we treat it like the newest version. +) => { + if (chapter !== 'cypher-manual' || !newPages[page]) return false + const cleanedVersion = semver.clean(neo4jVersion || '', true) + return ( + (cleanedVersion && + semver.valid(cleanedVersion) && + semver.satisfies(cleanedVersion, '>=4.3')) || + neo4jVersion === null + ) +} export type ManualLinkProps = { chapter: string @@ -103,7 +113,7 @@ export function ManualLink({ let version = formatDocVersion(neo4jVersion) if ( minVersion && - (!neo4jVersion || semver.cmp(neo4jVersion, '<', minVersion)) + (!neo4jVersion || semver.compareLoose(neo4jVersion, minVersion) === -1) ) { version = formatDocVersion(minVersion) } diff --git a/src/browser/components/VersionConditionalDoc.tsx b/src/browser/components/VersionConditionalDoc.tsx index 93d85aa1063..10155095d10 100644 --- a/src/browser/components/VersionConditionalDoc.tsx +++ b/src/browser/components/VersionConditionalDoc.tsx @@ -36,11 +36,12 @@ export function VersionConditionalDoc({ neo4jVersion, includeCurrent = false }: VersionConditionalDocProps): JSX.Element { + const cleanedVersion = semver.clean(neo4jVersion || '', true) if ( (includeCurrent && neo4jVersion === null) || - (neo4jVersion !== null && - semver.valid(neo4jVersion) && - semver.satisfies(neo4jVersion, versionCondition)) + (cleanedVersion && + semver.valid(cleanedVersion) && + semver.satisfies(cleanedVersion, versionCondition)) ) { return <>{children} } else { diff --git a/src/browser/modules/Sidebar/docsUtils.ts b/src/browser/modules/Sidebar/docsUtils.ts index 3e963aea13e..c7de61a9138 100644 --- a/src/browser/modules/Sidebar/docsUtils.ts +++ b/src/browser/modules/Sidebar/docsUtils.ts @@ -24,7 +24,9 @@ export const formatDocVersion = (v: string | null = ''): string => { // All non-strings return return 'current' } - if (semver.prerelease(v)) { + if (semver.compareLoose(v, '6.0.0') === 1) { + return 'current' + } else if (semver.prerelease(v)) { return `${semver.major(v)}.${semver.minor(v)}-preview` } return `${semver.major(v)}.${semver.minor(v)}` || 'current' diff --git a/src/browser/modules/Sidebar/static-scripts.ts b/src/browser/modules/Sidebar/static-scripts.ts index afbaebf99ea..65c0ec08040 100644 --- a/src/browser/modules/Sidebar/static-scripts.ts +++ b/src/browser/modules/Sidebar/static-scripts.ts @@ -29,7 +29,8 @@ import { getRawVersion } from 'shared/modules/dbMeta/dbMetaDuck' import * as editor from 'shared/modules/editor/editorDuck' const mapFavoritesStateToProps = (state: any) => { - const version = semver.coerce(getRawVersion(state) || '0') ?? '0' + const version = + semver.coerce(semver.clean(getRawVersion(state) || '', true) ?? '0') ?? '0' const folders = getFolders(state).filter(folder => folder.isStatic) const scripts = favorites .getFavorites(state) @@ -37,6 +38,7 @@ const mapFavoritesStateToProps = (state: any) => { fav => fav.isStatic && fav.versionRange && + version && semver.satisfies(version, fav.versionRange) ) diff --git a/src/browser/modules/Stream/SchemaFrame.tsx b/src/browser/modules/Stream/SchemaFrame.tsx index 444c98a6ce8..1f4cbf39147 100644 --- a/src/browser/modules/Stream/SchemaFrame.tsx +++ b/src/browser/modules/Stream/SchemaFrame.tsx @@ -192,13 +192,14 @@ export class SchemaFrame extends Component { } } - fetchData(neo4jVersion: SemVer) { + fetchData(neo4jVersion: SemVer | null) { if (this.props.bus) { // Indexes this.props.bus.self( CYPHER_REQUEST, { query: + neo4jVersion && semver.valid(neo4jVersion) && semver.satisfies(neo4jVersion, '<4.2.*') ? 'CALL db.indexes()' @@ -212,6 +213,7 @@ export class SchemaFrame extends Component { CYPHER_REQUEST, { query: + neo4jVersion && semver.valid(neo4jVersion) && semver.satisfies(neo4jVersion, '<4.2.*') ? 'CALL db.constraints()' @@ -244,8 +246,11 @@ export class SchemaFrame extends Component { render(): JSX.Element { const { neo4jVersion } = this.props const { indexes, constraints } = this.state + const cleanedVersion = semver.clean(neo4jVersion || '', true) const schemaCommand = - semver.valid(neo4jVersion) && semver.satisfies(neo4jVersion, '<=3.4.*') + cleanedVersion && + semver.valid(cleanedVersion) && + semver.satisfies(cleanedVersion, '<=3.4.*') ? 'CALL db.schema()' : 'CALL db.schema.visualization' diff --git a/src/shared/modules/dbMeta/dbMetaDuck.ts b/src/shared/modules/dbMeta/dbMetaDuck.ts index 04a2afac638..42c6a706f6c 100644 --- a/src/shared/modules/dbMeta/dbMetaDuck.ts +++ b/src/shared/modules/dbMeta/dbMetaDuck.ts @@ -19,7 +19,7 @@ */ import { uniq } from 'lodash-es' import { QueryResult } from 'neo4j-driver' -import { SemVer, coerce, gte } from 'semver' +import { SemVer, clean, coerce, gte } from 'semver' import { isConfigValFalsy } from 'services/bolt/boltHelpers' import { GlobalState } from 'shared/globalState' import { APP_START } from 'shared/modules/app/appDuck' @@ -271,7 +271,7 @@ export function getUniqueDatbases(state: GlobalState): Database[] { export const getRawVersion = (state: GlobalState): string | null => (state[NAME] || {}).server ? (state[NAME] || {}).server.version : null export const getSemanticVersion = (state: GlobalState): SemVer | null => - coerce(getRawVersion(state)) + coerce(clean(getRawVersion(state) || '', true)) export const supportsMultiDb = (state: GlobalState): boolean => { const version = getSemanticVersion(state) diff --git a/src/shared/modules/dbMeta/utils.ts b/src/shared/modules/dbMeta/utils.ts index a3e0d8c5aee..4e387bc4922 100644 --- a/src/shared/modules/dbMeta/utils.ts +++ b/src/shared/modules/dbMeta/utils.ts @@ -52,7 +52,7 @@ export function extractServerInfo(res: QueryResult): ServerInfo { } // Some aura servers self report versions that need coercing (eg. 3.5 or 4.3-aura) - if (!semver.valid(serverInfo.version)) { + if (!semver.valid(semver.clean(serverInfo.version || '', true))) { serverInfo.version = guessSemverVersion(serverInfo.version) } @@ -113,5 +113,10 @@ export const extractTrialStatusOld = (res: QueryResult): TrialStatus => { export const versionHasEditorHistorySetting = (version: string | null) => { if (!version) return false - return semver.gte(version, VERSION_FOR_EDITOR_HISTORY_SETTING) + const cleanedVersion = semver.clean(version, true) + return ( + cleanedVersion && + semver.valid(cleanedVersion) && + semver.gte(cleanedVersion, VERSION_FOR_EDITOR_HISTORY_SETTING) + ) } diff --git a/src/shared/modules/features/featureDuck.utils.ts b/src/shared/modules/features/featureDuck.utils.ts index db8e0d87d9c..46cd400d872 100644 --- a/src/shared/modules/features/featureDuck.utils.ts +++ b/src/shared/modules/features/featureDuck.utils.ts @@ -23,8 +23,10 @@ export const guessSemverVersion = (versionString: string | null) => { if (!versionString) { return null } - if (semver.valid(versionString)) { - return versionString + const cleanedVersion = + typeof versionString === 'string' ? semver.clean(versionString, true) : null + if (semver.valid(cleanedVersion)) { + return cleanedVersion } const coerceVersion = semver.coerce(versionString)