Skip to content

Commit

Permalink
[dagit] Use a virtualized list in <SuggestWIP /> to fix launchpad par…
Browse files Browse the repository at this point in the history
…tition picker perf (#6852)
  • Loading branch information
bengotow committed Mar 7, 2022
1 parent ed210ae commit 3df7e14
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions js_modules/dagit/packages/ui/src/components/Suggest.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {InputGroupProps2, IPopoverProps} from '@blueprintjs/core';
// eslint-disable-next-line no-restricted-imports
import {Suggest as BlueprintSuggest, SuggestProps} from '@blueprintjs/select';
import {isCreateNewItem, Suggest as BlueprintSuggest, SuggestProps} from '@blueprintjs/select';
import deepmerge from 'deepmerge';
import * as React from 'react';
import {List} from 'react-virtualized';
import {createGlobalStyle} from 'styled-components/macro';

import {ColorsWIP} from './Colors';
Expand Down Expand Up @@ -49,6 +50,11 @@ export const GlobalSuggestStyle = createGlobalStyle`
}
`;

export const MENU_ITEM_HEIGHT = 32;

const MENU_WIDTH = 250; // arbitrary, just looks nice
const MENU_HEIGHT_MAX = MENU_ITEM_HEIGHT * 7.5;

export const SuggestWIP = <T,>(props: React.PropsWithChildren<SuggestProps<T>>) => {
const popoverProps: Partial<IPopoverProps> = {
...props.popoverProps,
Expand All @@ -65,5 +71,30 @@ export const SuggestWIP = <T,>(props: React.PropsWithChildren<SuggestProps<T>>)
className: 'dagit-suggest-input',
};

return <BlueprintSuggest {...props} inputProps={inputProps} popoverProps={popoverProps} />;
return (
<BlueprintSuggest<T>
{...props}
inputProps={inputProps}
itemListRenderer={(props) => (
<List
style={{outline: 'none', marginRight: -5, paddingRight: 5}}
rowCount={props.filteredItems.length}
scrollToIndex={
props.activeItem && !isCreateNewItem(props.activeItem)
? props.filteredItems.indexOf(props.activeItem)
: undefined
}
rowHeight={MENU_ITEM_HEIGHT}
rowRenderer={(a) => (
<div key={a.index} style={a.style}>
{props.renderItem(props.filteredItems[a.index] as T, a.index)}
</div>
)}
width={MENU_WIDTH}
height={Math.min(props.filteredItems.length * MENU_ITEM_HEIGHT, MENU_HEIGHT_MAX)}
/>
)}
popoverProps={popoverProps}
/>
);
};

1 comment on commit 3df7e14

@vercel
Copy link

@vercel vercel bot commented on 3df7e14 Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dagit-storybook – ./js_modules/dagit/packages/ui

dagit-storybook-git-master-elementl.vercel.app
dagit-storybook-elementl.vercel.app
dagit-storybook.vercel.app

Please sign in to comment.