From 137fd8fed4e33332ded224f0b2650f040484733f Mon Sep 17 00:00:00 2001 From: Frederic Collonval Date: Wed, 9 Sep 2020 21:05:22 +0200 Subject: [PATCH] Better height strategy but element always rerender --- src/components/FileItem.tsx | 2 ++ src/components/FileList.tsx | 63 +++++++++++++++++++++++++++---------- src/components/GitStage.tsx | 63 ++++++++++++++++++++++--------------- src/style/FileItemStyle.ts | 1 + src/style/FileListStyle.ts | 2 +- 5 files changed, 87 insertions(+), 44 deletions(-) diff --git a/src/components/FileItem.tsx b/src/components/FileItem.tsx index db23a297d..e488515d7 100644 --- a/src/components/FileItem.tsx +++ b/src/components/FileItem.tsx @@ -34,6 +34,7 @@ export interface IFileItemProps { onDoubleClick: () => void; selected?: boolean; selectFile?: (file: Git.IStatusFile | null) => void; + style: React.CSSProperties; } export interface IGitMarkBoxProps { @@ -95,6 +96,7 @@ export class FileItem extends React.Component { }) } onDoubleClick={this.props.onDoubleClick} + style={this.props.style} title={`${this.props.file.to} ● ${status}`} > {this.props.markBox && ( diff --git a/src/components/FileList.tsx b/src/components/FileList.tsx index bc6c4b011..a25c2aa10 100644 --- a/src/components/FileList.tsx +++ b/src/components/FileList.tsx @@ -4,6 +4,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { Menu } from '@lumino/widgets'; import * as React from 'react'; +import AutoSizer from 'react-virtualized-auto-sizer'; import { GitExtension } from '../model'; import { hiddenButtonStyle } from '../style/ActionButtonStyle'; import { fileListWrapperClass } from '../style/FileListStyle'; @@ -392,7 +393,9 @@ export class FileList extends React.Component { if (this.props.settings.composite['simpleStaging']) { return (
- {this._renderSimpleStage(this.props.files)} + + {({ height }) => this._renderSimpleStage(this.props.files, height)} +
); } else { @@ -432,9 +435,15 @@ export class FileList extends React.Component { className={fileListWrapperClass} onContextMenu={event => event.preventDefault()} > - {this._renderStaged(stagedFiles)} - {this._renderChanged(unstagedFiles)} - {this._renderUntracked(untrackedFiles)} + + {({ height }) => ( + <> + {this._renderStaged(stagedFiles, height)} + {this._renderChanged(unstagedFiles, height)} + {this._renderUntracked(untrackedFiles, height)} + + )} + ); } @@ -454,18 +463,21 @@ export class FileList extends React.Component { ); } - private _renderStaged(files: Git.IStatusFile[]) { + private _renderStaged(files: Git.IStatusFile[], height: number) { const doubleClickDiff = this.props.settings.get('doubleClickDiff') .composite as boolean; - const renderStagedRow = (file: Git.IStatusFile) => { + const renderStagedRow = ( + file: Git.IStatusFile, + style: React.CSSProperties + ) => { const openFile = () => { openListedFile(file, this.props.model); }; const diffButton = this._createDiffButton(file, 'INDEX'); return ( { : () => undefined : openFile } + style={style} /> ); }; @@ -513,26 +526,30 @@ export class FileList extends React.Component { /> } collapsible - heading={'Staged'} files={files} + heading={'Staged'} + height={height} rowRenderer={renderStagedRow} /> ); } - private _renderChanged(files: Git.IStatusFile[]) { + private _renderChanged(files: Git.IStatusFile[], height: number) { const doubleClickDiff = this.props.settings.get('doubleClickDiff') .composite as boolean; const disabled = files.length === 0; - const renderChangedRow = (file: Git.IStatusFile) => { + const renderChangedRow = ( + file: Git.IStatusFile, + style: React.CSSProperties + ) => { const openFile = () => { openListedFile(file, this.props.model); }; const diffButton = this._createDiffButton(file, 'WORKING'); return ( { : () => undefined : openFile } + style={style} /> ); }; @@ -597,20 +615,24 @@ export class FileList extends React.Component { } collapsible heading={'Changed'} + height={height} files={files} rowRenderer={renderChangedRow} /> ); } - private _renderUntracked(files: Git.IStatusFile[]) { + private _renderUntracked(files: Git.IStatusFile[], height: number) { const doubleClickDiff = this.props.settings.get('doubleClickDiff') .composite as boolean; - const renderUntrackedRow = (file: Git.IStatusFile) => { + const renderUntrackedRow = ( + file: Git.IStatusFile, + style: React.CSSProperties + ) => { return ( { }} selected={this._isSelectedFile(file)} selectFile={this.updateSelectedFile} + style={style} /> ); }; @@ -658,17 +681,21 @@ export class FileList extends React.Component { } collapsible heading={'Untracked'} + height={height} files={files} rowRenderer={renderUntrackedRow} /> ); } - private _renderSimpleStage(files: Git.IStatusFile[]) { + private _renderSimpleStage(files: Git.IStatusFile[], height: number) { const doubleClickDiff = this.props.settings.get('doubleClickDiff') .composite as boolean; - const renderSimpleStageRow = (file: Git.IStatusFile) => { + const renderSimpleStageRow = ( + file: Git.IStatusFile, + style: React.CSSProperties + ) => { const openFile = () => { openListedFile(file, this.props.model); }; @@ -744,7 +771,7 @@ export class FileList extends React.Component { return ( { onDoubleClick={onDoubleClick} contextMenu={contextMenu} selectFile={this.updateSelectedFile} + style={style} /> ); }; @@ -768,6 +796,7 @@ export class FileList extends React.Component { /> } heading={'Changed'} + height={height} files={files} rowRenderer={renderSimpleStageRow} /> diff --git a/src/components/GitStage.tsx b/src/components/GitStage.tsx index 31d9cde94..67e38a18f 100644 --- a/src/components/GitStage.tsx +++ b/src/components/GitStage.tsx @@ -1,6 +1,5 @@ import { caretDownIcon, caretRightIcon } from '@jupyterlab/ui-components'; import * as React from 'react'; -import AutoSizer from 'react-virtualized-auto-sizer'; import { FixedSizeList } from 'react-window'; import { changeStageButtonStyle, @@ -11,6 +10,9 @@ import { } from '../style/GitStageStyle'; import { Git } from '../tokens'; +const HEADER_HEIGHT = 34; +const ITEM_HEIGHT = 25; + /** * Git stage component properties */ @@ -23,18 +25,22 @@ export interface IGitStageProps { * Is this group collapsible */ collapsible?: boolean; - /** - * Group title - */ - heading: string; /** * Files in the group */ files: Git.IStatusFile[]; + /** + * Group title + */ + heading: string; + height: number; /** * Row renderer */ - rowRenderer: (file: Git.IStatusFile) => JSX.Element; + rowRenderer: ( + file: Git.IStatusFile, + style: React.CSSProperties + ) => JSX.Element; } /** @@ -50,6 +56,17 @@ export const GitStage: React.FunctionComponent = ( const [showFiles, setShowFiles] = React.useState(true); const nFiles = props.files.length; + const _renderList = ({ + index, + style + }: { + index: number; + style: React.CSSProperties; + }) => { + const file = props.files[index]; + return props.rowRenderer(file, style); + }; + return (
@@ -73,27 +90,21 @@ export const GitStage: React.FunctionComponent = ( {props.actions} ({nFiles})
- {showFiles && ( - - {({ height, width }) => ( - - {({ index, style }) => { - const file = props.files[index]; - return ( -
- {props.rowRenderer(file)} -
- ); - }} -
- //
    + {showFiles && nFiles > 0 && ( + + itemCount={nFiles} + itemData={props.files} + itemKey={(index, data) => data[index].to} + itemSize={ITEM_HEIGHT} + width={'100%'} + style={{ overflowX: 'visible' }} + > + {_renderList} + )}
    ); diff --git a/src/style/FileItemStyle.ts b/src/style/FileItemStyle.ts index 38c05f058..ecd697e95 100644 --- a/src/style/FileItemStyle.ts +++ b/src/style/FileItemStyle.ts @@ -6,6 +6,7 @@ export const fileStyle = style( display: 'flex', flexDirection: 'row', alignItems: 'center', + boxSizing: 'border-box', color: 'var(--jp-ui-font-color1)', lineHeight: 'var(--jp-private-running-item-height)', padding: '0px 4px', diff --git a/src/style/FileListStyle.ts b/src/style/FileListStyle.ts index 53c74447b..f6bb38dcd 100644 --- a/src/style/FileListStyle.ts +++ b/src/style/FileListStyle.ts @@ -1,7 +1,7 @@ import { style } from 'typestyle'; export const fileListWrapperClass = style({ - height: 'auto', + height: 'inherit', minHeight: '150px', overflow: 'hidden',