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

NU-1999 Restrict description window to not take 100% height #7496

Merged
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ export const StyledContent = styled(Window.Content)(({ theme }) => {
"body :has(>&)": {
scrollPadding: theme.spacing(3.5),
scrollPaddingTop: theme.spacing(6),
"::-webkit-scrollbar-track": {
width: "8px",
height: "8px",
background: blendLighten(theme.palette.background.paper, 0.1),
},
"::-webkit-scrollbar-thumb": {
background: blendLighten(theme.palette.background.paper, 0.5),
backgroundClip: "content-box",
border: "2px solid transparent",
borderRadius: "100px",
height: "15px",
},
"::-webkit-scrollbar-thumb:hover": {
background: blendLighten(theme.palette.background.paper, 0.5),
},
"::-webkit-scrollbar-corner": {
background: theme.palette.background.paper,
},
"::-webkit-scrollbar": {
paddingTop: theme.spacing(2),
width: "8px",
height: "8px",
},
},
};
});
44 changes: 40 additions & 4 deletions designer/client/src/containers/ScenarioDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ import { Scenario } from "../components/Process/types";
import NodeUtils from "../components/graph/NodeUtils";
import { NodeOrPropertiesType } from "../types";

const measureText = (text: string, font: string, elementWidth: number): { width: number; height: number } => {
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
if (!context) return { width: 0, height: 0 };

context.font = font;
const lines = text.split("\n");
let totalHeight = 0;
let maxWidth = 0;

lines.forEach((line) => {
const metrics = context.measureText(line);
const width = metrics.width;
const lineHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;

// Calculate the number of lines based on the element width
const lineCount = Math.ceil(width / elementWidth);
totalHeight += lineHeight * lineCount;
maxWidth = Math.max(maxWidth, width);
});

return { width: Math.min(maxWidth, elementWidth), height: totalHeight };
};

export const DescriptionViewMode = {
descriptionView: "description",
descriptionEdit: "descriptionEdit",
Expand All @@ -25,14 +49,26 @@ export function useOpenDescription() {
scenario: Scenario,
descriptionViewMode?: DescriptionViewMode,
layoutData?: WindowType["layoutData"],
) =>
open({
) => {
const textMetric = measureText(scenario.scenarioGraph.properties.additionalFields.description, "14px monospace", 600);

const descriptionHeightInPercentage = (textMetric.height / window.innerHeight) * 100;
const maxHeightInPercentage = 35;
const maxPercentageHeightAsNumber = window.innerHeight * (maxHeightInPercentage / 100);
const isRestrictedMaxHeight = descriptionHeightInPercentage > maxHeightInPercentage;

return open({
kind: descriptionViewMode === DescriptionViewMode.descriptionEdit ? WindowKind.editDescription : WindowKind.viewDescription,
isResizable: true,
shouldCloseOnEsc: false,
meta: { node, scenario },
layoutData,
}),
height: isRestrictedMaxHeight ? maxPercentageHeightAsNumber : undefined,
layoutData: {
...layoutData,
},
});
},

[open],
);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.