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

chore(ui): Object viewer expand/collapse button simplification #3308

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const CallDetails: FC<{
sx={{
flex: '0 0 auto',
maxHeight: `calc(100% - ${HEADER_HEIGHT_BUFFER}px)`,
p: 2,
padding: '4px 16px',
}}>
<CustomWeaveTypeProjectContext.Provider
value={{entity: call.entity, project: call.project}}>
Expand All @@ -146,7 +146,7 @@ export const CallDetails: FC<{
maxHeight: `calc(100% - ${
multipleChildCallOpRefs.length > 0 ? HEADER_HEIGHT_BUFFER : 0
}px)`,
p: 2,
padding: '4px 16px',
}}>
{'traceback' in excInfo ? (
<div style={{overflow: 'auto', height: '100%'}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {isWeaveObjectRef, parseRef} from '../../../../../../react';
import {Alert} from '../../../../../Alert';
import {Button} from '../../../../../Button';
import {CodeEditor} from '../../../../../CodeEditor';
import {Icon} from '../../../../../Icon';
import {isWeaveRef} from '../../filters/common';
import {isCustomWeaveTypePayload} from '../../typeViews/customWeaveType.types';
import {CustomWeaveTypeDispatcher} from '../../typeViews/CustomWeaveTypeDispatcher';
Expand Down Expand Up @@ -44,11 +45,18 @@ TitleRow.displayName = 'S.TitleRow';
const Title = styled.div`
flex: 1 1 auto;
font-family: Source Sans Pro;
font-size: 16px;
font-size: 14px;
font-weight: 600;
line-height: 32px;
letter-spacing: 0px;
text-align: left;
display: flex;
align-items: center;
cursor: pointer;

&:hover {
opacity: 0.8;
}
`;
Title.displayName = 'S.Title';

Expand Down Expand Up @@ -172,6 +180,14 @@ const ObjectViewerSectionNonEmpty = ({
}
};

const onToggleExpansion = () => {
if (mode === 'expanded') {
onClickCollapsed();
} else {
onClickExpanded();
}
};

// On first render and when data changes, recompute expansion state
useEffect(() => {
const isSimple = isSimpleData(data);
Expand All @@ -187,21 +203,24 @@ const ObjectViewerSectionNonEmpty = ({
return (
<Box sx={{height: '100%', display: 'flex', flexDirection: 'column'}}>
<TitleRow>
<Title>{title}</Title>
<Button
variant="quiet"
icon="row-height-small"
active={mode === 'collapsed'}
onClick={onClickCollapsed}
tooltip="View collapsed"
/>
<Title
onClick={() => setMode(mode === 'hidden' ? 'collapsed' : 'hidden')}>
Copy link
Member

Choose a reason for hiding this comment

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

total nit but i've been thinking that 1 liner functions are more aesthetic than I previously thought, we might consider adding a local isModeHidden fn like:

function isModeHidden(mode) {
   return mode === 'hidden'
}
function isModeExpanded...

Copy link
Member

Choose a reason for hiding this comment

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

and then obviously use it everywhere we test the mode state

<Icon
name={mode === 'hidden' ? 'chevron-next' : 'chevron-down'}
width={16}
height={16}
style={{marginRight: '8px'}}
/>
{title}
</Title>
<Button
variant="quiet"
icon="expand-uncollapse"
active={mode === 'expanded'}
onClick={onClickExpanded}
icon={mode === 'expanded' ? 'collapse' : 'expand-uncollapse'}
onClick={onToggleExpansion}
tooltip={
isExpandAllSmall
mode === 'expanded'
? 'View collapsed'
: isExpandAllSmall
? 'Expand all'
: `Expand next ${EXPANDED_IDS_LENGTH} rows`
}
Expand All @@ -213,15 +232,6 @@ const ObjectViewerSectionNonEmpty = ({
onClick={() => setMode('json')}
tooltip="View as JSON"
/>
{!noHide && (
<Button
variant="quiet"
icon="hide-hidden"
active={mode === 'hidden'}
onClick={() => setMode('hidden')}
tooltip="Hide"
/>
)}
</TitleRow>
{body}
</Box>
Expand Down
Loading