-
- {SHOW_LATEST_RCS}
-
+
+
+ {SHOW_LATEST_RCS}
+
+
+
+
+ {USE_YARN_PLUGIN}
+
+
>
}
trigger="click"
diff --git a/src/components/common/VersionSelector.js b/src/components/common/VersionSelector.js
index 2a253c93..e896a071 100644
--- a/src/components/common/VersionSelector.js
+++ b/src/components/common/VersionSelector.js
@@ -9,6 +9,8 @@ import UpgradeButton from './UpgradeButton'
import { updateURL } from '../../utils/update-url'
import { deviceSizes } from '../../utils/device-sizes'
import { useReleases } from '../../ReleaseProvider'
+import { useSettings } from '../../SettingsProvider'
+import { SHOW_LATEST_RCS, USE_YARN_PLUGIN } from '../../utils'
export const testIDs = {
fromVersionSelector: 'fromVersionSelector',
@@ -174,13 +176,52 @@ const doesVersionExist = ({ version, allVersions, minVersion }) => {
}
}
+const getDefaultToVersion = releases => releases[0]
+
+const getDefaultFromVersion = (toVersion, releases, showReleaseCandidates) => {
+ // Remove `rc` versions from the array of versions
+ const sanitizedVersionsWithReleases = getReleasedVersionsWithCandidates({
+ releasedVersions: releases,
+ toVersion,
+ latestVersion: releases[0].version,
+ showReleaseCandidates
+ })
+
+ const sanitizedVersions = sanitizedVersionsWithReleases.map(
+ ({ version }) => version
+ )
+
+ const version =
+ getFirstRelease(
+ {
+ releasedVersions: sanitizedVersions,
+ versionToCompare: toVersion.version
+ },
+ 'minor'
+ ) ||
+ getFirstRelease(
+ {
+ releasedVersions: sanitizedVersions,
+ versionToCompare: toVersion.version
+ },
+ 'patch'
+ )
+
+ return sanitizedVersionsWithReleases.find(value => value.version === version)
+}
+
const VersionSelector = ({
packageName,
language,
isPackageNameDefinedInURL,
- showDiff,
- showReleaseCandidates
+ showDiff
}) => {
+ const {
+ settings: {
+ [SHOW_LATEST_RCS]: showReleaseCandidates,
+ [USE_YARN_PLUGIN]: useYarnPlugin
+ }
+ } = useSettings()
const [allVersions, setAllVersions] = useState([])
const [fromVersionList, setFromVersionList] = useState([])
const [toVersionList, setToVersionList] = useState([])
@@ -300,15 +341,14 @@ const VersionSelector = ({
})
)
- if (hasVersionsFromURL) {
- upgradeButtonEl.current.props.onClick()
- }
+ upgradeButtonEl.current.props.onClick()
}, [
isLoading,
allVersions,
localFromVersion,
localToVersion,
hasVersionsFromURL,
+ releases,
showReleaseCandidates
])
@@ -316,15 +356,20 @@ const VersionSelector = ({
const resolveDiffVersion = targetVersion =>
releases.find(r => r.version === targetVersion)
+ const to =
+ resolveDiffVersion(localToVersion) || getDefaultToVersion(releases)
+ const from =
+ resolveDiffVersion(localFromVersion) ||
+ getDefaultFromVersion(to, releases, showReleaseCandidates)
+
setSelectedVersions({
- from: resolveDiffVersion(localFromVersion),
- to: resolveDiffVersion(localToVersion)
+ from,
+ to
})
showDiff({
- fromVersion:
- resolveDiffVersion(localFromVersion)?.createApp || localFromVersion,
- toVersion: resolveDiffVersion(localToVersion)?.createApp || localToVersion
+ fromVersion: from[useYarnPlugin ? 'version' : 'createApp'],
+ toVersion: to[useYarnPlugin ? 'version' : 'createApp']
})
updateURL({
@@ -340,6 +385,7 @@ const VersionSelector = ({
{
const [toVersion, setToVersion] = useState('')
const [shouldShowDiff, setShouldShowDiff] = useState(false)
// const [releases, setReleases] = useState({})
- const [settings, setSettings] = useLocalStorage(
- 'backstage:upgrade-helper:settings',
- {
- [`${SHOW_LATEST_RCS}`]: false
- }
- )
const [appName /* setAppName */] = useState('')
useEffect(() => {
@@ -117,66 +110,64 @@ const Home = () => {
setShouldShowDiff(true)
}
- const handleSettingsChange = settingsValues => {
- setSettings(settingsValues)
- }
-
return (
-
-
-
-
-
-
-
-
- Backstage Upgrade Helper
-
-
-
-
- Star
-
-
-
-
- Keeping Backstage Updated
+
+
+
+
+
+
+
+
+
+ Backstage Upgrade Helper
-
-
-
-
-
-
-
+
+
+ Star
+
+
+
+
+ Keeping Backstage Updated
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
)
}
diff --git a/src/hooks/fetch-diff.js b/src/hooks/fetch-diff.js
index ffc24e14..6980673e 100644
--- a/src/hooks/fetch-diff.js
+++ b/src/hooks/fetch-diff.js
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { parseDiff } from 'react-diff-view'
-import { getDiffURL } from '../utils'
+import { getDiffURL, USE_YARN_PLUGIN } from '../utils'
+import { useSettings } from '../SettingsProvider'
const delay = ms => new Promise(res => setTimeout(res, ms))
@@ -14,6 +15,9 @@ export const useFetchDiff = ({
fromVersion,
toVersion
}) => {
+ const {
+ settings: { [USE_YARN_PLUGIN]: useYarnPlugin }
+ } = useSettings()
const [isLoading, setIsLoading] = useState(true)
const [isDone, setIsDone] = useState(false)
const [diff, setDiff] = useState(undefined)
@@ -24,7 +28,15 @@ export const useFetchDiff = ({
setIsDone(false)
const [response] = await Promise.all([
- fetch(getDiffURL({ packageName, language, fromVersion, toVersion })),
+ fetch(
+ getDiffURL({
+ packageName,
+ language,
+ fromVersion,
+ toVersion,
+ useYarnPlugin
+ })
+ ),
delay(300)
])
diff --git a/src/hooks/fetch-release-versions.js b/src/hooks/fetch-release-versions.js
index 19124806..c131e859 100644
--- a/src/hooks/fetch-release-versions.js
+++ b/src/hooks/fetch-release-versions.js
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
import { getReleasesFileURL } from '../utils'
import compare from 'semver/functions/rcompare'
-export const useFetchReleases = ({ packageName }) => {
+export const useFetchReleases = ({ packageName, useYarnPlugin }) => {
const [isLoading, setIsLoading] = useState(true)
const [isDone, setIsDone] = useState(false)
const [releases, setReleases] = useState(undefined)
@@ -12,7 +12,7 @@ export const useFetchReleases = ({ packageName }) => {
setIsLoading(true)
setIsDone(false)
const response = await (
- await fetch(getReleasesFileURL({ packageName }))
+ await fetch(getReleasesFileURL({ packageName, useYarnPlugin }))
).json()
const _releases = Object.entries(response)
@@ -27,7 +27,7 @@ export const useFetchReleases = ({ packageName }) => {
}
fetchReleaseVersions()
- }, [packageName])
+ }, [packageName, useYarnPlugin])
return {
isLoading,
diff --git a/src/utils.js b/src/utils.js
index 514d2aa3..876a4aec 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -12,12 +12,14 @@ const getRNDiffRepository = ({ packageName }) =>
const getDiffBranch = ({ packageName }) =>
packageName === PACKAGE_NAMES.BACKSTAGE ? 'master' : 'diffs'
-export const getReleasesFileURL = ({ packageName }) =>
+export const getReleasesFileURL = ({ packageName, useYarnPlugin }) =>
`https://raw.githubusercontent.com/${getRNDiffRepository({
packageName
})}/${DIFF_BASE_BRANCH}/${
packageName === PACKAGE_NAMES.BACKSTAGE
- ? 'releases.json'
+ ? useYarnPlugin
+ ? 'releases-yarn-plugin.json'
+ : 'releases.json'
: packageName === PACKAGE_NAMES.RNM
? 'RELEASES_MAC'
: packageName === PACKAGE_NAMES.RNM
@@ -29,7 +31,8 @@ export const getDiffURL = ({
packageName,
language,
fromVersion,
- toVersion
+ toVersion,
+ useYarnPlugin
}) => {
// eslint-disable-next-line no-unused-vars
const languageDir =
@@ -41,7 +44,9 @@ export const getDiffURL = ({
return `https://raw.githubusercontent.com/${getRNDiffRepository({
packageName
- })}/${getDiffBranch({ packageName })}/diffs/${fromVersion}..${toVersion}.diff`
+ })}/${getDiffBranch({ packageName })}/${
+ useYarnPlugin ? 'diffs-yarn-plugin' : 'diffs'
+ }/${fromVersion}..${toVersion}.diff`
}
// `path` must contain `RnDiffApp` prefix
@@ -111,6 +116,7 @@ export const getTransitionDuration = duration =>
// settings constants
export const SHOW_LATEST_RCS = 'Show all next releases'
+export const USE_YARN_PLUGIN = 'Use yarn plugin'
export const getFilePathsToShow = ({ oldPath, newPath, appName }) => {
const oldPathSanitized = replaceWithProvidedAppName(oldPath, appName)