Skip to content

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

Fix formatFilterUrlParam

Joshen Lime30b0db4adf4
diff --git a/studio/components/grid/SupabaseGrid.utils.ts b/studio/components/grid/SupabaseGrid.utils.ts
index bb2421ec4f1..65160ae3f3b 100644
--- a/studio/components/grid/SupabaseGrid.utils.ts
+++ b/studio/components/grid/SupabaseGrid.utils.ts
@@ -51,13 +51,16 @@ export function formatFilterURLParams(filter?: string[]): Filter[] {
Array.isArray(filter)
? filter
.map((f) => {
- const [column, operatorAbbrev, value] = f.split(':')
+ const [column, operatorAbbrev, ...value] = f.split(':')
+
+ // Allow usage of : in value, so join them back after spliting
+ const formattedValue = value.join(':')
const operator = FilterOperatorOptions.find(
(option) => option.abbrev === operatorAbbrev
)
// Reject any possible malformed filter param
if (!column || !operatorAbbrev || !operator) return undefined
- else return { column, operator: operator.value, value: value || '' }
+ else return { column, operator: operator.value, value: formattedValue || '' }
})
.filter((f) => f !== undefined)
: []
diff --git a/studio/components/grid/components/footer/pagination/Pagination.tsx b/studio/components/grid/components/footer/pagination/Pagination.tsx
index 32bc0117aae..8bc26536eed 100644
--- a/studio/components/grid/components/footer/pagination/Pagination.tsx
+++ b/studio/components/grid/components/footer/pagination/Pagination.tsx
@@ -102,11 +102,6 @@ const Pagination: FC<PaginationProps> = () => {
dispatch({ type: 'SET_ROWS_PER_PAGE', payload: value })
}
- console.log('State', {
- totalRows: state.totalRows,
- isLoading: state.isLoading,
- })
-
return (
<div className="sb-grid-pagination">
{state.totalRows < 0 ? (
diff --git a/studio/components/grid/components/header/filter/FilterRow.tsx b/studio/components/grid/components/header/filter/FilterRow.tsx
index d01d445ad9d..94b8f1ba8e9 100644
--- a/studio/components/grid/components/header/filter/FilterRow.tsx
+++ b/studio/components/grid/components/header/filter/FilterRow.tsx
@@ -8,13 +8,13 @@ import { DropdownControl } from 'components/grid/components/common'
import { useTrackedState } from 'components/grid/store'
import { FilterOperatorOptions } from './Filter.constants'
-type FilterRowProps = {
+interface Props {
filter: Filter
filterIdx: number
}
// [Area of improvement] Input field loses focus after the debounce (because of useUrlState?)
-const FilterRow: FC<FilterRowProps> = ({ filter, filterIdx }) => {
+const FilterRow: FC<Props> = ({ filter, filterIdx }) => {
const state = useTrackedState()
const [_, setParams] = useUrlState({ arrayKeys: ['filter'] })
@@ -107,6 +107,13 @@ const FilterRow: FC<FilterRowProps> = ({ filter, filterIdx }) => {
}
const debounceHandler = useCallback(debounce(updateFilterValue, 600), [])
+ const placeholder =
+ column?.format === 'timestamptz'
+ ? 'yyyy-mm-dd hh:mm:ss+zz'
+ : column?.format === 'timestamp'
+ ? 'yyyy-mm-dd hh:mm:ss'
+ : 'Enter a value'
+
return (
<div className="sb-grid-filter-row px-3">
<DropdownControl align="start" options={columnOptions} onSelect={onColumnChange}>
@@ -139,7 +146,7 @@ const FilterRow: FC<FilterRowProps> = ({ filter, filterIdx }) => {
<Input
size="tiny"
className="w-full"
- placeholder="Enter a value"
+ placeholder={placeholder}
value={filterValue}
onChange={onValueChange}
/>
diff --git a/studio/tests/components/Grid/Grid.utils.test.js b/studio/tests/components/Grid/Grid.utils.test.js
index e367897d2a3..e6dee39ff64 100644
--- a/studio/tests/components/Grid/Grid.utils.test.js
+++ b/studio/tests/components/Grid/Grid.utils.test.js
@@ -1,4 +1,5 @@
import { formatSortURLParams, formatFilterURLParams } from 'components/grid/SupabaseGrid.utils'
+import { format } from 'path'
// Sort URL syntax: `column:order`
describe('SupabaseGrid.utils: formatSortURLParams', () => {
@@ -45,6 +46,15 @@ describe('SupabaseGrid.utils: formatFilterURLParams', () => {
value: '40',
})
})
+ test('should format filters for timestamps correctly', () => {
+ const mockInput = ['created_at:gte:2022-05-30 03:00:00']
+ const output = formatFilterURLParams(mockInput)
+ expect(output[0]).toStrictEqual({
+ column: 'created_at',
+ operator: '>=',
+ value: '2022-05-30 03:00:00',
+ })
+ })
test('should reject any malformed filter options based on URL params', () => {
const mockInput = ['id', ':gte', ':50', 'id:eq:10']
const output = formatFilterURLParams(mockInput)