0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 18:07:17 +01:00

refactor(navigation): Remove Ant Layout and clean up .main-app-content (#13657)

* Remove Ant `Layout` completely

* Update `react/forbid-elements` rule

* Always apply base `.main-app-content`
This commit is contained in:
Michael Matloka 2023-01-12 12:37:17 +01:00 committed by GitHub
parent 2ced726754
commit 8290cfd104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 14 deletions

View File

@ -89,11 +89,19 @@ module.exports = {
{ {
element: 'Row', element: 'Row',
message: message:
'use flex utility classes instead e.g. <Row align="middle"> could be <div className="flex items-center">', 'use flex utility classes instead, e.g. <Row align="middle"> could be <div className="flex items-center">',
}, },
{ {
element: 'Col', element: 'Col',
message: 'use flex utility classes instead. Most of the time can simply be a plain <div>', message: 'use flex utility classes instead - most of the time can simply be a plain <div>',
},
{
element: 'Space',
message: 'use flex or space utility classes instead',
},
{
element: 'Card',
message: 'use utility classes instead',
}, },
{ {
element: 'Button', element: 'Button',
@ -118,10 +126,25 @@ module.exports = {
], ],
}, },
], ],
'react/forbid-elements': [
2,
{
forbid: [
{
element: 'Layout',
message: 'use utility classes instead',
},
{
element: 'Spin',
message: 'use Spinner instead',
},
],
},
],
}, },
overrides: [ overrides: [
{ {
// enable the rule specifically for TypeScript files // disable these rules for files generated by kea-typegen
files: ['*Type.ts', '*Type.tsx'], files: ['*Type.ts', '*Type.tsx'],
rules: { rules: {
'@typescript-eslint/no-explicit-any': ['off'], '@typescript-eslint/no-explicit-any': ['off'],

View File

@ -1,5 +1,4 @@
import { Meta } from '@storybook/react' import { Meta } from '@storybook/react'
import { Layout } from 'antd'
import { TopBar } from './TopBar/TopBar' import { TopBar } from './TopBar/TopBar'
import { SideBar } from './SideBar/SideBar' import { SideBar } from './SideBar/SideBar'
import React from 'react' import React from 'react'
@ -11,11 +10,11 @@ export default {
export function Navigation_(): JSX.Element { export function Navigation_(): JSX.Element {
return ( return (
<Layout> <div>
<TopBar /> <TopBar />
<SideBar> <SideBar>
<React.Fragment /> <React.Fragment />
</SideBar> </SideBar>
</Layout> </div>
) )
} }

View File

@ -1,4 +1,4 @@
import { Layout } from 'antd' import clsx from 'clsx'
import { useValues } from 'kea' import { useValues } from 'kea'
import { BillingAlertsV2 } from 'lib/components/BillingAlertsV2' import { BillingAlertsV2 } from 'lib/components/BillingAlertsV2'
import { sceneLogic } from 'scenes/sceneLogic' import { sceneLogic } from 'scenes/sceneLogic'
@ -12,10 +12,10 @@ export function Navigation({ children }: { children: any }): JSX.Element {
const { sceneConfig, activeScene } = useValues(sceneLogic) const { sceneConfig, activeScene } = useValues(sceneLogic)
return ( return (
<Layout> <div>
{activeScene !== Scene.Ingestion && <TopBar />} {activeScene !== Scene.Ingestion && <TopBar />}
<SideBar> <SideBar>
<Layout.Content className={!sceneConfig?.plain ? 'main-app-content' : undefined}> <div className={clsx('main-app-content', sceneConfig?.plain && 'main-app-content--plain')}>
{!sceneConfig?.plain && ( {!sceneConfig?.plain && (
<> <>
<BillingAlertsV2 /> <BillingAlertsV2 />
@ -24,8 +24,8 @@ export function Navigation({ children }: { children: any }): JSX.Element {
</> </>
)} )}
{children} {children}
</Layout.Content> </div>
</SideBar> </SideBar>
</Layout> </div>
) )
} }

View File

@ -1,5 +1,4 @@
import { kea, useMountedLogic, useValues, BindLogic } from 'kea' import { kea, useMountedLogic, useValues, BindLogic } from 'kea'
import { Layout } from 'antd'
import { ToastContainer, Slide } from 'react-toastify' import { ToastContainer, Slide } from 'react-toastify'
import { preflightLogic } from './PreflightCheck/preflightLogic' import { preflightLogic } from './PreflightCheck/preflightLogic'
import { userLogic } from 'scenes/userLogic' import { userLogic } from 'scenes/userLogic'
@ -143,10 +142,10 @@ function AppScene(): JSX.Element | null {
if (!user) { if (!user) {
return sceneConfig?.onlyUnauthenticated || sceneConfig?.allowUnauthenticated ? ( return sceneConfig?.onlyUnauthenticated || sceneConfig?.allowUnauthenticated ? (
<Layout style={{ minHeight: '100vh' }}> <>
{protectedBoundActiveScene} {protectedBoundActiveScene}
{toastContainer} {toastContainer}
</Layout> </>
) : null ) : null
} }

View File

@ -562,6 +562,7 @@ input::-ms-clear {
.main-app-content { .main-app-content {
position: relative; // So that scene-level <Loading/> is positioned correctly. position: relative; // So that scene-level <Loading/> is positioned correctly.
min-width: 0; min-width: 0;
height: 100%;
padding: 0 1rem 1rem; padding: 0 1rem 1rem;
@include screen($sm) { @include screen($sm) {
@ -571,6 +572,10 @@ input::-ms-clear {
@include screen($lg) { @include screen($lg) {
padding: 0 2rem 4rem; padding: 0 2rem 4rem;
} }
&.main-app-content--plain {
padding: 0;
}
} }
// AntD overrrides, placed inside `body` to increase specifity (nicely avoiding the need for !important) // AntD overrrides, placed inside `body` to increase specifity (nicely avoiding the need for !important)