Skip to content

Commit

Permalink
add descriptions SH-216
Browse files Browse the repository at this point in the history
  • Loading branch information
v.trushin authored and vauweb committed Nov 7, 2024
1 parent 0e46371 commit 16917cf
Show file tree
Hide file tree
Showing 10 changed files with 643 additions and 48 deletions.
497 changes: 497 additions & 0 deletions statshouse-ui/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions statshouse-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"react-router-dom": "^6.17.0",
"react-scripts": "^5.0.1",
"react-window": "^1.8.10",
"remark-gfm": "^4.0.0",
"sass": "^1.69.5",
"typescript": "^4.9.5",
"uplot": "^1.6.27",
Expand Down
17 changes: 14 additions & 3 deletions statshouse-ui/src/components2/Dashboard/DashboardName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import cn from 'classnames';
import { Tooltip } from 'components/UI';
import { DashboardNameTitle } from './DashboardNameTitle';
import { useStatsHouseShallow } from 'store2';
import css from '../style.module.css';
import { MarkdownRender } from 'components2/Plot/PlotView/MarkdownRender';

export function _DashboardName() {
const { dashboardName, dashboardDescription } = useStatsHouseShallow(
Expand All @@ -28,13 +30,22 @@ export function _DashboardName() {
hover
horizontal="left"
>
<div>
<div className="overflow-hidden text-truncate">
{dashboardName}
{!!dashboardDescription && ':'}
</div>
{!!dashboardDescription && (
<div className="text-secondary flex-grow-1 w-0 overflow-hidden text-truncate">
<>{dashboardDescription}</>
<div className="text-secondary flex-grow-1 w-0 overflow-hidden">
<MarkdownRender
className={css.markdown}
allowedElements={['p', 'a']}
components={{
p: ({ node, ...props }) => <span {...props} />,
}}
unwrapDisallowed
>
{dashboardDescription}
</MarkdownRender>
</div>
)}
</Tooltip>
Expand Down
12 changes: 2 additions & 10 deletions statshouse-ui/src/components2/Dashboard/DashboardNameTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import React from 'react';
import { TooltipMarkdown } from 'components2/Plot/PlotView/TooltipMarkdown';

export type DashboardNameTitleProps = {
name: string;
Expand All @@ -18,16 +19,7 @@ export function DashboardNameTitle({ name, description }: DashboardNameTitleProp
{name}
{!!description && ':'}
</div>
{!!description && (
<>
<div style={{ maxWidth: '80vw', whiteSpace: 'pre-wrap' }}>
<>{description}</>
</div>
<div className="opacity-0 overflow-hidden h-0" style={{ maxWidth: '80vw', whiteSpace: 'pre' }}>
<>{description}</>
</div>
</>
)}
{!!description && <TooltipMarkdown description={description} />}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import React, { useCallback } from 'react';
import React, { useCallback, useId, useMemo, useRef, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button } from 'components/UI';
import { Button, TextArea } from 'components/UI';
import { useStatsHouseShallow } from 'store2';
import { useGlobalLoader } from 'store2/plotQueryStore';

Expand Down Expand Up @@ -44,15 +44,12 @@ export function DashboardInfo({ className }: DashboardInfoProps) {
},
[setParams]
);
const inputDescription = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
setParams((params) => {
params.dashboardDescription = value;
});
},
[setParams]
);

const inputDescription = (value: string) => {
setParams((params) => {
params.dashboardDescription = value;
});
};

const onRemoveDashboard = useCallback(
(event: React.MouseEvent) => {
Expand Down Expand Up @@ -95,13 +92,11 @@ export function DashboardInfo({ className }: DashboardInfoProps) {
Description
</label>
<div className="col-sm-10">
<input
id="dashboard-input-description"
type="text"
className="form-control"
aria-label="Name"
defaultValue={dashboardDescription ?? ''}
<TextArea
className="form-control-sm"
value={dashboardDescription || ''}
onInput={inputDescription}
autoHeight
/>
</div>
</div>
Expand Down
29 changes: 29 additions & 0 deletions statshouse-ui/src/components2/Plot/PlotView/MarkdownRender.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import ReactMarkdown, { Components } from 'react-markdown';
import remarkGfm from 'remark-gfm';

type IMarkdownRenderer = {
children?: string;
className?: string;
allowedElements?: string[];
components?: Components;
unwrapDisallowed?: boolean;
};

const remarkPlugins = [remarkGfm];

const customLinkComponents: Components = {
a: ({ node, ...props }) => (
<a {...props} target="_blank" rel="noopener noreferrer">
{props.children}
</a>
),
};

const _MarkdownRender = ({ children = '', components, ...props }: IMarkdownRenderer) => (
<ReactMarkdown remarkPlugins={remarkPlugins} components={{ ...customLinkComponents, ...components }} {...props}>
{children}
</ReactMarkdown>
);

export const MarkdownRender = React.memo(_MarkdownRender);
36 changes: 28 additions & 8 deletions statshouse-ui/src/components2/Plot/PlotView/PlotHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useStatsHouseShallow } from 'store2';
import { PlotNavigate } from '../PlotNavigate';
import cn from 'classnames';
import css from './style.module.css';
import markdownStyles from '../../style.module.css';
import { ReactComponent as SVGTrash } from 'bootstrap-icons/icons/trash.svg';
import { ReactComponent as SVGBoxArrowUpRight } from 'bootstrap-icons/icons/box-arrow-up-right.svg';
import { ReactComponent as SVGChevronUp } from 'bootstrap-icons/icons/chevron-up.svg';
Expand All @@ -25,6 +26,8 @@ import { PlotHeaderBadges } from './PlotHeaderBadges';
import { getMetricMeta, getMetricName, getMetricWhat } from '../../../store2/helpers';
import { PlotLink } from '../PlotLink';
import { PlotHeaderBadgeResolution } from './PlotHeaderBadgeResolution';
import { MarkdownRender } from './MarkdownRender';
import { TooltipMarkdown } from './TooltipMarkdown';

export type PlotHeaderProps = { plotKey: PlotKey; isDashboard?: boolean };

Expand Down Expand Up @@ -130,10 +133,10 @@ export function _PlotHeader({ plotKey, isDashboard }: PlotHeaderProps) {
setEditTitle(false);
});

const plotTooltip = useMemo(
() => <PlotHeaderTooltipContent name={<PlotName plotKey={plotKey} />} description={description || ''} />,
[description, plotKey]
);
const plotTooltip = useMemo(() => {
const desc = description || '';
return <PlotHeaderTooltipContent name={<PlotName plotKey={plotKey} />} description={desc} />;
}, [description, plotKey]);

if (isDashboard) {
return (
Expand Down Expand Up @@ -220,7 +223,7 @@ export function _PlotHeader({ plotKey, isDashboard }: PlotHeaderProps) {
className="overflow-force-wrap text-secondary fw-normal font-normal flex-grow-0"
style={{ whiteSpace: 'pre-wrap' }}
>
<>{description}</>
<MarkdownRender className={markdownStyles.markdownMargin}>{description}</MarkdownRender>
</small>
)}
</div>
Expand Down Expand Up @@ -312,9 +315,26 @@ export function _PlotHeader({ plotKey, isDashboard }: PlotHeaderProps) {
autoHeight
/>
) : (
<Tooltip className="d-flex" title={description} hover>
<small className="text-secondary w-0 flex-grow-1 text-truncate no-tooltip-safari-fix">
<>{description}</>
<Tooltip
className="d-flex"
title={
<div className="small text-secondary overflow-auto">
<TooltipMarkdown description={description} />
</div>
}
hover
>
<small className="text-secondary w-0 flex-grow-1 no-tooltip-safari-fix">
<MarkdownRender
className={markdownStyles.markdown}
allowedElements={['p', 'a']}
components={{
p: ({ node, ...props }) => <span {...props} />,
}}
unwrapDisallowed
>
{description}
</MarkdownRender>
</small>
</Tooltip>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import React from 'react';
import cn from 'classnames';
import { TooltipMarkdown } from './TooltipMarkdown';

export type PlotHeaderTooltipContentProps = {
name: React.ReactNode;
Expand All @@ -18,16 +19,7 @@ export function PlotHeaderTooltipContent({ name, description }: PlotHeaderToolti
return (
<div className="small text-secondary overflow-auto">
<div className={cn('font-monospace fw-bold', hasDescription && 'mb-3')}>{name}</div>
{hasDescription && (
<>
<div style={{ maxWidth: '80vw', whiteSpace: 'pre-wrap' }}>
<>{description}</>
</div>
<div className="opacity-0 overflow-hidden h-0" style={{ maxWidth: '80vw', whiteSpace: 'pre' }}>
<>{description}</>
</div>
</>
)}
{hasDescription && <TooltipMarkdown description={description} />}
</div>
);
}
29 changes: 29 additions & 0 deletions statshouse-ui/src/components2/Plot/PlotView/TooltipMarkdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 V Kontakte LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import React from 'react';
import markdownStyles from '../../style.module.css';
import { MarkdownRender } from './MarkdownRender';
import cn from 'classnames';

export type ITooltipMarkdownProps = {
description?: string;
};

const _TooltipMarkdown = ({ description }: ITooltipMarkdownProps) => (
<>
<div style={{ maxWidth: '80vw', maxHeight: '80vh' }}>
<MarkdownRender className={cn(markdownStyles.markdownMargin, markdownStyles.markdownSpace)}>
{description}
</MarkdownRender>
</div>
<div className="opacity-0 overflow-hidden h-0" style={{ maxWidth: '80vw', whiteSpace: 'pre' }}>
<MarkdownRender className={markdownStyles.markdownMargin}>{description}</MarkdownRender>
</div>
</>
);

export const TooltipMarkdown = React.memo(_TooltipMarkdown);
29 changes: 29 additions & 0 deletions statshouse-ui/src/components2/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright 2024 V Kontakte LLC
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

/* referring to tag <p> because <Markdown> returns content inside tag <p> */
.markdown {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin: 0;
}

.markdownMargin * {
margin: 0;
}

.markdownSpace p,
.markdownSpace h1,
.markdownSpace h2,
.markdownSpace h3,
.markdownSpace h4,
.markdownSpace h5,
.markdownSpace h6,
.markdownSpace li {
white-space: break-spaces;
}

0 comments on commit 16917cf

Please sign in to comment.