import { Column } from 'react-data-grid' import z from 'zod' import { PostgresQueue } from 'data/database-queues/database-queues-query' import { cn } from 'ui' import { QueueCreatedAtCell, QueueNameCell, QueueRLSCell, QueueSizeCell, QueueTypeCell, QueueWithMetrics, } from './QueueCells' export const formatQueueColumns = (): Column[] => { return [ { key: 'queue_name', name: 'Name', resizable: true, minWidth: 200, headerCellClass: undefined, renderHeaderCell: () => { return (

Name

) }, renderCell: (props) => { return }, }, { key: 'type', name: 'Type', resizable: true, minWidth: 120, headerCellClass: undefined, renderHeaderCell: () => { return (

Type

) }, renderCell: (props) => { return }, }, { key: 'rls_enabled', name: 'RLS enabled', resizable: true, minWidth: 120, headerCellClass: undefined, renderHeaderCell: () => { return (

RLS enabled

) }, renderCell: (props) => { return }, }, { key: 'created_at', name: 'Created at', resizable: true, minWidth: 180, headerCellClass: undefined, renderHeaderCell: () => { return (

Created at

) }, renderCell: (props) => { return }, }, { key: 'queue_size', name: 'Size', resizable: true, minWidth: 120, headerCellClass: undefined, renderHeaderCell: () => { return (

Size

) }, renderCell: (props) => { return }, }, ] } export const prepareQueuesForDataGrid = (queues: PostgresQueue[]): QueueWithMetrics[] => { return queues.map((queue) => ({ ...queue, id: queue.queue_name, // Use queue_name as unique id })) } export const QueryNameSchema = z .string() .trim() .min(1, 'Please provide a name for your queue') .max(47, "The name can't be longer than 47 characters") .regex( /^[a-zA-Z0-9_-]+$/, 'Name must contain only alphanumeric characters, underscores, and hyphens' ) /** * Checks if the queue name is valid. Returns a boolean. */ export const isQueueNameValid = (queueName: string) => { return QueryNameSchema.safeParse(queueName).success }