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: highlight links in cards and pqir and tooltips #746

Merged
merged 6 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 7 additions & 4 deletions components/canvas/NodeDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styles from "./Node.module.scss";
import { Typography } from "@equinor/eds-core-react";
import { formatNodeText } from "./utils/formatNodeText";
import { FormatNodeText } from "./utils/FormatNodeText";
import { getNodeTypeName } from "@/utils/getNodeTypeName";
import { NodeTypes } from "@/types/NodeTypes";

Expand All @@ -18,9 +18,12 @@ export const NodeDescription = ({ header, description }: NodeDescription) => {
</Typography>
)}
{description && (
<Typography variant="caption" className={styles["node__description"]}>
{formatNodeText(description)}
</Typography>
<FormatNodeText
variant="caption"
className={styles["node__description"]}
>
{description}
</FormatNodeText>
)}
</div>
);
Expand Down
11 changes: 5 additions & 6 deletions components/canvas/NodeTooltipSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Typography } from "@equinor/eds-core-react";
import styles from "./NodeTooltipSection.module.scss";
import { formatNodeText } from "./utils/formatNodeText";
import { FormatNodeText } from "./utils/FormatNodeText";

type NodeTooltipSection = {
header?: string;
Expand All @@ -9,9 +8,9 @@ type NodeTooltipSection = {

export const NodeTooltipSection = ({ header, text }: NodeTooltipSection) => (
<div className={styles.container}>
<Typography variant="meta" color="Gray">
{formatNodeText(header)}
</Typography>
<Typography variant="body_long">{formatNodeText(text)}</Typography>
<FormatNodeText variant="meta" color="Gray">
{header}
</FormatNodeText>
<FormatNodeText variant="body_long">{text}</FormatNodeText>
</div>
);
15 changes: 8 additions & 7 deletions components/canvas/SubActivityNode.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { Connection, Position, useStore } from "reactflow";
import { formatNodeText } from "./utils/formatNodeText";
import { FormatNodeText } from "./utils/FormatNodeText";
import { formatDuration } from "types/unitDefinitions";
import styles from "./Node.module.scss";
import { SubActivityButton } from "./SubActivityButton";
Expand Down Expand Up @@ -152,9 +152,12 @@ export const SubActivityNode = ({
description={description}
/>
<div className={styles["node__role-container"]}>
<Typography variant="caption" className={styles["node__info-text"]}>
{formatNodeText(role)}
</Typography>
<FormatNodeText
variant="caption"
className={styles["node__info-text"]}
>
{role}
</FormatNodeText>
</div>
<div className={styles["node__time-container"]}>
<Typography variant="caption" className={styles["node__info-text"]}>
Expand All @@ -172,9 +175,7 @@ export const SubActivityNode = ({
{description && (
<NodeTooltipSection header={"Description"} text={description} />
)}
{role && (
<NodeTooltipSection header={"Role(s)"} text={formatNodeText(role)} />
)}
{role && <NodeTooltipSection header={"Role(s)"} text={role} />}
{duration && (
<NodeTooltipSection
header={"Duration"}
Expand Down
34 changes: 34 additions & 0 deletions components/canvas/utils/FormatNodeText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Typography, TypographyProps } from "@equinor/eds-core-react";
import styles from "../Node.module.scss";

export function FormatNodeText({
children,
...typographyProps
}: TypographyProps) {
if (!children) return null;
const text = children.toString();
// Pattern matching for Markdown hyperlink urls
const pattern = /\[([^\]]+)]\(([^)]+)\)/g;
let result = [];
HavardNot marked this conversation as resolved.
Show resolved Hide resolved
let lastIndex = 0;

text.replace(pattern, (match, linkText, _, offset) => {
if (lastIndex <= offset) {
result.push(<>{text.slice(lastIndex, offset)}</>);
}

result.push(
<Typography className={styles[typographyProps.className]} link>
{linkText}
</Typography>
);
lastIndex = offset + match.length;
return linkText;
});

if (lastIndex < text.length) {
result.push(<>{text.slice(lastIndex)}</>);
}

return <Typography {...typographyProps}>{result}</Typography>;
}
8 changes: 0 additions & 8 deletions components/canvas/utils/formatNodeText.ts

This file was deleted.

Loading