Files
supabase/studio/components/interfaces/Database/Extensions/ExtensionCard.tsx
T
b91532f6c7 Migrate to styling tokens (#18314)
* migrate some www components to tokens

* consolidate InteractiveShimmerCard to Panel component

* update tokens in blog

* update tokens in careers page

* update tokens in customers section

* update tokens in open-source section

* update tokens in Realtime page

* update tokens in Storage and Vector

* update tokens in SplitCodeBlockCarousel

* update tokens in PGCharts

* remove unused css files

* update tokens in Card

* update tokens in Pricing page

* clean up priving page imports

* remove hardcoded theme vars

* migrate first half of defaultTheme.ts to tokens

* migrate second half of defaultTheme.ts to tokens

* improve inputs

* add foreground to text-light and text-lighter

* add foreground to text-light and text-lighter

* migrate docs components with styling tokens

* migrate docs components with styling tokens

* fix broken Repos component

* fix broken classes in blog

* update tokens on Button and other components

* update tokens on IconPanel

* update studio main layout base styling tokens

* update tokens across studio, docs and www

* update tokens across studio, docs and www

* update ui/Panel to styling tokens

* update ExampleProject and TableEditorMenu tokens

* www vector page tokens

* update studio UI tokens

* update other studio UI tokens

* update more studio UI tokens

* change tokens here, change tokens there

* finish updating colors with tokens variables

* add gui sandbox for theme experimentation

* use common package for www, docs and studio and fix Command K tokens

* provide light mode default tokens options

* fix conflict leftover

* update loading line

* fix className typo

* fix prettier

* update themeSandbox preset default values

* fix text-background0

* prettier

* update warningBanner with warning color

* switch all border-border with border-default

* improve border-secondary and foreground-muted in light mode

* force ring color on toggle

* fix button bg color and border-muted light token

* fix input bg color

* fix dark button hover

* fix homepage product card

* fix code-hike table header colors

* button dark border

* remove tabIndex leftover from homepage main ctas

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
2023-11-07 03:40:53 +00:00

170 lines
5.6 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { observer } from 'mobx-react-lite'
import { useState } from 'react'
import ConfirmationModal from 'components/ui/ConfirmationModal'
import { useCheckPermissions, useStore } from 'hooks'
import { isResponseOk } from 'lib/common/fetch'
import Link from 'next/link'
import { extensions } from 'shared-data'
import { Badge, IconExternalLink, IconLoader, Modal, Toggle } from 'ui'
import EnableExtensionModal from './EnableExtensionModal'
interface ExtensionCardProps {
extension: any
}
const ExtensionCard = ({ extension }: ExtensionCardProps) => {
const { ui, meta } = useStore()
const isOn = extension.installed_version !== null
const [loading, setLoading] = useState(false)
const [showConfirmEnableModal, setShowConfirmEnableModal] = useState(false)
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || ''
const canUpdateExtensions = useCheckPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
'extensions'
)
async function enableExtension() {
return setShowConfirmEnableModal(true)
}
const [isDisableModalOpen, setIsDisableModalOpen] = useState(false)
function openDisableModal() {
setIsDisableModalOpen(true)
}
async function disableExtension() {
try {
setLoading(true)
const response = await meta.extensions.del(extension.name)
if (!isResponseOk(response)) {
throw response.error
}
ui.setNotification({
category: 'success',
message: `${extension.name.toUpperCase()} is off.`,
})
setIsDisableModalOpen(false)
} catch (error: any) {
ui.setNotification({
category: 'error',
message: `Toggle ${extension.name.toUpperCase()} failed: ${error.message}`,
})
} finally {
// Need to reload them because the delete function
// removes the extension from the store
meta.extensions.load()
setLoading(false)
}
}
return (
<>
<div
className={[
'flex border-overlay',
'flex-col overflow-hidden rounded border shadow-sm',
].join(' ')}
>
<div
className={[
'border-overlay bg-surface-100',
'flex justify-between w-full border-b py-3 px-4',
].join(' ')}
>
<div className="flex items-center gap-1 max-w-[85%]">
<div className="flex items-center space-x-2 truncate">
<h3
title={extension.name}
className="h-5 m-0 text-sm truncate cursor-pointer text-foreground"
>
{extension.name}
</h3>
<p className="text-sm text-foreground-light">
{extension?.installed_version ?? extension.default_version}
</p>
</div>
{extensions.find((item: any) => item.name === extension.name) ? (
<Link
href={
extensions
.find((item: any) => item.name === extension.name)
?.link.startsWith('/guides')
? siteUrl === 'http://localhost:8082'
? `http://localhost:3001/docs${
extensions.find((item: any) => item.name === extension.name)?.link
}`
: `https://supabase.com/docs${
extensions.find((item: any) => item.name === extension.name)?.link
}`
: extensions.find((item: any) => item.name === extension.name)?.link ?? ''
}
className="max-w-[85%] cursor-default zans"
target="_blank"
rel="noreferrer"
>
<IconExternalLink className="ml-2.5 cursor-pointer" size={14} />
</Link>
) : null}
</div>
{loading ? (
<IconLoader className="animate-spin" size={16} />
) : (
<Toggle
size="tiny"
checked={isOn}
disabled={!canUpdateExtensions}
onChange={() => (isOn ? openDisableModal() : enableExtension())}
/>
)}
</div>
<div
className={[
'bg-panel-header-light dark:bg-panel-header-dark',
'bg-panel-secondary-light dark:bg-panel-secondary-dark flex h-full flex-col justify-between',
].join(' ')}
>
<div className="py-3 px-4">
<p className="text-sm text-foreground-light capitalize-sentence">{extension.comment}</p>
</div>
{isOn && extension.schema && (
<div className="py-3 px-4">
<div className="flex items-center flex-grow space-x-2 text-sm text-foreground-light">
<span>Schema:</span>
<Badge color="scale">{`${extension.schema}`}</Badge>
</div>
</div>
)}
</div>
</div>
<EnableExtensionModal
visible={showConfirmEnableModal}
extension={extension}
onCancel={() => setShowConfirmEnableModal(false)}
/>
<ConfirmationModal
visible={isDisableModalOpen}
header="Confirm to disable extension"
buttonLabel="Disable"
onSelectCancel={() => setIsDisableModalOpen(false)}
onSelectConfirm={() => {
disableExtension()
}}
>
<Modal.Content>
<p className="py-4 text-sm text-foreground-light">
Are you sure you want to turn OFF "{extension.name}" extension?
</p>
</Modal.Content>
</ConfirmationModal>
</>
)
}
export default observer(ExtensionCard)