-
-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serverInfo: show server info at MenuFooter #694
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { AppQueue } from '@bull-board/api/typings/app'; | ||
import cn from 'clsx'; | ||
import React, { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { NavLink } from 'react-router-dom'; | ||
import { useSelectedStatuses } from '../../hooks/useSelectedStatuses'; | ||
import { useQueues } from './../../hooks/useQueues'; | ||
import { links } from '../../utils/links'; | ||
import { SearchIcon } from '../Icons/Search'; | ||
import { MenuFooter } from './MenuFooter'; | ||
import s from './Menu.module.css'; | ||
|
||
export const Menu = ({ queues }: { queues: AppQueue[] | null }) => { | ||
export const Menu = () => { | ||
const { t } = useTranslation(); | ||
const { queues } = useQueues(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also this way typescript infers the types and we dont need to import anything else |
||
const selectedStatuses = useSelectedStatuses(); | ||
const [searchTerm, setSearchTerm] = useState(''); | ||
|
||
|
@@ -52,7 +54,8 @@ export const Menu = ({ queues }: { queues: AppQueue[] | null }) => { | |
</ul> | ||
)} | ||
</nav> | ||
<div className={cn(s.appVersion, s.secondary)}>{process.env.APP_VERSION}</div> | ||
|
||
<MenuFooter /> | ||
</aside> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import cn from 'clsx'; | ||
import React from 'react'; | ||
import { useRedisOptions } from '../../hooks/useRedisOptions'; | ||
import s from './Menu.module.css'; | ||
|
||
export const MenuFooter = () => { | ||
const options = useRedisOptions(); | ||
|
||
return ( | ||
<div> | ||
{options && ( | ||
<p className={s.redisOpts}> | ||
{`${options.host}:${options.port}:${options.db}`} | ||
</p> | ||
)} | ||
<div className={cn(s.appVersion, s.secondary)}> | ||
{process.env.APP_VERSION} | ||
</div> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import React from 'react'; | ||
import s from './Title.module.css'; | ||
import { useActiveQueue } from '../../hooks/useActiveQueue'; | ||
|
||
interface TitleProps { | ||
name?: string; | ||
description?: string; | ||
} | ||
export const Title = () => { | ||
const queue = useActiveQueue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as hooks can be composed from other hooks, this hook doesnt need to have any arguments, it will resolve automatically which is the active queue |
||
|
||
export const Title = ({ name, description }: TitleProps) => ( | ||
<div className={s.queueTitle}> | ||
{!!name && ( | ||
<> | ||
<h1 className={s.name}>{name}</h1> | ||
{!!description && <p className={s.description}>{description}</p>} | ||
</> | ||
)} | ||
</div> | ||
); | ||
if (!queue) | ||
return <div/> | ||
|
||
return ( | ||
<div className={s.queueTitle}> | ||
{queue.name && ( | ||
<> | ||
<h1 className={s.name}>{queue.name}</h1> | ||
{queue.description && <p className={s.description}>{queue.description}</p>} | ||
</> | ||
)} | ||
</div> | ||
) | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { AppQueue } from '@bull-board/api/typings/app'; | ||
import { useActiveQueueName } from './useActiveQueueName'; | ||
import { QueuesState } from './useQueues'; | ||
import { useQueues } from './useQueues'; | ||
|
||
export function useActiveQueue(data: Pick<QueuesState, 'queues'>): AppQueue | null { | ||
const activeQueueName = useActiveQueueName(); | ||
|
||
if (!data.queues) { | ||
export function useActiveQueue(): AppQueue | null { | ||
const { queues } = useQueues(); | ||
|
||
if (!queues) { | ||
return null; | ||
} | ||
|
||
const activeQueue = data.queues.find((q) => q.name === activeQueueName); | ||
const activeQueueName = useActiveQueueName(); | ||
const activeQueue = queues.find((q) => q.name === activeQueueName); | ||
|
||
return activeQueue || null; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { RedisOptions } from '@bull-board/api/typings/app'; | ||
import { useApi } from './useApi'; | ||
|
||
export function useRedisOptions(): RedisOptions | undefined { | ||
const [options, setOptions] = React.useState<RedisOptions>(); | ||
const api = useApi(); | ||
|
||
React.useEffect(() => { | ||
api.getStats().then(({ options }) => { | ||
setOptions(options) | ||
}) | ||
}, []); | ||
|
||
return options; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont really need this here, each component that needs can fetch with its own hook