Skip to content

Commit

Permalink
Merge pull request #22 from vtex-apps/feature/reduce-rerenders
Browse files Browse the repository at this point in the history
Avoid unnecessary re-renders and remove query logic from SideBar component
  • Loading branch information
victorhmp authored Aug 29, 2019
2 parents 9844589 + 6c524c6 commit fe54be0
Show file tree
Hide file tree
Showing 7 changed files with 755 additions and 724 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
105 changes: 21 additions & 84 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- New `SideBarContext` component.

### Fixed
- `<Link>` component was being used with `href` attribute instead of `to`.

## [0.22.0] - 2019-08-29
### Added
Expand All @@ -21,234 +26,166 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Support for displaying a complete list of available components on `ComponentsGrid`.

## [0.20.1] - 2019-08-29

### Fixed

- Missing messages.

## [0.20.0] - 2019-08-12

### Added

- New `AppDocs` component for `/docs/app/:app(/:file)` and `/docs/components/:category/:app` routes.
- `EnhancedAppVersionProvider` to the `PageLayoutContainer` component.

## [0.19.3] - 2019-08-12

### Fixed

- Some messages that were missing.

## [0.19.2] - 2019-08-06

## [0.19.1] - 2019-08-01

### Fixed

- Missing Footer links.

## [0.19.0] - 2019-08-01

### Added

- Dynamic `Latest Features` section in the homepage.

## [0.18.1] - 2019-07-31

### Fixed

- Minor layout updates

## [0.18.0] - 2019-07-31

### Added

- New navigation bar at the top of all pages.
- `SideBarItem` navigation indicator.

### Fixed

- Text colors for better accessibility.

## [0.17.1] - 2019-07-30

### Fixed

- Inconsistent page layout.

## [0.17.0] - 2019-07-29

### Added

- New `Recipes` section that lives at `/docs/resources` and `/docs/resources/:resource`.

## [0.16.0] - 2019-07-29

### Added

- Full support for mobile navigation.

## [0.15.0] - 2019-07-29

### Added

- New `GettingStartedArticle` component to live at `/docs/getting-started/:track/:article`.

## [0.14.0] - 2019-07-26

### Added

- New `ComponentDocs` page that lives at `/docs/components/:category/:component(/:file)`.

## [0.13.0] - 2019-07-25

### Added

- New `ComponentGrid` to visualize all available components under a certain category.

## [0.12.1] - 2019-07-25

### Fixed

- Links in the SideBar now trim the file extensions to avoid requests with duplicate file extensions, such as `.md.md`.

### Changed

- Update `vtex.docs-graphql` version to `1.x`.

## [0.12.0] - 2019-07-25

### Added

- New `RecipeView` page.

## [0.11.0] - 2019-07-25

### Added

- Dynamic recipes listing page.
- New `RecipeList` GraphQL query.

## [0.10.0] - 2019-07-19

### Added

- Better support for Chapters with multiple sub-levels in the SideBar.

### Changed

- Unify `SideBar` and `HomeSideBar` into a single component.

## [0.9.0] - 2019-07-18

### Added

- Article navigation bar based on the headers present in the page.

## [0.8.0] - 2019-07-18

### Added

- New Docs homepage.

### Changed

- Clean-up unnecessary components.
- Clean-up and update Messages.

## [0.7.0] - 2019-07-17

## Added

### Added
- Support for rendering raw HTMl from Markdown files.
- Support for 3 special CSS classes for highlighting text:
- `alert-info`
- `alert-danger`
- `alert-warning`

## Changed

### Changed
- `react-markdown` is now used by `DocsRenderer` component as `remark-react` was removed.

## [0.6.0] - 2019-07-17

## Added

### Added
- Version selection feature at `vtex.io/docs/:app(:/file)`.

## [0.5.0] - 2019-07-10

## Added

### Added
- Support for relative links from one markdown file to another.

## [0.4.0] - 2019-07-10

## Changed

### Changed
- App documentation url format to `/docs/:appName(/:fileName)`.
- When no `:fileName` param is given, the UI defaults to show the `README.md` file.

## [0.3.0] - 2019-07-09

## Added

### Added
- Tag list taken from the markdown file front-matter in the `DocsRenderer` component.
- Custom `<li>` tag for Remark.
- `Edit this page on GitHub` link at the bottom of the `AppDocs` page, using the `git` property taken from the markdown file front-matter.

## Fix

### Fix
- Links to `ID`s that were not lowercase would not work, now they do.

## Changed

### Changed
- Overall layout updates.

## [0.2.0] - 2019-07-08

## Added

### Added
- New Under Construction page.

## Changed

### Changed
- `Docs` component is now rendered at `/docs/home`.
- `/docs` renders `UnderConstruction` component.

## [0.1.4] - 2019-07-08

## Fix

### Fix
- Inverted colors on `AppDocs` component.
- Broken Navbar links

## [0.1.3] - 2019-07-08

## Changed

### Changed
- Semantic colors defined in `styles/configs/style.json`.

## Added

### Added
- CustomCard component.

## [0.1.2] - 2019-07-08

## Fix
### Fix

- Trigger new build for the Styles builder.

## [0.1.1] - 2019-07-05

## Fix

### Fix
- Navbar links

## Changed

### Changed
- Remove apps that should not be used from `DocsData`.

## [0.1.0] - 2019-07-04

- Initial implementation based on the one taken from `vtex-apps/landing-pages`.
13 changes: 8 additions & 5 deletions react/PageLayoutContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import favicon from './images/favicon.png'
import SideBar from './components/SideBar'
import TopNav from './components/TopNav'
import { EnhancedAppVersionProvider } from './components/AppVersionContext'
import { EnhancedSideBarContentProvider } from './components/SideBarContext'

const PageLayoutContainer: FC = ({ children }) => {
return (
Expand All @@ -19,11 +20,13 @@ const PageLayoutContainer: FC = ({ children }) => {
</Helmet>
<div className="flex flex-row-l flex-column min-vh-100">
<EnhancedAppVersionProvider>
<div
className="w-25-l vh-100-l overflow-y-scroll"
style={{ maxWidth: '256px' }}>
<SideBar />
</div>
<EnhancedSideBarContentProvider>
<div
className="w-25-l vh-100-l overflow-y-scroll"
style={{ maxWidth: '256px' }}>
<SideBar />
</div>
</EnhancedSideBarContentProvider>
<div className="w-100 vh-100 overflow-y-scroll flex flex-column justify-between">
<TopNav />
<main className="flex w-90-l" style={{ maxWidth: '1024px' }}>
Expand Down
70 changes: 25 additions & 45 deletions react/components/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import React, { ReactElement, FC } from 'react'
import { Query } from 'react-apollo'
import { ApolloError } from 'apollo-client'
import { Drawer } from 'vtex.store-drawer'
import { Link } from 'vtex.render-runtime'

import SideBarItem from './SideBarItem'
import Skeleton from './Skeleton'
import EmptySummary from './EmptySummary'
import { formatLink } from '../utils'
import { useSideBarContentState } from './SideBarContext'

import VTEXBlack from './icons/VTEXBlack'
import Summary from '../graphql/appSummary.graphql'

interface Chapter {
title: string
Expand All @@ -20,49 +16,33 @@ interface Chapter {

const SideBar: FC = () => {
const appName = '[email protected]'
const { content } = useSideBarContentState()

return (
<Query query={Summary} variables={{ appName, locale: 'en' }}>
{({
loading,
error,
data,
}: {
loading: boolean
error?: ApolloError
data: { appSummary: { chapterList: Chapter[] } }
}) => {
if (loading) return <Skeleton />
if (error) return <EmptySummary />

return (
<nav className="w-100 fixed static-l bg-base z-2 min-h-100-l br-l b--muted-4">
{/* Mobile navigation */}
<div className="flex items-center dn-l">
<div className="w-50 pl4">
<Drawer>
<div className="flex flex-column w-90 center" role="menu">
{getArticles(data.appSummary.chapterList, 0, appName)}
</div>
</Drawer>
</div>
<div className="w-100 center">
<Link to="/docs/home">
<VTEXBlack />
</Link>
</div>
</div>
{/* Desktop navigation */}
<div className="dn db-l" role="menu">
<Link to="/docs/home" className="flex pt2 mt2 pl5">
<VTEXBlack />
</Link>
{getArticles(data.appSummary.chapterList, 0, appName)}
<nav className="w-100 fixed static-l bg-base z-2 min-h-100-l br-l b--muted-4">
{/* Mobile navigation */}
<div className="flex items-center dn-l">
<div className="w-50 pl4">
<Drawer>
<div className="flex flex-column w-90 center" role="menu">
{getArticles(content, 0, appName)}
</div>
</nav>
)
}}
</Query>
</Drawer>
</div>
<div className="w-100 center">
<Link to="/docs/home">
<VTEXBlack />
</Link>
</div>
</div>
{/* Desktop navigation */}
<div className="dn db-l" role="menu">
<Link to="/docs/home" className="flex pt2 mt2 pl5">
<VTEXBlack />
</Link>
{getArticles(content, 0, appName)}
</div>
</nav>
)
}

Expand Down
Loading

0 comments on commit fe54be0

Please sign in to comment.