From 1ba123baa3a972ac3e30497df2cb1c24198c7a3a Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Fri, 31 Jan 2025 20:47:09 +0100 Subject: [PATCH] small tweaks --- src/components/common/VersionSelector.tsx | 2 +- src/components/pages/Home.tsx | 50 +++++++++++++++++++---- src/hooks/fetch-diff.ts | 42 +++++++++++-------- 3 files changed, 68 insertions(+), 26 deletions(-) diff --git a/src/components/common/VersionSelector.tsx b/src/components/common/VersionSelector.tsx index 4a6d22b5..5f1ec0a3 100644 --- a/src/components/common/VersionSelector.tsx +++ b/src/components/common/VersionSelector.tsx @@ -458,7 +458,7 @@ const VersionSelector = ({ key={'from-' + useYarnPlugin} showSearch data-testid={testIDs.fromVersionSelector} - title={`What's your current Backstage release or @backstage/create-app (0.4.x) version?`} + title={`What's your current Backstage version?`} loading={isLoading} value={localFromVersion} options={fromVersionList} diff --git a/src/components/pages/Home.tsx b/src/components/pages/Home.tsx index e885723a..14b102a1 100644 --- a/src/components/pages/Home.tsx +++ b/src/components/pages/Home.tsx @@ -1,4 +1,8 @@ -import React, { useState, useEffect /* useDeferredValue */ } from 'react' +import React, { + useState, + useEffect /* useDeferredValue */, + ComponentProps, +} from 'react' import styled from '@emotion/styled' import { ThemeProvider } from '@emotion/react' import { Card, ConfigProvider, theme } from 'antd' @@ -7,7 +11,7 @@ import GitHubButton, { ReactGitHubButtonProps } from 'react-github-btn' import createPersistedState from 'use-persisted-state' // import queryString from 'query-string' import VersionSelector from '../common/VersionSelector' -import DiffViewer from '../common/DiffViewer' +import DiffViewer, { DiffViewerProps } from '../common/DiffViewer' import Settings from '../common/Settings' // @ts-ignore-next-line import logo from '../../assets/logo.svg' @@ -19,6 +23,9 @@ import { ReleasesProvider } from '../../ReleaseProvider' import { SettingsProvider } from '../../SettingsProvider' import { lightTheme, darkTheme, type Theme } from '../../theme' import pkg from '../../../package.json' +import { getChangelogURL } from '../../utils' +import { PACKAGE_NAMES } from '../../constants' +import { Link } from '../common/Markdown' const homepage = pkg.homepage @@ -124,7 +131,6 @@ const Home = () => { const [fromVersion, setFromVersion] = useState('') const [toVersion, setToVersion] = useState('') const [shouldShowDiff, setShouldShowDiff] = useState(false) - // const [releases, setReleases] = useState({}) const [appName /* setAppName */] = useState('') // const homepageUrl = process.env.PUBLIC_URL @@ -143,9 +149,9 @@ const Home = () => { fromVersion: string toVersion: string }) => { - if (fromVersion === toVersion) { - return - } + // if (fromVersion === toVersion) { + // return + // } setFromVersion(fromVersion) setToVersion(toVersion) @@ -221,7 +227,7 @@ const Home = () => { isPackageNameDefinedInURL={isPackageNameDefinedInURL} /> - { ) } +function BackstageDiffViewer(props: ComponentProps) { + const { fromVersion, toVersion } = props as unknown as DiffViewerProps + + if (fromVersion && fromVersion === toVersion) { + return ( +
+

+ The selected versions share the same dependencies. This usually + happens when a patch for one of the dependencies is released. +

+

+ Please refer to the{' '} + + changelog + {' '} + to see what has changed. +

+
+ ) + } + return +} + export default Home diff --git a/src/hooks/fetch-diff.ts b/src/hooks/fetch-diff.ts index 093c2165..6719cf45 100644 --- a/src/hooks/fetch-diff.ts +++ b/src/hooks/fetch-diff.ts @@ -5,22 +5,6 @@ import { getDiffURL, USE_YARN_PLUGIN } from '../utils' import sortBy from 'lodash/sortBy' import { useSettings } from '../SettingsProvider' -const excludeYarnLock = ({ oldPath, newPath, ...rest }: File) => - !(oldPath.includes('yarn.lock') || newPath.includes('yarn.lock')) - -const applyCustomSort = (parsedDiff: File[]) => - sortBy(parsedDiff, ({ newPath }: File) => { - if (newPath.includes('package.json')) { - return -1 - } else if (newPath === '.yarnrc.yml') { - return 1 - } else if (newPath.startsWith('.yarn/')) { - return 2 - } - - return 0 - }) - const delay = (ms: number) => new Promise((res) => setTimeout(res, ms)) // const movePackageJsonToTop = (parsedDiff: File[]) => @@ -45,7 +29,7 @@ export const useFetchDiff = ({ } = useSettings() const [isLoading, setIsLoading] = useState(true) const [isDone, setIsDone] = useState(false) - const [diff, setDiff] = useState([]) + const [diff, setDiff] = useState([]) useEffect(() => { const fetchDiff = async () => { @@ -67,7 +51,7 @@ export const useFetchDiff = ({ const diff = await response.text() - setDiff(applyCustomSort(parseDiff(diff).filter(excludeYarnLock))) + setDiff(applyBackstageDiff(response, parseDiff(diff))) setIsLoading(false) setIsDone(true) @@ -86,3 +70,25 @@ export const useFetchDiff = ({ diff, } } + +function applyBackstageDiff(response: Response, parsedDiff: File[]) { + if (response.status === 404) { + return new Error('Diff not found. Please reach out to the maintainers.') + } + + return sortBy(parsedDiff, ({ newPath }: File) => { + if (newPath.includes('package.json')) { + return -1 + } else if (newPath === '.yarnrc.yml') { + return 1 + } else if (newPath.startsWith('.yarn/')) { + return 2 + } + + return 0 + }).filter(excludeYarnLock) +} + +function excludeYarnLock({ oldPath, newPath }: File) { + return !(oldPath.includes('yarn.lock') || newPath.includes('yarn.lock')) +}