svelte: Update messaging and icon for switching to/from the prototype (#60049)

This PR removes the tech used from the messaging around the
prototype in the app and changes the icon to a flask which generally
symbolizes the experimental nature of something.
This commit is contained in:
Felix Kling 2024-02-02 15:07:40 +01:00 committed by GitHub
parent 2bfcb37c59
commit 2be0a6d73d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 54 additions and 74 deletions

View File

@ -14,7 +14,6 @@ SRCS = [
".prettierignore",
".env",
".env.dotcom",
"static/react-logo.svg",
"//client/wildcard:sass-breakpoints",
"//client/wildcard:global-style-sources",
"//client/web/dist/img:copy",

View File

@ -1,4 +1,3 @@
export { default as logoLight } from '$root/client/web/dist/img/sourcegraph-logo-light.svg'
export { default as logoDark } from '$root/client/web/dist/img/sourcegraph-logo-dark.svg'
export { default as mark } from '$root/client/web/dist/img/sourcegraph-mark.svg'
export { default as svelteLogoEnabled } from '$root/client/web/dist/img/svelte-logo.svg'

View File

@ -1,7 +1,7 @@
<script lang="ts">
import { mdiBookOutline, mdiChartBar, mdiMagnify } from '@mdi/js'
import { mdiBookOutline, mdiChartBar, mdiFlaskOutline, mdiMagnify } from '@mdi/js'
import { mark, svelteLogoEnabled } from '$lib/images'
import { mark } from '$lib/images'
import HeaderNavLink from './HeaderNavLink.svelte'
import { Button } from '$lib/wildcard'
@ -12,6 +12,7 @@
import CodeMonitoringIcon from '$lib/icons/CodeMonitoring.svelte'
import BatchChangesIcon from '$lib/icons/BatchChanges.svelte'
import type { Header_User } from './Header.gql'
import Icon from '$lib/Icon.svelte'
export let authenticatedUser: Header_User | null | undefined
@ -19,11 +20,11 @@
const urlCopy = new URL(url)
urlCopy.searchParams.delete('feat')
for (let feature of urlCopy.searchParams.getAll('feat')) {
if (feature !== 'enable-sveltekit') {
if (feature !== 'web-next') {
urlCopy.searchParams.append('feat', feature)
}
}
urlCopy.searchParams.append('feat', '-enable-sveltekit')
urlCopy.searchParams.append('feat', '-web-next')
return urlCopy.toString()
})($page.url)
</script>
@ -51,9 +52,9 @@
<HeaderNavLink external href="/insights" svgIconPath={mdiChartBar}>Insights</HeaderNavLink>
</ul>
</nav>
<Tooltip tooltip="Disable SvelteKit (go to React)">
<Tooltip tooltip="Leave experimental web app">
<a href={reactURL} data-sveltekit-reload>
<img src={svelteLogoEnabled} alt="Svelte logo" width="20" height="20" />
<Icon svgPath={mdiFlaskOutline} --color="var(--oc-green-6)" />
</a>
</Tooltip>
<div>

View File

@ -1,17 +1,20 @@
<script lang="ts">
import { page } from '$app/stores'
import Icon from '$lib/Icon.svelte'
import { mdiInformation, mdiReact } from '@mdi/js'
import { mdiFlaskRemoveOutline, mdiInformation } from '@mdi/js'
// A hard referesh will only load the React version if the URL does not explicitly
// include the `feat=enable-sveltekit` query parameter.
$: urlHasFeatureFlag = $page.url.searchParams.getAll('feat').includes('enable-sveltekit')
// include the `feat=web-next` query parameter.
$: urlHasFeatureFlag = $page.url.searchParams.getAll('feat').includes('web-next')
</script>
<div>
<Icon svgPath={mdiInformation} inline />
You are trying out the SvelteKit prototype. Links marked with <Icon svgPath={mdiReact} inline /> will bring you back
to the React version{#if urlHasFeatureFlag}.{:else}, as will a hard refresh.{/if}
You are trying out the experimental web app. Links marked with <Icon
svgPath={mdiFlaskRemoveOutline}
inline
--color="var(--gray-06)"
/> will bring you back to the production version{#if urlHasFeatureFlag}.{:else}, as will a hard refresh.{/if}
</div>
<style lang="scss">

View File

@ -10,10 +10,10 @@ test('has sign in button', async ({ page }) => {
await expect(page).toHaveURL('/sign-in')
})
test('has SvelteKit toggle button', async ({ page }) => {
test('has experimental web app toggle button', async ({ page }) => {
await page.goto('/')
await page.getByLabel('Disable SvelteKit').click()
await expect(page).toHaveURL(/\?feat=-enable-sveltekit/)
await page.getByLabel('Leave experimental web app').click()
await expect(page).toHaveURL(/\?feat=-web-next/)
})
test('has user menu', async ({ sg, page }) => {

View File

@ -15,7 +15,9 @@ a[data-sveltekit-reload='true'] {
height: 1rem;
display: inline-block;
content: '';
background-image: url('/react-logo.svg');
// The fill color value is the value of '--gray-06'
// The '#' needs to be encoded as %23 because it's a special character in URLs
background-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%237a8cb0"><title>flask-remove-outline</title><path d="M15.46 15.88L16.88 14.46L19 16.59L21.12 14.47L22.53 15.88L20.41 18L22.54 20.12L21.12 21.54L19 19.41L16.88 21.53L15.47 20.12L17.59 18L15.46 15.88M5 19C5 19.55 5.45 20 6 20H13.34C13.61 20.75 14 21.42 14.53 22H6C4.34 22 3 20.66 3 19C3 18.4 3.18 17.84 3.5 17.36L9 7.81V6C8.45 6 8 5.55 8 5V4C8 2.9 8.9 2 10 2H14C15.11 2 16 2.9 16 4V5C16 5.55 15.55 6 15 6V7.81L17.5 12.18C16.86 12.35 16.24 12.63 15.69 13L13 8.35V4H11V8.35L5.18 18.43C5.07 18.59 5 18.79 5 19M13 16L13.58 15.42C13.21 16.2 13 17.08 13 18H7.73L10.39 13.39L13 16M12.5 12C12.78 12 13 12.22 13 12.5C13 12.78 12.78 13 12.5 13C12.22 13 12 12.78 12 12.5C12 12.22 12.22 12 12.5 12Z" /></svg>');
background-repeat: no-repeat;
}
}

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 34 32"><path fill="#a7b3cb" d="M19.314 15.987a2.392 2.392 0 11-4.784 0 2.392 2.392 0 014.784 0z" /><path fill="#a7b3cb" d="M16.922 24.783c1.878 1.826 3.729 2.906 5.221 2.906.489 0 .952-.103 1.337-.334 1.337-.772 1.826-2.701 1.363-5.453-.077-.489-.18-.977-.309-1.492.514-.154.977-.309 1.44-.463 2.598-1.003 4.038-2.392 4.038-3.909 0-1.543-1.44-2.932-4.038-3.909-.463-.18-.926-.334-1.44-.463.129-.514.232-1.003.309-1.492.437-2.803-.051-4.758-1.389-5.53-.386-.231-.849-.334-1.337-.334-1.466 0-3.344 1.08-5.221 2.906-1.852-1.826-3.704-2.906-5.195-2.906-.489 0-.952.103-1.337.334-1.337.772-1.826 2.701-1.363 5.453.077.489.18.977.309 1.492-.514.154-.977.309-1.44.463-2.598 1.003-4.038 2.392-4.038 3.909 0 1.543 1.44 2.932 4.038 3.909.463.18.926.334 1.44.463a16.882 16.882 0 00-.309 1.492c-.437 2.752.051 4.707 1.363 5.453.386.232.849.334 1.337.334 1.492.051 3.344-1.029 5.221-2.829zm-1.441-3.472c.463.026.952.026 1.44.026s.977 0 1.44-.026a24.523 24.523 0 01-1.44 1.723 24.252 24.252 0 01-1.44-1.723zm-3.189-2.649c.257.437.489.849.772 1.26a27.786 27.786 0 01-2.263-.386c.232-.694.489-1.415.797-2.135.206.411.437.849.694 1.26zM10.8 12.463c.72-.154 1.466-.283 2.263-.386-.257.412-.514.823-.772 1.26s-.489.849-.694 1.286a17.109 17.109 0 01-.797-2.161zm1.415 3.524c.334-.694.694-1.389 1.106-2.083.386-.669.823-1.337 1.26-2.006a35.293 35.293 0 014.682 0c.463.669.874 1.337 1.26 2.006.412.694.772 1.389 1.106 2.083a26.922 26.922 0 01-1.106 2.083c-.386.669-.823 1.337-1.26 2.006a35.293 35.293 0 01-4.682 0 28.695 28.695 0 01-1.26-2.006 27.106 27.106 0 01-1.106-2.083zm10.057-1.389l-.694-1.286c-.257-.437-.489-.849-.772-1.26.797.103 1.543.232 2.263.386-.231.72-.489 1.44-.797 2.161zm0 2.778c.309.72.566 1.44.797 2.135-.72.154-1.466.283-2.263.386.257-.412.514-.823.772-1.26.232-.386.463-.823.694-1.26zm.591 8.925c-.206.129-.463.18-.746.18-1.26 0-2.829-1.029-4.372-2.572a26.868 26.868 0 002.186-2.701 23.619 23.619 0 003.447-.54c.129.463.206.926.283 1.389.36 2.186.077 3.755-.797 4.244zm1.338-13.555c2.881.823 4.604 2.083 4.604 3.241 0 1.003-1.183 2.006-3.266 2.804-.412.154-.874.309-1.337.437a27.01 27.01 0 00-1.26-3.241c.514-1.106.952-2.186 1.26-3.241zm-2.058-7.253c.283 0 .514.051.746.18.849.489 1.157 2.032.797 4.244-.077.437-.18.9-.283 1.389a33.072 33.072 0 00-3.447-.54 23.774 23.774 0 00-2.186-2.701c1.543-1.518 3.112-2.572 4.372-2.572zm-3.781 5.17c-.463-.026-.952-.026-1.44-.026s-.977 0-1.44.026c.463-.617.952-1.183 1.44-1.723.489.54.977 1.132 1.44 1.723zm-7.382-4.99c.206-.129.463-.18.746-.18 1.26 0 2.829 1.029 4.372 2.572a26.756 26.756 0 00-2.186 2.701 23.619 23.619 0 00-3.447.54c-.129-.463-.206-.926-.283-1.389-.36-2.186-.077-3.729.797-4.244zM9.643 19.228c-2.881-.823-4.604-2.083-4.604-3.241 0-1.003 1.183-2.006 3.266-2.803.412-.154.874-.309 1.337-.437a27.01 27.01 0 001.26 3.241c-.514 1.106-.952 2.212-1.26 3.241zm.54 2.829c.077-.437.18-.9.283-1.389 1.08.232 2.238.412 3.447.54a23.774 23.774 0 002.186 2.701c-1.543 1.517-3.112 2.572-4.372 2.572-.283 0-.514-.051-.746-.18-.875-.489-1.157-2.058-.797-4.244z" /></svg>

Before

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 98.1 118" style="enable-background:new 0 0 98.1 118;" xml:space="preserve">
<style type="text/css">
.st0{fill:#5e6e8c;}
.st1{fill:#FFFFFF;}
</style>
<path class="st0" d="M91.8,15.6C80.9-0.1,59.2-4.7,43.6,5.2L16.1,22.8C8.6,27.5,3.4,35.2,1.9,43.9c-1.3,7.3-0.2,14.8,3.3,21.3
c-2.4,3.6-4,7.6-4.7,11.8c-1.6,8.9,0.5,18.1,5.7,25.4c11,15.7,32.6,20.3,48.2,10.4l27.5-17.5c7.5-4.7,12.7-12.4,14.2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0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 98.1 118" style="enable-background:new 0 0 98.1 118;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FF3E00;}
.st1{fill:#FFFFFF;}
</style>
<path class="st0" d="M91.8,15.6C80.9-0.1,59.2-4.7,43.6,5.2L16.1,22.8C8.6,27.5,3.4,35.2,1.9,43.9c-1.3,7.3-0.2,14.8,3.3,21.3
c-2.4,3.6-4,7.6-4.7,11.8c-1.6,8.9,0.5,18.1,5.7,25.4c11,15.7,32.6,20.3,48.2,10.4l27.5-17.5c7.5-4.7,12.7-12.4,14.2-21.1
c1.3-7.3,0.2-14.8-3.3-21.3c2.4-3.6,4-7.6,4.7-11.8C99.2,32.1,97.1,22.9,91.8,15.6"/>
<path class="st1" d="M40.9,103.9c-8.9,2.3-18.2-1.2-23.4-8.7c-3.2-4.4-4.4-9.9-3.5-15.3c0.2-0.9,0.4-1.7,0.6-2.6l0.5-1.6l1.4,1
c3.3,2.4,6.9,4.2,10.8,5.4l1,0.3l-0.1,1c-0.1,1.4,0.3,2.9,1.1,4.1c1.6,2.3,4.4,3.4,7.1,2.7c0.6-0.2,1.2-0.4,1.7-0.7L65.5,72
c1.4-0.9,2.3-2.2,2.6-3.8c0.3-1.6-0.1-3.3-1-4.6c-1.6-2.3-4.4-3.3-7.1-2.6c-0.6,0.2-1.2,0.4-1.7,0.7l-10.5,6.7
c-1.7,1.1-3.6,1.9-5.6,2.4c-8.9,2.3-18.2-1.2-23.4-8.7c-3.1-4.4-4.4-9.9-3.4-15.3c0.9-5.2,4.1-9.9,8.6-12.7l27.5-17.5
c1.7-1.1,3.6-1.9,5.6-2.5c8.9-2.3,18.2,1.2,23.4,8.7c3.2,4.4,4.4,9.9,3.5,15.3c-0.2,0.9-0.4,1.7-0.7,2.6l-0.5,1.6l-1.4-1
c-3.3-2.4-6.9-4.2-10.8-5.4l-1-0.3l0.1-1c0.1-1.4-0.3-2.9-1.1-4.1c-1.6-2.3-4.4-3.3-7.1-2.6c-0.6,0.2-1.2,0.4-1.7,0.7L32.4,46.1
c-1.4,0.9-2.3,2.2-2.6,3.8s0.1,3.3,1,4.6c1.6,2.3,4.4,3.3,7.1,2.6c0.6-0.2,1.2-0.4,1.7-0.7l10.5-6.7c1.7-1.1,3.6-1.9,5.6-2.5
c8.9-2.3,18.2,1.2,23.4,8.7c3.2,4.4,4.4,9.9,3.5,15.3c-0.9,5.2-4.1,9.9-8.6,12.7l-27.5,17.5C44.8,102.5,42.9,103.3,40.9,103.9"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -19,8 +19,12 @@ export const FEATURE_FLAGS = [
'contrast-compliant-syntax-highlighting',
'enable-ownership-panels',
'enable-simple-search',
// TODO(fkling): Remove this flag
'enable-sveltekit',
// TODO(fkling): Remove this flag
'enable-sveltekit-toggle',
'web-next',
'web-next-toggle',
'end-user-onboarding',
'insight-polling-enabled',
'opencodegraph',

View File

@ -1,25 +1,34 @@
import type { FC } from 'react'
import { mdiFlaskEmptyOutline } from '@mdi/js'
import { useLocation } from 'react-router-dom'
import { Button, Tooltip } from '@sourcegraph/wildcard'
import { Button, Icon, Tooltip } from '@sourcegraph/wildcard'
import { useFeatureFlag } from '../featureFlags/useFeatureFlag'
import { isSvelteKitSupportedURL, reload } from './util'
function useIsSvelteKitToggleEnabled(): boolean {
const [isSvelteKitToggleEnabled] = useFeatureFlag('enable-sveltekit-toggle')
const [isExperimentalWebAppToggleEnabled] = useFeatureFlag('web-next-toggle')
return isSvelteKitToggleEnabled || isExperimentalWebAppToggleEnabled
}
export const SvelteKitNavItem: FC = () => {
const location = useLocation()
const [isSvelteKitToggleEnabled] = useFeatureFlag('enable-sveltekit-toggle')
const isEnabled = useIsSvelteKitToggleEnabled()
if (!isSvelteKitToggleEnabled || !isSvelteKitSupportedURL(location.pathname)) {
if (!isEnabled || !isSvelteKitSupportedURL(location.pathname)) {
return null
}
return (
<Tooltip content="Go to SvelteKit version">
<Tooltip content="Go to experimental web app">
<Button variant="icon" onClick={reload}>
<img src="/.assets/img/svelte-logo-disabled.svg" alt="Svelte Logo" width={20} height={20} />
<span className="text-muted">
<Icon svgPath={mdiFlaskEmptyOutline} aria-hidden={true} inline={false} />
</span>
</Button>
</Tooltip>
)

View File

@ -1,28 +1,30 @@
import isAbsoluteUrl from 'is-absolute-url'
import { matchPath } from 'react-router-dom'
import { routes } from '../routes'
import { PageRoutes } from '../routes.constants'
const SVELTEKIT_SUPPORTED_REPO_PATHS = /^\/.*?\/-\/(blob|tree|branches|commit|commits|stats|tags)\//
const SVELTEKIT_SUPPORTED_REPO_PATHS = /^\/.*?\/-\/(blob\/|tree\/|branches$|commit\/|commits$|stats$|tags$)/
export function isSvelteKitSupportedURL(href: string): boolean {
if (!href || isAbsoluteUrl(href)) {
function isRepoSubPage(href: string): boolean {
return href.includes('/-/')
}
export function isSvelteKitSupportedURL(pathname: string): boolean {
if (!pathname) {
return false
}
const route = routes.find(
route =>
(route.path && matchPath(route.path, href)) ||
(route.path && matchPath(route.path.replace(/\/\*$/, ''), href))
route => route.path && (matchPath(route.path, pathname) || matchPath(route.path.replace(/\/\*$/, ''), pathname))
)
return (
route?.path === PageRoutes.Search ||
(route?.path === PageRoutes.RepoContainer && SVELTEKIT_SUPPORTED_REPO_PATHS.test(href))
(route?.path === PageRoutes.RepoContainer &&
(!isRepoSubPage(pathname) || SVELTEKIT_SUPPORTED_REPO_PATHS.test(pathname)))
)
}
export function reload(): void {
const url = new URL(window.location.href)
url.searchParams.append('feat', 'enable-sveltekit')
url.searchParams.append('feat', 'web-next')
window.location.href = url.toString()
}

View File

@ -27,7 +27,7 @@ var sveltekitEnabledRoutes = map[string]struct{}{
}
// useSvelteKit returns true if the route is configured to be supported by useSvelteKit
// (see svelteKitEnabledRoutes) and the 'enable-sveltekit' feature flag is set
// (see svelteKitEnabledRoutes) and the 'enable-sveltekit' or 'enable-sveltekit' feature flag is set
func useSvelteKit(r *http.Request) bool {
route := mux.CurrentRoute(r)
if route == nil {
@ -38,7 +38,9 @@ func useSvelteKit(r *http.Request) bool {
return false
}
return featureflag.FromContext(r.Context()).GetBoolOr("enable-sveltekit", false)
ff := featureflag.FromContext(r.Context())
return ff.GetBoolOr("enable-sveltekit", false) || ff.GetBoolOr("web-next", false)
}
// renderSvelteKit writes SvelteKit's fallback page to the provided writer