Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

refactor: extend dayjs once on _app

phamhieuf5c3eee5f275
diff --git a/studio/components/interfaces/Organization/BillingSettings/ProjectsSummary.tsx b/studio/components/interfaces/Organization/BillingSettings/ProjectsSummary.tsx
index 193749b8ce7..5aa6038eb03 100644
--- a/studio/components/interfaces/Organization/BillingSettings/ProjectsSummary.tsx
+++ b/studio/components/interfaces/Organization/BillingSettings/ProjectsSummary.tsx
@@ -1,14 +1,11 @@
import Link from 'next/link'
import dayjs from 'dayjs'
-import utc from 'dayjs/plugin/utc'
import { FC, useEffect } from 'react'
import { IconChevronRight, IconLoader } from '@supabase/ui'
import { useProjectSubscription, useStore } from 'hooks'
import Panel from 'components/to-be-cleaned/Panel'
-dayjs.extend(utc)
-
interface ProjectSummaryProps {
project: any
}
@@ -30,12 +27,12 @@ const ProjectSummary: FC<ProjectSummaryProps> = ({ project }) => {
}, [error])
return (
- <div className="w-full px-6 py-3 flex items-center">
+ <div className="flex w-full items-center px-6 py-3">
<div className="w-[25%]">
<p className="text-sm">{project.name}</p>
</div>
{loading ? (
- <div className="w-[75%] flex items-center justify-center">
+ <div className="flex w-[75%] items-center justify-center">
<IconLoader size={14} className="animate-spin" />
</div>
) : (
@@ -43,15 +40,15 @@ const ProjectSummary: FC<ProjectSummaryProps> = ({ project }) => {
<div className="w-[20%]">
<p className="text-sm">{subscription?.tier.name ?? ''}</p>
</div>
- <div className="w-[40%] space-x-2 flex items-center">
+ <div className="flex w-[40%] items-center space-x-2">
<p className="text-sm">{dayjs.unix(currentPeriodStart).utc().format('MMM D, YYYY')}</p>
<p className="text-sm">-</p>
<p className="text-sm">{dayjs.unix(currentPeriodEnd).utc().format('MMM D, YYYY')}</p>
</div>
- <div className="flex items-center justify-end w-[15%]">
+ <div className="flex w-[15%] items-center justify-end">
<Link href={`/project/${project.ref}/settings/billing`}>
- <a className="flex items-center space-x-2 group">
- <p className="transition group-hover:opacity-100 opacity-0 text-sm">View details</p>
+ <a className="group flex items-center space-x-2">
+ <p className="text-sm opacity-0 transition group-hover:opacity-100">View details</p>
<IconChevronRight />
</a>
</Link>
@@ -72,7 +69,7 @@ const ProjectsSummary: FC<ProjectsSummaryProps> = ({ projects }) => {
<h4>Projects at a glance</h4>
<Panel
title={
- <div className="w-full flex items-center">
+ <div className="flex w-full items-center">
<div className="w-[25%]">
<p className="text-sm opacity-50">Name</p>
</div>
@@ -91,7 +88,7 @@ const ProjectsSummary: FC<ProjectsSummaryProps> = ({ projects }) => {
))}
{projects.length === 0 && (
<Panel.Content>
- <p className="text-sm text-scale-1100">No projects created yet</p>
+ <p className="text-scale-1100 text-sm">No projects created yet</p>
</Panel.Content>
)}
</Panel>
diff --git a/studio/components/interfaces/Settings/Logs/LogEventChart.tsx b/studio/components/interfaces/Settings/Logs/LogEventChart.tsx
index d1844b61cd4..d7a39fb4458 100644
--- a/studio/components/interfaces/Settings/Logs/LogEventChart.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogEventChart.tsx
@@ -1,9 +1,8 @@
import { BarChart } from 'components/to-be-cleaned/Charts/ChartRenderer'
import dayjs from 'dayjs'
import { LogData } from '.'
-import utc from 'dayjs/plugin/utc'
import { useMemo } from 'react'
-dayjs.extend(utc)
+
interface Props {
data?: LogData[]
onBarClick: (timestamp: number) => void
diff --git a/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx b/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
index 0c895d06900..68867800ec9 100644
--- a/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
+++ b/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
@@ -10,8 +10,6 @@ import {
IconEyeOff,
} from '@supabase/ui'
import { Filters, LogSearchCallback, LogTemplate, PREVIEWER_DATEPICKER_HELPERS } from '.'
-import dayjs from 'dayjs'
-import utc from 'dayjs/plugin/utc'
import { FILTER_OPTIONS, LogsTableName } from './Logs.constants'
import LogsFilterPopover from './LogsFilterPopover'
import DatePickers from './Logs.DatePickers'
@@ -37,8 +35,6 @@ interface Props {
filters: Filters
}
-dayjs.extend(utc)
-
/**
* Logs control panel header + wrapper
*/
@@ -78,8 +74,8 @@ const PreviewFilterPanel: FC<Props> = ({
{newCount > 0 && (
<div
className={[
- 'absolute flex items-center justify-center -top-3 right-3',
- 'h-4 w-4 z-50',
+ 'absolute -top-3 right-3 flex items-center justify-center',
+ 'z-50 h-4 w-4',
].join(' ')}
>
<div className="absolute z-20">
@@ -87,8 +83,8 @@ const PreviewFilterPanel: FC<Props> = ({
{newCount > 1000 ? `${Math.floor(newCount / 100) / 10}K` : newCount}
</Typography.Text>
</div>
- <div className="bg-green-800 rounded-full w-full h-full animate-ping opacity-60"></div>
- <div className="absolute z-60 top-0 right-0 bg-green-900 opacity-80 rounded-full w-full h-full"></div>
+ <div className="h-full w-full animate-ping rounded-full bg-green-800 opacity-60"></div>
+ <div className="z-60 absolute top-0 right-0 h-full w-full rounded-full bg-green-900 opacity-80"></div>
</div>
)}
<IconRefreshCw size={10} />
@@ -106,9 +102,9 @@ const PreviewFilterPanel: FC<Props> = ({
return (
<div
- className={'flex items-center justify-between w-full' + (condensedLayout ? ' px-5 pt-4' : '')}
+ className={'flex w-full items-center justify-between' + (condensedLayout ? ' px-5 pt-4' : '')}
>
- <div className="flex flex-row gap-4 items-center">
+ <div className="flex flex-row items-center gap-4">
<form
id="log-panel-search"
onSubmit={(e) => {
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.utils.ts
index 53b07120875..419f286079c 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.utils.ts
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/DateTimeInput/DateTimeInput.utils.ts
@@ -1,9 +1,5 @@
-import dayjs from 'dayjs'
-import customParseFormat from 'dayjs/plugin/customParseFormat'
import { TIMESTAMP_TYPES, DATE_TYPES, TIME_TYPES } from '../../SidePanelEditor.constants'
-dayjs.extend(customParseFormat)
-
export function getColumnType(format: string) {
if (isDateColumn(format)) {
return 'date'
diff --git a/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx b/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx
index 0733e94b6f7..6f28cd4eae2 100644
--- a/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx
+++ b/studio/components/to-be-cleaned/Charts/ChartRenderer.tsx
@@ -13,16 +13,9 @@ import {
} from 'recharts'
import dayjs from 'dayjs'
-import customParseFormat from 'dayjs/plugin/customParseFormat'
-import timezone from 'dayjs/plugin/timezone'
-import utc from 'dayjs/plugin/utc'
import { formatBytes } from 'lib/helpers'
import { CHART_COLORS } from 'components/ui/Charts/Charts.constants'
-dayjs.extend(customParseFormat)
-dayjs.extend(timezone)
-dayjs.extend(utc)
-
function dataCheck(data: any, attribute: any) {
const hasData = data && data.find((record: any) => record[attribute])
return hasData ? true : false
@@ -95,7 +88,7 @@ const Header = ({
const highlighted = (
<h5
className={
- 'text-xl text-scale-1200 font-normal ' + (minimalHeader ? 'text-base' : 'text-2xl')
+ 'text-scale-1200 text-xl font-normal ' + (minimalHeader ? 'text-base' : 'text-2xl')
}
>
{title}
@@ -103,7 +96,7 @@ const Header = ({
</h5>
)
const date = (
- <h5 className="text-xs text-scale-900">
+ <h5 className="text-scale-900 text-xs">
{focus ? (
data && data[focus] && day(data[focus].period_start).format(FOCUS_FORMAT)
) : (
@@ -114,9 +107,9 @@ const Header = ({
if (minimalHeader) {
return (
- <div className="flex flex-row gap-x-4 items-center" style={{ minHeight: '1.8rem' }}>
+ <div className="flex flex-row items-center gap-x-4" style={{ minHeight: '1.8rem' }}>
{chartTitle}
- <div className="flex flex-row gap-x-2 items-baseline">
+ <div className="flex flex-row items-baseline gap-x-2">
{highlighted}
{date}
</div>
@@ -136,10 +129,10 @@ const Header = ({
const NoData = ({ title = 'No data to show', message = 'May take 24 hours for data to show' }) => (
<div
className="
- h-full w-full
- border border-dashed border-scale-600
- flex flex-col items-center justify-center
- space-y-2 text-center
+ border-scale-600 flex
+ h-full w-full flex-col
+ items-center justify-center space-y-2 border
+ border-dashed text-center
"
>
<IconBarChart2 className="text-scale-800" />
@@ -235,7 +228,7 @@ export function BarChart({
left: 0,
bottom: 0,
}}
- className="overflow-visible cursor-pointer"
+ className="cursor-pointer overflow-visible"
onMouseMove={onMouseMove}
onMouseLeave={onMouseLeave}
onClick={(tooltipData: any) => {
@@ -282,7 +275,7 @@ export function BarChart({
</RechartBarChart>
</ResponsiveContainer>
{data && (
- <div className="text-xs text-scale-900 flex items-center justify-between -mt-5">
+ <div className="text-scale-900 -mt-5 flex items-center justify-between text-xs">
<span>
{day(data[0].period_start).format(
customDateFormat ? customDateFormat : DATE_FORMAT__WITH_TIME
@@ -404,7 +397,7 @@ export function AreaChart({
</RechartAreaChart>
</ResponsiveContainer>
{data && (
- <div className="text-scale-900 text-xs flex items-center justify-between -mt-5">
+ <div className="text-scale-900 -mt-5 flex items-center justify-between text-xs">
<span>
{dayjs(data[0].period_start).format(
customDateFormat ? customDateFormat : DATE_FORMAT__WITH_TIME
diff --git a/studio/components/ui/DatePicker/DatePicker.tsx b/studio/components/ui/DatePicker/DatePicker.tsx
index ce1d7cf7874..3337a4b7820 100644
--- a/studio/components/ui/DatePicker/DatePicker.tsx
+++ b/studio/components/ui/DatePicker/DatePicker.tsx
@@ -15,11 +15,6 @@ import dayjs from 'dayjs'
import { ButtonProps } from '@supabase/ui/dist/cjs/components/Button/Button'
import { DatePickerToFrom } from 'components/interfaces/Settings/Logs'
-var utc = require('dayjs/plugin/utc')
-var timezone = require('dayjs/plugin/timezone') // dependent on utc plugin
-dayjs.extend(utc)
-dayjs.extend(timezone)
-
export interface DatePickerProps {
onChange?: (args: DatePickerToFrom) => void
to?: string
@@ -118,8 +113,8 @@ function _DatePicker({
side="bottom"
header={
<>
- <div className="flex justify-between items-stretch py-2">
- <div className="grow flex flex-col gap-1">
+ <div className="flex items-stretch justify-between py-2">
+ <div className="flex grow flex-col gap-1">
<TimeSplitInput
type="start"
startTime={startTime}
@@ -134,16 +129,16 @@ function _DatePicker({
</div>
<div
className={`
- w-12
+ text-scale-900
flex
- items-center
+ w-12
+ items-center
justify-center
- text-scale-900
`}
>
<IconArrowRight strokeWidth={1.5} size={14} />
</div>
- <div className="grow flex flex-col gap-1">
+ <div className="flex grow flex-col gap-1">
<TimeSplitInput
type="end"
startTime={startTime}
@@ -181,7 +176,7 @@ function _DatePicker({
nextMonthButtonDisabled,
}) => (
<div className="flex items-center justify-between px-2 py-2">
- <div className="flex items-center justify-between w-full">
+ <div className="flex w-full items-center justify-between">
<button
onClick={decreaseMonth}
disabled={prevMonthButtonDisabled}
@@ -193,7 +188,7 @@ function _DatePicker({
>
<IconChevronLeft size={16} strokeWidth={2} />
</button>
- <span className="text-sm text-scale-1100">{format(date, 'MMMM yyyy')}</span>
+ <span className="text-scale-1100 text-sm">{format(date, 'MMMM yyyy')}</span>
<button
onClick={increaseMonth}
disabled={nextMonthButtonDisabled}
@@ -215,7 +210,7 @@ function _DatePicker({
to: endDate?.toISOString() || null,
})}
<Popover.Seperator />
- <div className="flex items-center justify-end gap-2 py-2 pb-4 px-3">
+ <div className="flex items-center justify-end gap-2 py-2 px-3 pb-4">
<Button type="default" onClick={() => handleClear()}>
Clear
</Button>
diff --git a/studio/hooks/analytics/useLogsPreview.tsx b/studio/hooks/analytics/useLogsPreview.tsx
index efd61bf5221..d22fa934c6c 100644
--- a/studio/hooks/analytics/useLogsPreview.tsx
+++ b/studio/hooks/analytics/useLogsPreview.tsx
@@ -18,8 +18,6 @@ import { API_URL } from 'lib/constants'
import { get } from 'lib/common/fetch'
import dayjs from 'dayjs'
-import utc from 'dayjs/plugin/utc'
-dayjs.extend(utc)
interface Data {
logData: LogData[]
error: string | Object | null
diff --git a/studio/pages/_app.tsx b/studio/pages/_app.tsx
index a58d38901a0..5633656aedb 100644
--- a/studio/pages/_app.tsx
+++ b/studio/pages/_app.tsx
@@ -10,6 +10,11 @@ import 'styles/contextMenu.scss'
import 'styles/react-data-grid-logs.scss'
import 'styles/date-picker.scss'
+import dayjs from 'dayjs'
+import customParseFormat from 'dayjs/plugin/customParseFormat'
+import timezone from 'dayjs/plugin/timezone'
+import utc from 'dayjs/plugin/utc'
+
import Head from 'next/head'
import { AppPropsWithLayout } from 'types'
@@ -24,6 +29,10 @@ import { PortalToast, GoTrueWrapper, RouteValidationWrapper } from 'components/i
import PageTelemetry from 'components/ui/PageTelemetry'
import FlagProvider from 'components/ui/Flag/FlagProvider'
+dayjs.extend(customParseFormat)
+dayjs.extend(timezone)
+dayjs.extend(utc)
+
function MyApp({ Component, pageProps }: AppPropsWithLayout) {
const [rootStore] = useState(() => new RootStore())
const router = useRouter()
diff --git a/studio/pages/project/[ref]/settings/database.tsx b/studio/pages/project/[ref]/settings/database.tsx
index 52e6c064560..27b45c71bd9 100644
--- a/studio/pages/project/[ref]/settings/database.tsx
+++ b/studio/pages/project/[ref]/settings/database.tsx
@@ -1,7 +1,4 @@
import dayjs from 'dayjs'
-import customParseFormat from 'dayjs/plugin/customParseFormat'
-import timezone from 'dayjs/plugin/timezone'
-import utc from 'dayjs/plugin/utc'
import useSWR from 'swr'
import { FC, useState, useRef, useEffect } from 'react'
import { toJS } from 'mobx'
@@ -22,10 +19,6 @@ import { ProjectUsageMinimal } from 'components/to-be-cleaned/Usage'
import DateRangePicker from 'components/to-be-cleaned/DateRangePicker'
import ChartHandler from 'components/to-be-cleaned/Charts/ChartHandler'
-dayjs.extend(customParseFormat)
-dayjs.extend(timezone)
-dayjs.extend(utc)
-
const ProjectSettings = () => {
const router = useRouter()
const { ref } = router.query
@@ -35,8 +28,8 @@ const ProjectSettings = () => {
return (
<SettingsLayout title="Database">
- <div className="content w-full h-full overflow-y-auto">
- <div className="w-full px-4 py-4 max-w-5xl">
+ <div className="content h-full w-full overflow-y-auto">
+ <div className="w-full max-w-5xl px-4 py-4">
<Usage project={project} />
<GeneralSettings projectRef={ref} />
</div>
@@ -64,7 +57,7 @@ const Usage: FC<any> = ({ project }) => {
}
>
<Panel.Content>
- <div className="flex space-x-3 items-center mb-4">
+ <div className="mb-4 flex items-center space-x-3">
<DateRangePicker
loading={false}
value={'3h'}
@@ -73,7 +66,7 @@ const Usage: FC<any> = ({ project }) => {
onChange={setDateRange}
/>
{dateRange && (
- <div className="flex space-x-2 items-center">
+ <div className="flex items-center space-x-2">
<Typography.Text type="secondary">
{dayjs(dateRange.period_start.date).format('MMMM D, hh:mma')}
</Typography.Text>
@@ -207,11 +200,11 @@ const ResetDbPassword: FC<any> = () => {
<>
<Panel>
<Panel.Content>
- <div className="grid grid-cols-1 lg:grid-cols-2 items-center">
+ <div className="grid grid-cols-1 items-center lg:grid-cols-2">
<div>
<Typography.Text className="block">Database password</Typography.Text>
<div style={{ maxWidth: '420px' }}>
- <p className="opacity-50 text-sm">
+ <p className="text-sm opacity-50">
You can use this password to connect directly to your Postgres database.
</p>
</div>
@@ -234,7 +227,7 @@ const ResetDbPassword: FC<any> = () => {
onCancel={() => setShowResetDbPass(false)}
onConfirm={() => confirmResetDbPass()}
>
- <div className="w-full space-y-8 mb-8">
+ <div className="mb-8 w-full space-y-8">
<Input
type="password"
onChange={onDbPassChange}
@@ -261,11 +254,11 @@ const DownloadCertificate: FC<any> = ({ createdAt }) => {
return (
<Panel>
<Panel.Content>
- <div className="grid grid-cols-1 lg:grid-cols-2 items-center">
+ <div className="grid grid-cols-1 items-center lg:grid-cols-2">
<div>
<Typography.Text className="block">SSL Connection</Typography.Text>
<div style={{ maxWidth: '420px' }}>
- <p className="opacity-50 text-sm">
+ <p className="text-sm opacity-50">
Use this cert when connecting to your database to prevent snooping and
man-in-the-middle attacks.
</p>
@@ -291,7 +284,7 @@ const GeneralSettings: FC<any> = ({ projectRef }) => {
if (data?.error || error) {
return (
- <div className="p-6 mx-auto sm:w-full md:w-3/4 text-center">
+ <div className="mx-auto p-6 text-center sm:w-full md:w-3/4">
<Typography.Title level={3}>Error loading database settings</Typography.Title>
</div>
)
@@ -299,7 +292,7 @@ const GeneralSettings: FC<any> = ({ projectRef }) => {
if (!data) {
return (
- <div className="p-6 mx-auto sm:w-full md:w-3/4 text-center">
+ <div className="mx-auto p-6 text-center sm:w-full md:w-3/4">
<Typography.Title level={3}>Loading...</Typography.Title>
</div>
)
@@ -326,7 +319,7 @@ const GeneralSettings: FC<any> = ({ projectRef }) => {
return (
<>
<div className="">
- <section className="space-y-6 mt-6">
+ <section className="mt-6 space-y-6">
<Panel
title={[
<Typography.Title key="panel-title" level={5} className="mb-0">
@@ -368,7 +361,7 @@ const GeneralSettings: FC<any> = ({ projectRef }) => {
<Input
layout="horizontal"
- className="input-mono text-base table-input-cell"
+ className="input-mono table-input-cell text-base"
readOnly
copy
disabled
@@ -391,7 +384,7 @@ const GeneralSettings: FC<any> = ({ projectRef }) => {
<DownloadCertificate createdAt={connectionInfo.inserted_at} />
</div>
<div>
- <section className="space-y-6 mt-6">
+ <section className="mt-6 space-y-6">
<Panel
title={
<Typography.Title key="panel-title" level={5} className="mb-0">