Skip to content

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

chore: DatePicker now starting to filter

Jonathan Summers-Muirc15524c83d6d
diff --git a/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx b/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
new file mode 100644
index 00000000000..d4a46de6d55
--- /dev/null
+++ b/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
@@ -0,0 +1,40 @@
+import { Button, Dropdown, IconClock } from '@supabase/ui'
+import { DatePicker } from 'components/ui/DatePicker'
+
+const DatePickers = ({
+ to,
+ from,
+ // defaultValues,
+ onChange,
+}: {
+ to?: number
+ from?: number
+ defaultValues?: any
+ onChange: ({}) => void
+}) => {
+ return (
+ <div className="flex items-center">
+ <Dropdown
+ size="small"
+ side="bottom"
+ align="start"
+ overlay={
+ <>
+ <Dropdown.RadioGroup onChange={(e) => console.log(e)} value={'1_hour'}>
+ <Dropdown.Radio value="1_hour">1 hour</Dropdown.Radio>
+ <Dropdown.Radio value="3_hour">Last 3 hour</Dropdown.Radio>
+ <Dropdown.Radio value="1_day">Last day</Dropdown.Radio>
+ </Dropdown.RadioGroup>
+ </>
+ }
+ >
+ <Button as="span" type="default" icon={<IconClock size={12} />}>
+ Last hour
+ </Button>
+ </Dropdown>
+ <DatePicker onChange={onChange} to={to} from={from} />
+ </div>
+ )
+}
+
+export default DatePickers
diff --git a/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx b/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
index e79a7180d1b..f73996d3a09 100644
--- a/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
+++ b/studio/components/interfaces/Settings/Logs/PreviewFilterPanel.tsx
@@ -24,6 +24,8 @@ import utc from 'dayjs/plugin/utc'
import { FILTER_OPTIONS, LogsTableName } from './Logs.constants'
import { LogsFilter } from './Logs.filter'
import { DatePicker } from 'components/ui/DatePicker'
+import DatePickers from './Logs.DatePickers'
+
interface Props {
defaultSearchValue?: string
defaultToValue?: string
@@ -40,6 +42,10 @@ interface Props {
dispatchWhereFilters: (x: any) => void
whereFilters: any
table: LogsTableName
+ te: { value: string; error: string }
+ ts: { value: string; error: string }
+ setTo: ({}) => void
+ setFrom: ({}) => void
}
dayjs.extend(utc)
@@ -63,6 +69,10 @@ const PreviewFilterPanel: FC<Props> = ({
dispatchWhereFilters,
whereFilters: filters,
table,
+ // te: to,
+ // ts: from,
+ // setTo,
+ // setFrom,
}) => {
const [search, setSearch] = useState('')
@@ -138,6 +148,7 @@ const PreviewFilterPanel: FC<Props> = ({
const handleToChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value
+ console.log('value', value)
if (value !== '' && isNaN(Date.parse(value))) {
setTo({ value, error: 'Invalid ISO 8601 timestamp' })
} else {
@@ -210,39 +221,13 @@ const PreviewFilterPanel: FC<Props> = ({
/>
</form>
- <div className="flex items-center">
- <Dropdown
- size="small"
- side="bottom"
- align="start"
- overlay={
- <>
- <Dropdown.RadioGroup onChange={(e) => console.log(e)} value={'1_hour'}>
- <Dropdown.Radio value="1_hour">1 hour</Dropdown.Radio>
- <Dropdown.Radio value="3_hour">Last 3 hour</Dropdown.Radio>
- <Dropdown.Radio value="1_day">Last day</Dropdown.Radio>
- </Dropdown.RadioGroup>
- </>
- }
- >
- <Button
- as="span"
- type="default"
- icon={<IconClock size={12} />}
- // style={{ borderTopRightRadius: 0, borderBottomRightRadius: 0 }}
- >
- Last hour
- </Button>
- </Dropdown>
- {/* <Button
- type="default"
- style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
- icon={<IconCalendar size={12} />}
- >
- Custom
- </Button> */}
- <DatePicker />
- </div>
+ <DatePickers
+ onChange={(e: any) => {
+ setFrom({ value: e.from, error: '' })
+ setTo({ value: e.to, error: '' })
+ handleSearch()
+ }}
+ />
<div>
<RefreshButton />
diff --git a/studio/components/ui/DatePicker/DatePicker.tsx b/studio/components/ui/DatePicker/DatePicker.tsx
index 3d8f33d0dce..a5c7b20537a 100644
--- a/studio/components/ui/DatePicker/DatePicker.tsx
+++ b/studio/components/ui/DatePicker/DatePicker.tsx
@@ -32,24 +32,26 @@ dayjs.extend(utc)
dayjs.extend(timezone)
interface RootProps {
- handleChange?: ({}) => void
+ onChange?: ({}) => void
initialValues?: {
to: number
from: number
}
+ to?: number
+ from?: number
}
const START_DATE_DEFAULT = new Date()
const END_DATE_DEFAULT = new Date()
-console.log('START_DATE_DEFAULT', START_DATE_DEFAULT)
+// console.log('START_DATE_DEFAULT', START_DATE_DEFAULT)
const TIME_NOW = format(new Date(), 'HH:mm:ss').split(':')
const START_TIME_DEFAULT = { HH: TIME_NOW[0], mm: TIME_NOW[1], ss: TIME_NOW[2] }
const END_TIME_DEFAULT = { HH: TIME_NOW[0], mm: TIME_NOW[1], ss: TIME_NOW[2] }
-function _DatePicker({ handleChange, initialValues }: RootProps) {
+function _DatePicker({ to, from, onChange, initialValues }: RootProps) {
const [open, setOpen] = useState<boolean>(false)
const [showTime, setShowTime] = useState<boolean>(true)
@@ -105,7 +107,7 @@ function _DatePicker({ handleChange, initialValues }: RootProps) {
// console.log('unixPayload', unixPayload())
// console.log('isoPayload', isoPayload())
- if (handleChange) handleChange(unixPayload())
+ if (onChange) onChange(isoPayload())
}
function handleClear() {
diff --git a/studio/pages/project/[ref]/settings/logs/[type].tsx b/studio/pages/project/[ref]/settings/logs/[type].tsx
index f279d8a08fd..b458ce9d805 100644
--- a/studio/pages/project/[ref]/settings/logs/[type].tsx
+++ b/studio/pages/project/[ref]/settings/logs/[type].tsx
@@ -196,6 +196,10 @@ export const LogPage: NextPage = () => {
dispatchWhereFilters={dispatchWhereFilters}
whereFilters={whereFilters}
table={table}
+ te={te}
+ ts={ts}
+ setTo={setTo}
+ setFrom={setFrom}
/>
{/* {showChart && (
<div>