Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): Introduce slider as an option for navigating paginated tables #3256

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions weave-js/src/components/Panel2/ControlPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Node, opCount} from '@wandb/weave/core';
import React, {useCallback, useEffect, useMemo} from 'react';

import SliderInput from '../../common/components/elements/SliderInput';
import clamp from '../../common/util/clamp';
import * as LLReact from '../../react';
import * as S from './ControlPage.styles';

Expand All @@ -9,7 +11,8 @@ const PageControls: React.FC<{
pageSize: number;
page: number;
setPage: (page: number) => void;
}> = ({rowsNode, pageSize, page, setPage}) => {
shouldUseSlider: boolean;
}> = ({rowsNode, pageSize, page, setPage, shouldUseSlider}) => {
const countNode = useMemo(() => opCount({arr: rowsNode as any}), [rowsNode]);

const countValue = LLReact.useNodeValue(countNode);
Expand Down Expand Up @@ -46,10 +49,29 @@ const PageControls: React.FC<{
setPage(page + 1);
}
}, [page, setPage, onLastPage]);
return countValue.loading || countValue.result < 2 ? (
<></>
const onSliderChange = useCallback(
value => setPage(clamp(value - 1, {min: 0, max: totalItems - 1})),
[setPage, totalItems]
);

const controls = shouldUseSlider ? (
<span
style={{
flex: '1 1 auto',
textAlign: 'center',
}}>
<SliderInput
min={1}
max={totalItems}
onChange={onSliderChange}
step={1}
value={page + 1}
hasInput={true}
debounceTime={100}
/>
</span>
) : (
<S.ControlBar>
<>
<S.ArrowIcon name="previous" onClick={prevPage} />
<span
style={{
Expand All @@ -60,7 +82,13 @@ const PageControls: React.FC<{
{!singleItem && `-${endIndex}`} of {totalItems}{' '}
</span>
<S.ArrowIcon name="next" onClick={nextPage} />
</S.ControlBar>
</>
);

return countValue.loading || countValue.result < 2 ? (
<></>
) : (
<S.ControlBar>{controls}</S.ControlBar>
);
};

Expand Down
22 changes: 19 additions & 3 deletions weave-js/src/components/Panel2/PanelRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface PanelRowConfig {

vertical?: boolean;
filterEmpty?: boolean;
shouldUseSlider?: boolean;
childConfig: any;
}
type PanelRowProps = Panel2.PanelConverterProps;
Expand Down Expand Up @@ -59,7 +60,13 @@ function defaultConfig(
pageSize = 1;
}

return {pageSize, vertical: false, filterEmpty: true, childConfig: undefined};
return {
pageSize,
vertical: false,
filterEmpty: true,
shouldUseSlider: false,
childConfig: undefined,
};
}

const useConfig = (
Expand All @@ -80,7 +87,7 @@ const PanelRowConfigComp: React.FC<PanelRowProps> = props => {
const {updateConfig} = props;
const {dashboardConfigOptions} = usePanelContext();
const config = useConfig(props.input.type, props.child, props.config);
const {pageSize, vertical, filterEmpty} = config;
const {pageSize, vertical, filterEmpty, shouldUseSlider} = config;
const childConfig = useMemo(
() => config.childConfig ?? {},
[config.childConfig]
Expand Down Expand Up @@ -135,6 +142,14 @@ const PanelRowConfigComp: React.FC<PanelRowProps> = props => {
onChange={(e, {checked}) => updateConfig({filterEmpty: !!checked})}
/>
</ConfigPanel.ConfigOption>
<ConfigPanel.ConfigOption label={'Use Slider'}>
<Checkbox
checked={shouldUseSlider ?? false}
onChange={(e, {checked}) =>
updateConfig({shouldUseSlider: !!checked})
}
/>
</ConfigPanel.ConfigOption>
<PanelComp2
input={newInput}
inputType={convertedType}
Expand Down Expand Up @@ -228,12 +243,13 @@ const PanelRow: React.FC<PanelRowProps> = props => {
})}
</div>
{(rowsNode.type.length == null || rowsNode.type.length > pageSize) && (
<div style={{flex: '0 0 auto', maxHeight: '27px'}}>
<div style={{flex: '0 0 auto'}}>
<PageControls
rowsNode={rowsNode}
page={pageNum}
pageSize={pageSize}
setPage={setPageNum}
shouldUseSlider={config.shouldUseSlider ?? false}
/>
</div>
)}
Expand Down
Loading