Skip to content

Commit

Permalink
adapting calver versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
nnecla committed Dec 16, 2024
1 parent 8dd931d commit 9f196b2
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 24 deletions.
32 changes: 21 additions & 11 deletions src/browser/components/ManualLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 4 additions & 3 deletions src/browser/components/VersionConditionalDoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/browser/modules/Sidebar/docsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion src/browser/modules/Sidebar/static-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ 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)
.filter(
fav =>
fav.isStatic &&
fav.versionRange &&
version &&
semver.satisfies(version, fav.versionRange)
)

Expand Down
9 changes: 7 additions & 2 deletions src/browser/modules/Stream/SchemaFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,14 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
}
}

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()'
Expand All @@ -212,6 +213,7 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
CYPHER_REQUEST,
{
query:
neo4jVersion &&
semver.valid(neo4jVersion) &&
semver.satisfies(neo4jVersion, '<4.2.*')
? 'CALL db.constraints()'
Expand Down Expand Up @@ -244,8 +246,11 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
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'

Expand Down
4 changes: 2 additions & 2 deletions src/shared/modules/dbMeta/dbMetaDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions src/shared/modules/dbMeta/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
)
}
6 changes: 4 additions & 2 deletions src/shared/modules/features/featureDuck.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9f196b2

Please sign in to comment.