Skip to content

Commit

Permalink
[ui] Fix unnecessary middle truncation occurring in dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
bengotow committed Nov 21, 2024
1 parent 6898a4d commit 2bca56d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ const Container = styled.div`
*/
const calculateMiddleTruncatedText = (container: HTMLDivElement, text: string) => {
const font = getComputedStyle(container).font;
const width = container.getBoundingClientRect().width;

// https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements#how_much_room_does_it_use_up
const width = container.offsetWidth;

const body = document.body;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ export const Simple = () => {
);
};

export const TransformedContainerUsage = () => {
return (
<Box>
<em style={{display: 'block', marginBottom: 10}}>
Note: Only the first item should appear truncated. This use case is based on our usage of
MiddleTruncate in modals that animate in.
</em>
{[
'asset_that_supports_partition_ranges',
'asset_downstream',
'asset_weekly_root',
'asset_weekly',
].map((text) => (
<Box
key={text}
style={{maxWidth: 200, transform: 'scale(0.8)'}}
flex={{direction: 'row', gap: 8}}
>
<Box>
<Icon name="asset_non_sda" />
</Box>
<a style={{overflow: 'hidden'}} href="#/">
<MiddleTruncate text={text} />
</a>
</Box>
))}
</Box>
);
};

export const FlexboxContainerUsage = () => {
return (
<Box>
Expand Down Expand Up @@ -85,6 +115,7 @@ export const FlexboxContainerUsage = () => {
</Box>
);
};

export const TagUsage = () => {
return (
<Tag icon="job">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const AssetKeysDialog = (props: Props) => {
<Dialog
isOpen={isOpen}
onClose={() => setIsOpen(false)}
style={{width: '750px', maxWidth: '80vw', minWidth: '500px', transform: 'scale(1)'}}
style={{width: '750px', maxWidth: '80vw', minWidth: '500px'}}
canOutsideClickClose
canEscapeKeyClose
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,12 @@ export const BackfillPreviewModal = ({
);
}, [data]);

// BG Note: The transform: scale(1) below fixes a bug with MiddleTruncate where the text size
// is measured while the dialog is animating open and the scale is < 1, causing it to think
// it needs to truncate. A more general fix for this seems like it'll require a lot of testing.

return (
<Dialog
title="Backfill preview"
isOpen={isOpen}
onClose={() => setOpen(false)}
style={{width: '90vw', maxWidth: 1100, transform: 'scale(1)'}}
style={{width: '90vw', maxWidth: 1100}}
>
<Container
ref={parentRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const TickDetailsDialog = ({
<Dialog
isOpen={isOpen}
onClose={onClose}
style={{width: '80vw', maxWidth: '1200px', minWidth: '600px', transform: 'scale(1)'}}
style={{width: '80vw', maxWidth: '1200px', minWidth: '600px'}}
>
<TickDetailsDialogImpl
tickId={tickId}
Expand Down

0 comments on commit 2bca56d

Please sign in to comment.