Skip to content

Commit

Permalink
fix: make back button navigate one route up
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Aug 18, 2023
1 parent 51a2812 commit 4d7331e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const ActionHeader: React.FC<ActionHeaderProps> = (props) => {
const cssActionsMB = action.showInDrawer ? 'xl' : 'default'
const CssHComponent = action.showInDrawer ? H3 : H2
const contentTag = getActionElementCss(resourceId, action.name, 'action-header')

return (
<Box className={cssClass('ActionHeader')} data-css={contentTag}>
{action.showInDrawer ? '' : (
Expand Down
21 changes: 3 additions & 18 deletions src/frontend/components/app/action-header/styled-back-button.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React, { useMemo } from 'react'
import React from 'react'
import { Link as RouterLink } from 'react-router-dom'
import {
ButtonCSS,
ButtonProps,
Icon,
} from '@adminjs/design-system'
import { styled } from '@adminjs/design-system/styled-components'
import { useSelector } from 'react-redux'

import allowOverride from '../../../hoc/allow-override.js'
import type { DrawerInState, ReduxState, RouterInState } from '../../../store/index.js'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const StyledLink = styled(({ rounded, to, ...rest }) => <RouterLink to={to} {...rest} />)<ButtonProps>`${ButtonCSS}`
Expand All @@ -20,26 +18,13 @@ export type StyledBackButtonProps = {

const StyledBackButton: React.FC<StyledBackButtonProps> = (props) => {
const { showInDrawer } = props
const { previousRoute } = useSelector<ReduxState, DrawerInState>((state) => state.drawer)
const { from = {} } = useSelector<ReduxState, RouterInState>((state) => state.router)
const cssCloseIcon = showInDrawer ? 'ChevronRight' : 'ChevronLeft'

const backLink = useMemo(() => {
if (!showInDrawer) {
return from?.pathname
}

if (previousRoute?.pathname) {
return `${previousRoute?.pathname}${previousRoute?.search}`
}

return from?.pathname
}, [previousRoute, from])

return (
<StyledLink
size="icon"
to={backLink}
to=".."
relative="path"
rounded
mr="lg"
type="button"
Expand Down

0 comments on commit 4d7331e

Please sign in to comment.