Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for the calendar versioning #1990

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/browser/components/ManualLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ const movedPages: [
text: 'Indexes',
url: 'https://neo4j.com/docs/cypher-manual/4.3/indexes-for-search-performance/'
}
],
[
{
neo4jVersion: '2025.01.0',
page: '/administration/indexes-for-search-performance/'
},
{
text: 'Indexes',
url: 'https://neo4j.com/docs/cypher-manual/current/indexes-for-search-performance/'
}
]
]

Expand Down
31 changes: 19 additions & 12 deletions src/browser/components/ManualLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import semver from 'semver'
import { DrawerExternalLink } from './drawer/drawer-styled'
import { formatDocVersion } from 'browser/modules/Sidebar/docsUtils'
import { GlobalState } from 'project-root/src/shared/globalState'
import { getRawVersion } from 'shared/modules/dbMeta/dbMetaDuck'
import {
getCleanedVersion,
getRawVersion
} from 'shared/modules/dbMeta/dbMetaDuck'

const oldPages: { [key: string]: { oldPage: string; oldContent: string } } = {
'/administration/indexes-for-search-performance/': {
Expand Down Expand Up @@ -60,21 +63,25 @@ 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 = getCleanedVersion(neo4jVersion)
return 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 = getCleanedVersion(neo4jVersion)
return (
(cleanedVersion && semver.satisfies(cleanedVersion, '>=4.3')) ||
neo4jVersion === null
)
}

export type ManualLinkProps = {
chapter: string
Expand Down Expand Up @@ -103,7 +110,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
16 changes: 16 additions & 0 deletions src/browser/components/VersionConditionalDoc.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ const tests: [Omit<VersionConditionalDocProps, 'children'>, boolean][] = [
includeCurrent: false
},
true
],
[
{
neo4jVersion: '2025.03.0',
versionCondition: '>=4.3',
includeCurrent: false
},
true
],
[
{
neo4jVersion: '2025.03.0',
versionCondition: '<4.3',
includeCurrent: true
},
false
]
]

Expand Down
10 changes: 6 additions & 4 deletions src/browser/components/VersionConditionalDoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import { connect } from 'react-redux'
import semver from 'semver'

import { GlobalState } from 'project-root/src/shared/globalState'
import { getRawVersion } from 'shared/modules/dbMeta/dbMetaDuck'
import {
getCleanedVersion,
getRawVersion
} from 'shared/modules/dbMeta/dbMetaDuck'

export type VersionConditionalDocProps = {
versionCondition: string
Expand All @@ -36,11 +39,10 @@ export function VersionConditionalDoc({
neo4jVersion,
includeCurrent = false
}: VersionConditionalDocProps): JSX.Element {
const cleanedVersion = getCleanedVersion(neo4jVersion)
if (
(includeCurrent && neo4jVersion === null) ||
(neo4jVersion !== null &&
semver.valid(neo4jVersion) &&
semver.satisfies(neo4jVersion, versionCondition))
(cleanedVersion && semver.satisfies(cleanedVersion, versionCondition))
) {
return <>{children}</>
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/browser/modules/Sidebar/docsUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ test('formatDocVersion', () => {
{ test: '1.1.0', expect: '1.1' },
{ test: '1.1.0-beta01', expect: '1.1-preview' },
{ test: '1.1.2', expect: '1.1' },
{ test: '2.1.10', expect: '2.1' }
{ test: '2.1.10', expect: '2.1' },
{ test: '2025.01.0', expect: 'current' },
{ test: '2024.11.10', expect: 'current' }
]

tests.forEach(t => expect(formatDocVersion(t.test)).toEqual(t.expect))
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
14 changes: 12 additions & 2 deletions src/browser/modules/Sidebar/static-scripts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describe('<Favorites />', () => {
content: !script.content.includes('Show meta-graph')
? script.content
: script.versionRange === '>=3 <4'
? script.content.replace('Show meta-graph', 'Show meta-graph v3')
: script.content.replace('Show meta-graph', 'Show meta-graph v4')
? script.content.replace('Show meta-graph', 'Show meta-graph v3')
: script.content.replace('Show meta-graph', 'Show meta-graph v4')
}))

const renderWithDBMSVersion = (version: any) => {
Expand Down Expand Up @@ -83,4 +83,14 @@ describe('<Favorites />', () => {
expect(queryByText('Show meta-graph v3')).toBeFalsy()
expect(queryByText('Show meta-graph v4')).toBeTruthy()
})

it('lists examples correctly when using calendar version', () => {
const version = '2025.01.0'
const { queryByText } = renderWithDBMSVersion(version)

fireEvent.click(queryByText('Common Procedures') as HTMLElement)

expect(queryByText('Show meta-graph v3')).toBeFalsy()
expect(queryByText('Show meta-graph v4')).toBeTruthy()
})
})
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
13 changes: 10 additions & 3 deletions src/browser/modules/Stream/SchemaFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import Directives from 'browser-components/Directives'
import { GlobalState } from 'project-root/src/shared/globalState'
import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
import { getSemanticVersion } from 'shared/modules/dbMeta/dbMetaDuck'
import {
getCleanedVersion,
getSemanticVersion
} from 'shared/modules/dbMeta/dbMetaDuck'

type IndexesProps = {
indexes: any
Expand Down Expand Up @@ -192,13 +195,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 +216,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 +249,10 @@ export class SchemaFrame extends Component<any, SchemaFrameState> {
render(): JSX.Element {
const { neo4jVersion } = this.props
const { indexes, constraints } = this.state
const cleanedVersion =
typeof neo4jVersion === 'string' ? getCleanedVersion(neo4jVersion) : null
const schemaCommand =
semver.valid(neo4jVersion) && semver.satisfies(neo4jVersion, '<=3.4.*')
cleanedVersion && semver.satisfies(cleanedVersion, '<=3.4.*')
? 'CALL db.schema()'
: 'CALL db.schema.visualization'

Expand Down
13 changes: 11 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, valid } 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 @@ -270,8 +270,17 @@ 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 getCleanedVersion = (version: string | null): string | null => {
const cleanedVersion = clean(version || '', true)
if (valid(cleanedVersion)) {
return cleanedVersion
}
return null
}

export const supportsMultiDb = (state: GlobalState): boolean => {
const version = getSemanticVersion(state)
Expand Down
14 changes: 11 additions & 3 deletions src/shared/modules/dbMeta/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { Integer, QueryResult } from 'neo4j-driver'
import semver from 'semver'

import { guessSemverVersion } from '../features/featureDuck.utils'
import { TrialStatus, VERSION_FOR_EDITOR_HISTORY_SETTING } from './dbMetaDuck'
import {
getCleanedVersion,
TrialStatus,
VERSION_FOR_EDITOR_HISTORY_SETTING
} from './dbMetaDuck'

type ServerInfo = {
version: string | null
Expand Down Expand Up @@ -52,7 +56,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 (!getCleanedVersion(serverInfo.version)) {
serverInfo.version = guessSemverVersion(serverInfo.version)
}

Expand Down Expand Up @@ -113,5 +117,9 @@ 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 = getCleanedVersion(version)
return (
cleanedVersion &&
semver.gte(cleanedVersion, VERSION_FOR_EDITOR_HISTORY_SETTING)
)
}
6 changes: 5 additions & 1 deletion src/shared/modules/features/featureDuck.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ describe('guessSemverVersion', () => {
['3.5.3', '3.5.3'],
['3.5', '3.5.0'],
['3.5-test', '3.5.0'],
['4.0-aura', '4.0.0']
['4.0-aura', '4.0.0'],
['2025.01.0', '2025.1.0'],
['2025.07.15-1242', '2025.7.15-1242'],
['2025.12.1', '2025.12.1'],
['2025.1.1', '2025.1.1']
]

test.each(tests)(
Expand Down
7 changes: 5 additions & 2 deletions src/shared/modules/features/featureDuck.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import semver from 'semver'
import { getCleanedVersion } from '../dbMeta/dbMetaDuck'

export const guessSemverVersion = (versionString: string | null) => {
if (!versionString) {
return null
}
if (semver.valid(versionString)) {
return versionString
const cleanedVersion =
typeof versionString === 'string' ? getCleanedVersion(versionString) : null
if (cleanedVersion) {
return cleanedVersion
}

const coerceVersion = semver.coerce(versionString)
Expand Down
Loading