Files
supabase/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
T
143f49414b Feat/tabs (#31071)
* init

* Update inner-side-menu.mdx

* chore: update SQL sidebar to use ui pattern components

* mor

* Update

* Update index.tsx

* init: merge table editor and sql editor and schema visualization together

* more

* move to valtio

* fix issue with Command+B shortcut

* now shows in treeviews if item is opened in tab

* Update ProjectLayout.tsx

* fix sidebar

* fix schema selector for non explorer version

* show schema name in tabs

* added schema names to tabs

* tabs have been updated to support preview tabs

* fix URL issue

* add empty state stuff

* Update SQLEditorNav.tsx

* preview tab works now

* more tabs stuff. 'new' tab also added

* new tab concept

* updates

* fix type errors

* remove unused files

* update test

* move back button, fix width issues on sidebar

* update sidebar logic

* Update ProjectLayout.tsx

* lots of updates. layouts now streamlined. localstorage for tabs in use

* moar

* bunch of new tab logic

* fix empty tab issue

* Update tabs.ts

* layouts switched

* new pages now have fixed layouts

* fix tabs

* fix code bg

* add tabs support for multiple project refs

* intialization issue

* update ID handling

* fixed isOpened state for SQL snippets

* remove old assistant because its bugging up panels

* preview style works in sql editor

* fix border

* removes preview tab if there is one

* fix background of loading skeleton

* lots of issues with types/icons/redirect

* new tab cards

* snippets in empty state now work

* moar stuff

* tabs now in feature flags

* Update tabs.ts

* Update tabs.ts

* moar

* add feature previews

* remove code not needed

* Update next-env.d.ts

* Delete FeaturePreviewModal.tsx

* fix typescript errors. remove more explorer stuff

* remove explorer files

* fixed issues with templates and quickstarts tab

* fixed active state when tabs are not opted in

* logic error

* fix open/highlight issue when opted out of tabs

* templates/quickstarts now displayed with new cards

* Update recent-items.tsx

* Update new-tab.tsx

* add icon back in

* add old empty state back in

* recent items updated to respect project ref

* localstorage cleanup on deletion

* moar

* overflow tabs now working

* correct tab names used for new sql templates/quickstarts

* ongoing queries fix

* cleanup

* update images

* Update RouteValidationWrapper.tsx

* Update AppLayout.tsx

* Update NavigationBar.tsx

* add headers back into side panels

* improve writing

* tabs now drag and drop a billion times better

* Update tabs.tsx

* Update tabs.tsx

* init issues on stores, which caused a race condition.

* fix hydration error

* fix new tab issue in sql

* Update ProjectLayout.tsx

* Update pnpm-lock.yaml

* Update new-tab.tsx

* move EditorMenuListSkeleton

* Fix type issues

* fixes: DESIGN-87

fixes: DESIGN-87

* refactor sort/filter components

* Update rules-set-button-text.tsx

* remove discussions for now

* small styling fixes

* Update FeaturePreviewModal.tsx

* Update FeaturePreviewModal.tsx

* Update RouteValidationWrapper.tsx

* revert

* revert

* revert

* revert

* revert

* more revert

* Update collapse-button.tsx

* Update SQLEditorTreeViewItem.tsx

* revert

* Update SchemaGraph.tsx

* Delete new-upcoming.tsx

* revert

* Update ProjectLayout.tsx

* fix home link

* Update table-editor.spec.ts

* test update

* Update table-editor.spec.ts

* Fix the playwright tests.

* layout fixes

* layout fix

* revert sort/filter

* Update LastSignInWrapper.tsx

* revert

* revert

* remove

* update file names

* revert

* revert

* revert

* Fix TreeView console error props

* Add guards in SQL Editor to ensure that feature preview tabs changes do not affect existing UI when flag is off

* Fix missing DefaultLayout in SQL editor templates + fix New tab

* Remove console log

* Remove DatabaseSelector for SQL editor on local

* Fix SQL editor shared favorites for local

* Fix test

* Ensure NewTab doesn't show up if flag is not toggled for SQL editor

* Decouple UI state changes from content-query and entity-types-infinite-query

* Fix tab closing unnecessary rerouting

* Beef up feature previews

* Fix create new table from table editor new tab

* Fix tabs getting incorrectly reset when going between table and SQL editors

* Fix last visited SQL snippet for both tabs and not tabs

* Fix last visited table for table editor tabs

* Clear dashboard history when closing last tab

* Fix loading dashboard history

* Add comment to refactor stores

* Ensure we only save up to 8 items for recent items for each type

* Remove unneccesary logic in tabs

* Smol style fix for DeleteAccountButton

* Smol fix

* Fix inability to close New tab

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Alaister Young <a@alaisteryoung.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2025-03-27 17:46:57 +08:00

172 lines
6.6 KiB
TypeScript

import { ExternalLink, Eye, EyeOff, FlaskConical } from 'lucide-react'
import Link from 'next/link'
import { useEffect, useState } from 'react'
import { useParams } from 'common'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useFlag } from 'hooks/ui/useFlag'
import { LOCAL_STORAGE_KEYS } from 'lib/constants'
import { useAppStateSnapshot } from 'state/app-state'
import { removeTabsByEditor } from 'state/tabs'
import { Badge, Button, Modal, ScrollArea, cn } from 'ui'
import { FEATURE_PREVIEWS, useFeaturePreviewContext } from './FeaturePreviewContext'
const FeaturePreviewModal = () => {
const { ref } = useParams()
const snap = useAppStateSnapshot()
const org = useSelectedOrganization()
const featurePreviewContext = useFeaturePreviewContext()
const { mutate: sendEvent } = useSendEventMutation()
const isFeaturePreviewTabsTableEditorFlag = useFlag('featurePreviewTabsTableEditor')
const isFeaturePreviewTabsSqlEditorFlag = useFlag('featurePreviewSqlEditorTabs')
const selectedFeaturePreview =
snap.selectedFeaturePreview === '' ? FEATURE_PREVIEWS[0].key : snap.selectedFeaturePreview
const [selectedFeatureKey, setSelectedFeatureKey] = useState<string>(selectedFeaturePreview)
const { flags, onUpdateFlag } = featurePreviewContext
const selectedFeature = FEATURE_PREVIEWS.find((preview) => preview.key === selectedFeatureKey)
const isSelectedFeatureEnabled = flags[selectedFeatureKey]
const toggleFeature = () => {
onUpdateFlag(selectedFeatureKey, !isSelectedFeatureEnabled)
sendEvent({
action: isSelectedFeatureEnabled ? 'feature_preview_disabled' : 'feature_preview_enabled',
properties: { feature: selectedFeatureKey },
groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
})
if (selectedFeatureKey === LOCAL_STORAGE_KEYS.UI_TABLE_EDITOR_TABS) {
removeTabsByEditor(ref as string | undefined, 'table')
}
if (selectedFeatureKey === LOCAL_STORAGE_KEYS.UI_SQL_EDITOR_TABS) {
removeTabsByEditor(ref as string | undefined, 'sql')
}
}
function handleCloseFeaturePreviewModal() {
snap.setShowFeaturePreviewModal(false)
snap.setSelectedFeaturePreview(FEATURE_PREVIEWS[0].key)
}
function isReleasedToPublic(feature: (typeof FEATURE_PREVIEWS)[number]) {
switch (feature.key) {
case LOCAL_STORAGE_KEYS.UI_TABLE_EDITOR_TABS:
return isFeaturePreviewTabsTableEditorFlag
case LOCAL_STORAGE_KEYS.UI_SQL_EDITOR_TABS:
return isFeaturePreviewTabsSqlEditorFlag
default:
return true
}
}
// this modal can be triggered on other pages
// Update local state when valtio state changes
useEffect(() => {
if (snap.selectedFeaturePreview !== '') {
setSelectedFeatureKey(snap.selectedFeaturePreview)
}
}, [snap.selectedFeaturePreview])
useEffect(() => {
if (snap.showFeaturePreviewModal) {
sendEvent({
action: 'feature_previews_clicked',
groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
})
}
}, [snap.showFeaturePreviewModal])
return (
<Modal
hideFooter
showCloseButton
size="xlarge"
className="!max-w-4xl"
header="Dashboard feature previews"
visible={snap.showFeaturePreviewModal}
onCancel={handleCloseFeaturePreviewModal}
>
{FEATURE_PREVIEWS.length > 0 ? (
<div className="flex">
<div>
<ScrollArea className="h-[550px] w-[280px] border-r">
{FEATURE_PREVIEWS.filter((feature) => {
// filter out preview features that are not released to the public
return isReleasedToPublic(feature)
}).map((feature) => {
const isEnabled = flags[feature.key] ?? false
return (
<div
key={feature.key}
onClick={() => setSelectedFeatureKey(feature.key)}
className={cn(
'flex items-center space-x-3 p-4 border-b cursor-pointer bg transition',
selectedFeatureKey === feature.key ? 'bg-surface-300' : 'bg-surface-100'
)}
>
{isEnabled ? (
<Eye size={14} strokeWidth={2} className="text-brand" />
) : (
<EyeOff size={14} strokeWidth={1.5} className="text-foreground-light" />
)}
<p className="text-sm truncate" title={feature.name}>
{feature.name}
</p>
</div>
)
})}
</ScrollArea>
</div>
<div className="flex-grow max-h-[550px] p-4 space-y-3 overflow-y-auto">
<div className="flex items-center justify-between">
<div className="flex items-center gap-x-2">
<p>{selectedFeature?.name}</p>
{selectedFeature?.isNew && <Badge color="green">New</Badge>}
</div>
<div className="flex items-center gap-x-2">
{selectedFeature?.discussionsUrl !== undefined && (
<Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>
<Link href={selectedFeature.discussionsUrl} target="_blank" rel="noreferrer">
Give feedback
</Link>
</Button>
)}
<Button type="default" onClick={() => toggleFeature()}>
{isSelectedFeatureEnabled ? 'Disable' : 'Enable'} feature
</Button>
</div>
</div>
{selectedFeature?.content}
</div>
</div>
) : (
<div className="h-[550px] flex flex-col items-center justify-center">
<FlaskConical size={30} strokeWidth={1.5} className="text-foreground-light" />
<div className="mt-1 mb-3 flex flex-col items-center gap-y-0.5">
<p className="text-sm">No feature previews available</p>
<p className="text-sm text-foreground-light">
Have an idea for the dashboard? Let us know via Github Discussions!
</p>
</div>
<Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>
<Link
href="https://github.com/orgs/supabase/discussions/categories/feature-requests"
target="_blank"
rel="noreferrer"
>
Github Discussions
</Link>
</Button>
</div>
)}
</Modal>
)
}
export default FeaturePreviewModal