Skip to content

Commit

Permalink
🔨 Refactor queue config to env var
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Feb 22, 2024
1 parent d82011d commit 29a8377
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ next-env.d.ts

# cypress
cypress/videos

.env
27 changes: 20 additions & 7 deletions components/reports/QueueSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { Dropdown } from '@/common/Dropdown'
import { ChevronDownIcon } from '@heroicons/react/20/solid'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'

export const QUEUES = {
stratosphere: {
name: 'Stratosphere',
},
troposphere: {
name: 'Troposphere',
},
type QueueConfig = Record<string, { name: string }>

const getQueueConfig = () => {
const config = process.env.NEXT_PUBLIC_QUEUE_CONFIG || '{}'
try {
return JSON.parse(config) as QueueConfig
} catch (err) {
return {}
}
}

export const QUEUES = getQueueConfig()
export const QUEUE_NAMES = Object.keys(QUEUES)

export const QueueSelector = () => {
Expand All @@ -28,6 +32,15 @@ export const QueueSelector = () => {
router.push((pathname ?? '') + '?' + nextParams.toString())
}

// If no queues are configured, just use a static title
if (!QUEUE_NAMES.length) {
return (
<h3 className="flex items-center text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">
Queue
</h3>
)
}

return (
<Dropdown
containerClassName="inline-block"
Expand Down
2 changes: 1 addition & 1 deletion components/repositories/DidHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ArrowTopRightOnSquareIcon } from '@heroicons/react/20/solid'
import { useQuery } from '@tanstack/react-query'

const PLC_DIRECTORY_URL =
process.env.PLC_DIRECTORY_URL || `https://plc.directory`
process.env.NEXT_PUBLIC_PLC_DIRECTORY_URL || `https://plc.directory`

// Not a complete mapping of the DID history event, just the parts we care about in the UI
type DidHistoryEvent = {
Expand Down
10 changes: 10 additions & 0 deletions environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Next from 'next'

declare global {
namespace NodeJS {
interface ProcessEnv {
NEXT_PUBLIC_PLC_DIRECTORY_URL?: string
NEXT_PUBLIC_QUEUE_CONFIG?: string
}
}
}

0 comments on commit 29a8377

Please sign in to comment.