Skip to content

Commit

Permalink
feat(logs): bind escape to close logs (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBonnet committed Nov 29, 2022
1 parent eee4336 commit c073aca
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions libs/shared/ui/src/lib/components/layouts/breadcrumb/breadcrumb.tsx
@@ -1,7 +1,7 @@
import equal from 'fast-deep-equal'
import { Application, Database, Environment, Organization, Project } from 'qovery-typescript-axios'
import React from 'react'
import { useLocation, useParams } from 'react-router-dom'
import React, { useEffect } from 'react'
import { useLocation, useNavigate, useParams } from 'react-router-dom'
import { IconEnum } from '@qovery/shared/enums'
import { ApplicationEntity, ClusterEntity, DatabaseEntity, EnvironmentEntity } from '@qovery/shared/interfaces'
import {
Expand Down Expand Up @@ -41,6 +41,7 @@ export function BreadcrumbMemo(props: BreadcrumbProps) {
const { organizationId, projectId, environmentId, applicationId, databaseId, clusterId } = useParams()

const location = useLocation()
const navigate = useNavigate()
const currentOrganization = organizations?.find((organization) => organizationId === organization.id)

const locationIsApplicationLogs = location.pathname.includes(
Expand Down Expand Up @@ -165,6 +166,21 @@ export function BreadcrumbMemo(props: BreadcrumbProps) {
</div>
)

const linkToCloseLogs = locationIsApplicationLogs
? `${APPLICATION_URL(organizationId, projectId, environmentId, applicationId)}${APPLICATION_GENERAL_URL}`
: SERVICES_URL(organizationId, projectId, environmentId)

useEffect(() => {
const bindTouch = (event: KeyboardEvent) => {
if (event.key === 'Escape') navigate(linkToCloseLogs)
}
document.addEventListener('keydown', bindTouch, false)

return () => {
document.removeEventListener('keydown', bindTouch, false)
}
}, [linkToCloseLogs, navigate])

if (organizations?.length === 0) return <div />

return (
Expand Down Expand Up @@ -272,16 +288,7 @@ export function BreadcrumbMemo(props: BreadcrumbProps) {
icon={IconAwesomeEnum.CROSS}
style={ButtonIconStyle.DARK}
size={ButtonSize.LARGE}
link={
locationIsApplicationLogs
? `${APPLICATION_URL(
organizationId,
projectId,
environmentId,
applicationId
)}${APPLICATION_GENERAL_URL}`
: SERVICES_URL(organizationId, projectId, environmentId)
}
link={linkToCloseLogs}
/>
</div>
)}
Expand Down

0 comments on commit c073aca

Please sign in to comment.