Skip to content

Commit 2d7ea53

Browse files
fix: asset details filename overflow issue. (webstudio-is#5054)
## Description I didn't find any open issue for this. the asset details card filename was a bit messed up and it was hiding the size detail. ![image](https://github.com/user-attachments/assets/b5a0a550-f959-4feb-b6de-b3523610325e) this PR fix, trims the filename and aligns the size in the next line as follows. ![Screenshot from 2025-03-25 14-37-26](https://github.com/user-attachments/assets/a27155b6-9add-45db-b651-2424bcca5b32) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [x] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [x] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent edceea2 commit 2d7ea53

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

apps/builder/app/builder/shared/image-manager/image-info.tsx

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import { useStore } from "@nanostores/react";
2-
import prettyBytes from "pretty-bytes";
2+
import { getMimeByExtension } from "@webstudio-is/asset-uploader";
33
import {
4-
theme,
54
Box,
5+
Button,
66
Flex,
77
Grid,
88
Text,
9-
Button,
9+
theme,
1010
Tooltip,
1111
} from "@webstudio-is/design-system";
1212
import {
13-
CloudIcon,
1413
AspectRatioIcon,
14+
CloudIcon,
1515
DimensionsIcon,
16+
PageIcon,
1617
TrashIcon,
1718
} from "@webstudio-is/icons";
1819
import type { Asset } from "@webstudio-is/sdk";
19-
import { Filename } from "./filename";
20-
import { getFormattedAspectRatio } from "./utils";
20+
import prettyBytes from "pretty-bytes";
2121
import { $authPermit } from "~/shared/nano-states";
22+
import { getFormattedAspectRatio } from "./utils";
2223

2324
type ImageInfoProps = {
2425
asset: Asset;
@@ -27,6 +28,10 @@ type ImageInfoProps = {
2728

2829
export const ImageInfo = ({ asset, onDelete }: ImageInfoProps) => {
2930
const { size, meta, id, name } = asset;
31+
32+
const parts = name.split(".");
33+
const extension = "." + parts.pop();
34+
3035
const authPermit = useStore($authPermit);
3136

3237
const isDeleteDisabled = authPermit === "view";
@@ -36,35 +41,44 @@ export const ImageInfo = ({ asset, onDelete }: ImageInfoProps) => {
3641

3742
return (
3843
<>
44+
<Box css={{ width: 250, padding: theme.panel.padding }}>
45+
<Text truncate>{name}</Text>
46+
</Box>
3947
<Box css={{ padding: theme.panel.padding }}>
40-
<Grid columns={2} align="center" gap={2}>
41-
<Box css={{ width: 100 }}>
42-
<Filename variant="labelsSentenceCase">{name}</Filename>
43-
</Box>
48+
<Grid
49+
columns={2}
50+
css={{ gridTemplateColumns: "auto auto" }}
51+
align="center"
52+
gap={3}
53+
>
4454
<Flex align="center" css={{ gap: theme.spacing[3] }}>
4555
<CloudIcon />
4656
<Text variant="labelsSentenceCase">{prettyBytes(size)}</Text>
4757
</Flex>
58+
<Flex align="center" css={{ gap: theme.spacing[3] }}>
59+
<PageIcon />
60+
<Text variant="labelsSentenceCase">
61+
{getMimeByExtension(extension)}
62+
</Text>
63+
</Flex>
64+
{"width" in meta && "height" in meta ? (
65+
<>
66+
<Flex align="center" gap={1}>
67+
<DimensionsIcon />
68+
<Text variant="labelsSentenceCase">
69+
{meta.width} x {meta.height}
70+
</Text>
71+
</Flex>
72+
<Flex align="center" gap={1}>
73+
<AspectRatioIcon />
74+
<Text variant="labelsSentenceCase">
75+
{getFormattedAspectRatio(meta)}
76+
</Text>
77+
</Flex>
78+
</>
79+
) : null}
4880
</Grid>
4981
</Box>
50-
{"width" in meta && "height" in meta ? (
51-
<Box css={{ padding: theme.panel.padding }}>
52-
<Grid columns={2} gap={2} align="center">
53-
<Flex align="center" gap={1}>
54-
<DimensionsIcon />
55-
<Text variant="labelsSentenceCase">
56-
{meta.width} x {meta.height}
57-
</Text>
58-
</Flex>{" "}
59-
<Flex align="center" gap={1}>
60-
<AspectRatioIcon />
61-
<Text variant="labelsSentenceCase">
62-
{getFormattedAspectRatio(meta)}
63-
</Text>
64-
</Flex>
65-
</Grid>
66-
</Box>
67-
) : null}
6882
<Box css={{ padding: theme.panel.padding }}>
6983
<Tooltip side="bottom" content={tooltipContent}>
7084
<Button

packages/asset-uploader/src/utils/mime.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ export const doesAssetMatchMimePatterns = (
131131
return patterns.has(mime) || patterns.has(`${getCategory(mime)}/*`);
132132
};
133133

134+
export const getMimeByExtension = (ext: string): string => {
135+
return extensionToMime.get(ext) ?? "unknown";
136+
};
137+
134138
// Didn't delete because we may need this later
135139
// From https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
136140
// const extentionToMime: [

0 commit comments

Comments
 (0)