Skip to content

Commit

Permalink
feat: another option for deployment name colors
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Oct 10, 2023
1 parent 9731534 commit 7ec7b5c
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 110 deletions.
13 changes: 13 additions & 0 deletions console/client/src/features/deployments/DeploymentCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useNavigate } from 'react-router-dom'
import { Card } from '../../components/Card'
import { deploymentTextColor } from './deployment.utils'

export const DeploymentCard = ({ name, className }: { name: string; className?: string }) => {
const navigate = useNavigate()
return (
<Card key={name} topBarColor='bg-green-500' className={className} onClick={() => navigate(`/deployments/${name}`)}>
{name}
<p className={`text-xs ${deploymentTextColor(name)}`}>{name}</p>
</Card>
)
}
15 changes: 3 additions & 12 deletions console/client/src/features/deployments/DeploymentsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import { RocketLaunchIcon } from '@heroicons/react/24/outline'
import React from 'react'
import { useNavigate } from 'react-router-dom'
import { Card } from '../../components/Card'
import { modulesContext } from '../../providers/modules-provider'
import { Page } from '../../layout'
import { modulesContext } from '../../providers/modules-provider'
import { DeploymentCard } from './DeploymentCard'

export const DeploymentsPage = () => {
const modules = React.useContext(modulesContext)
const navigate = useNavigate()

return (
<Page>
<Page.Header icon={<RocketLaunchIcon />} title='Deployments' />
<Page.Body className='p-4'>
<div className='grid grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4'>
{modules.modules.map((module) => (
<Card
key={module.deploymentName}
topBarColor='bg-green-500'
onClick={() => navigate(`/deployments/${module.deploymentName}`)}
>
{module.name}
<p className='text-xs text-gray-400'>{module.deploymentName}</p>
</Card>
<DeploymentCard key={module.deploymentName} name={module.deploymentName} />
))}
</div>
</Page.Body>
Expand Down
22 changes: 22 additions & 0 deletions console/client/src/features/deployments/deployment.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import hash from 'fnv1a'

const colorNames = [
'text-amber-500 dark:text-amber-400',
'text-blue-500 dark:text-blue-400',
'text-cyan-500 dark:text-cyan-400',
'text-emerald-500 dark:text-emerald-400',
'text-fuchsia-500 dark:text-fuchsia-400',
'text-green-500 dark:text-green-400',
'text-indigo-500 dark:text-indigo-400',
'text-lime-500 dark:text-lime-400',
'text-orange-500 dark:text-orange-400',
'text-pink-500 dark:text-pink-400',
'text-purple-500 dark:text-purple-400',
'text-sky-500 dark:text-sky-400',
'text-slate-500 dark:text-slate-400',
'text-teal-500 dark:text-teal-400',
'text-violet-500 dark:text-violet-400',
'text-yellow-500 dark:text-yellow-400',
]

export const deploymentTextColor = (name: string) => colorNames[hash(name) % colorNames.length]
47 changes: 0 additions & 47 deletions console/client/src/features/timeline/DeploymentLabel.tsx

This file was deleted.

8 changes: 5 additions & 3 deletions console/client/src/features/timeline/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SidePanelContext } from '../../providers/side-panel-provider.tsx'
import { eventIdFilter, getEvents, streamEvents, timeFilter } from '../../services/console.service.ts'
import { formatTimestampShort } from '../../utils/date.utils.ts'
import { panelColor } from '../../utils/style.utils.ts'
import { deploymentTextColor } from '../deployments/deployment.utils.ts'
import { TimelineCall } from './TimelineCall.tsx'
import { TimelineDeploymentCreated } from './TimelineDeploymentCreated.tsx'
import { TimelineDeploymentUpdated } from './TimelineDeploymentUpdated.tsx'
Expand All @@ -16,7 +17,6 @@ import { TimelineDeploymentCreatedDetails } from './details/TimelineDeploymentCr
import { TimelineDeploymentUpdatedDetails } from './details/TimelineDeploymentUpdatedDetails.tsx'
import { TimelineLogDetails } from './details/TimelineLogDetails.tsx'
import { TimeSettings } from './filters/TimelineTimeControls.tsx'
import { DeploymentLabel } from './DeploymentLabel.tsx'

interface Props {
timeSettings: TimeSettings
Expand Down Expand Up @@ -165,9 +165,11 @@ export const Timeline = ({ timeSettings, filters }: Props) => {
</td>
<td
title={deploymentName(entry)}
className='p-1 pr-2 w-40 items-center flex-none truncate text-indigo-500 dark:text-indigo-300'
className={`p-1 pr-2 w-40 items-center flex-none truncate ${deploymentTextColor(
deploymentName(entry),
)}`}
>
<DeploymentLabel name={deploymentName(entry)} />
{deploymentName(entry)}
</td>
<td className='p-1 flex-grow truncate'>
{(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Timestamp } from '@bufbuild/protobuf'
import React, { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { Card } from '../../../components'
import { AttributeBadge } from '../../../components/AttributeBadge'
import { CloseButton } from '../../../components/CloseButton'
import { CodeBlock } from '../../../components/CodeBlock'
Expand All @@ -11,6 +9,7 @@ import { CallEvent } from '../../../protos/xyz/block/ftl/v1/console/console_pb'
import { SidePanelContext } from '../../../providers/side-panel-provider'
import { getRequestCalls } from '../../../services/console.service'
import { formatDuration } from '../../../utils/date.utils'
import { DeploymentCard } from '../../deployments/DeploymentCard'
import { RequestGraph } from '../../requests/RequestGraph'
import { verbRefString } from '../../verbs/verb.utils'
import { TimelineTimestamp } from './TimelineTimestamp'
Expand All @@ -22,7 +21,6 @@ interface Props {

export const TimelineCallDetails = ({ timestamp, call }: Props) => {
const client = useClient(ConsoleService)
const navigate = useNavigate()
const { closePanel } = React.useContext(SidePanelContext)
const [requestCalls, setRequestCalls] = useState<CallEvent[]>([])
const [selectedCall, setSelectedCall] = useState(call)
Expand Down Expand Up @@ -86,15 +84,7 @@ export const TimelineCallDetails = ({ timestamp, call }: Props) => {
</>
)}

<Card
key={call.deploymentName}
topBarColor='bg-green-500'
className='mt-4'
onClick={() => navigate(`/deployments/${call.deploymentName}`)}
>
{call.deploymentName}
<p className='text-xs text-gray-400'>{call.deploymentName}</p>
</Card>
<DeploymentCard name={call.deploymentName} />

<ul className='pt-4 space-y-2'>
{selectedCall.requestName && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Timestamp } from '@bufbuild/protobuf'
import React from 'react'
import { useNavigate } from 'react-router-dom'
import { AttributeBadge } from '../../../components/AttributeBadge'
import { Card } from '../../../components/Card'
import { CloseButton } from '../../../components/CloseButton'
import { DeploymentCreatedEvent, Event } from '../../../protos/xyz/block/ftl/v1/console/console_pb'
import { SidePanelContext } from '../../../providers/side-panel-provider'
import { DeploymentCard } from '../../deployments/DeploymentCard'
import { TimelineTimestamp } from './TimelineTimestamp'

interface Props {
Expand All @@ -15,7 +14,6 @@ interface Props {

export const TimelineDeploymentCreatedDetails = ({ event, deployment }: Props) => {
const { closePanel } = React.useContext(SidePanelContext)
const navigate = useNavigate()

return (
<>
Expand All @@ -35,15 +33,7 @@ export const TimelineDeploymentCreatedDetails = ({ event, deployment }: Props) =
<CloseButton onClick={closePanel} />
</div>

<Card
key={deployment.name}
topBarColor='bg-green-500'
className='mt-4'
onClick={() => navigate(`/deployments/${deployment.name}`)}
>
{deployment.name}
<p className='text-xs text-gray-400'>{deployment.name}</p>
</Card>
<DeploymentCard name={deployment.name} />

<ul className='pt-4 space-y-2'>
<li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Timestamp } from '@bufbuild/protobuf'
import React from 'react'
import { useNavigate } from 'react-router-dom'
import { AttributeBadge } from '../../../components/AttributeBadge'
import { Card } from '../../../components/Card'
import { CloseButton } from '../../../components/CloseButton'
import { DeploymentUpdatedEvent, Event } from '../../../protos/xyz/block/ftl/v1/console/console_pb'
import { SidePanelContext } from '../../../providers/side-panel-provider'
import { DeploymentCard } from '../../deployments/DeploymentCard'
import { TimelineTimestamp } from './TimelineTimestamp'

interface Props {
Expand All @@ -15,7 +14,6 @@ interface Props {

export const TimelineDeploymentUpdatedDetails = ({ event, deployment }: Props) => {
const { closePanel } = React.useContext(SidePanelContext)
const navigate = useNavigate()

return (
<>
Expand All @@ -35,15 +33,7 @@ export const TimelineDeploymentUpdatedDetails = ({ event, deployment }: Props) =
<CloseButton onClick={closePanel} />
</div>

<Card
key={deployment.name}
topBarColor='bg-green-500'
className='mt-4'
onClick={() => navigate(`/deployments/${deployment.name}`)}
>
{deployment.name}
<p className='text-xs text-gray-400'>{deployment.name}</p>
</Card>
<DeploymentCard name={deployment.name} />

<ul className='pt-4 space-y-2'>
<li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Timestamp } from '@bufbuild/protobuf'
import React from 'react'
import { useNavigate } from 'react-router-dom'
import { AttributeBadge } from '../../../components/AttributeBadge'
import { Card } from '../../../components/Card'
import { CloseButton } from '../../../components/CloseButton'
import { CodeBlock } from '../../../components/CodeBlock'
import { Event, LogEvent } from '../../../protos/xyz/block/ftl/v1/console/console_pb'
import { SidePanelContext } from '../../../providers/side-panel-provider'
import { textColor } from '../../../utils/style.utils'
import { DeploymentCard } from '../../deployments/DeploymentCard'
import { LogLevelBadge } from '../../logs/LogLevelBadge'
import { logLevelBgColor } from '../../logs/log.utils'
import { TimelineTimestamp } from './TimelineTimestamp'
Expand All @@ -19,7 +18,6 @@ interface Props {

export const TimelineLogDetails = ({ event, log }: Props) => {
const { closePanel } = React.useContext(SidePanelContext)
const navigate = useNavigate()

return (
<>
Expand All @@ -39,15 +37,8 @@ export const TimelineLogDetails = ({ event, log }: Props) => {
<h2 className='pt-4 text-sm'>Attributes</h2>
<CodeBlock code={JSON.stringify(log.attributes, null, 2)} language='json' />

<Card
key={log.deploymentName}
topBarColor='bg-green-500'
className='mt-4'
onClick={() => navigate(`/deployments/${log.deploymentName}`)}
>
{log.deploymentName}
<p className='text-xs text-gray-400'>{log.deploymentName}</p>
</Card>
<DeploymentCard name={log.deploymentName} />

<ul className='pt-4 space-y-2'>
{log.requestName && (
<li>
Expand Down

0 comments on commit 7ec7b5c

Please sign in to comment.