Limit notification length

Summary: See https://fb.workplace.com/groups/flippersupport/permalink/1593262167821102/

Reviewed By: antonk52

Differential Revision: D44459787

fbshipit-source-id: ef14e560c523fddf4f815d0faafa37e44dc416b8
This commit is contained in:
Andrey Goncharov
2023-03-28 07:00:20 -07:00
committed by Facebook GitHub Bot
parent 914db21c7d
commit 35c145463a
4 changed files with 59 additions and 6 deletions

View File

@@ -16,6 +16,7 @@ import {useStore} from '../utils/useStore';
import {getAppVersion} from '../utils/info'; import {getAppVersion} from '../utils/info';
import {checkForUpdate} from '../fb-stubs/checkForUpdate'; import {checkForUpdate} from '../fb-stubs/checkForUpdate';
import {getRenderHostInstance} from 'flipper-frontend-core'; import {getRenderHostInstance} from 'flipper-frontend-core';
import {NotificationBody} from '../ui/components/NotificationBody';
export type VersionCheckResult = export type VersionCheckResult =
| { | {
@@ -71,7 +72,7 @@ export default function UpdateIndicator() {
placement: 'bottomLeft', placement: 'bottomLeft',
key: 'launchermsg', key: 'launchermsg',
message: 'Launch problem', message: 'Launch problem',
description: launcherMsg.message, description: <NotificationBody text={launcherMsg.message} />,
duration: null, duration: null,
}); });
} else { } else {
@@ -79,7 +80,7 @@ export default function UpdateIndicator() {
placement: 'bottomLeft', placement: 'bottomLeft',
key: 'launchermsg', key: 'launchermsg',
message: 'Flipper version warning', message: 'Flipper version warning',
description: launcherMsg.message, description: <NotificationBody text={launcherMsg.message} />,
duration: null, duration: null,
}); });
} }

View File

@@ -24,6 +24,7 @@ import {ClientDescription, timeout} from 'flipper-common';
import {reportPlatformFailures} from 'flipper-common'; import {reportPlatformFailures} from 'flipper-common';
import {sideEffect} from '../utils/sideEffect'; import {sideEffect} from '../utils/sideEffect';
import {waitFor} from '../utils/waitFor'; import {waitFor} from '../utils/waitFor';
import {NotificationBody} from '../ui/components/NotificationBody';
export function connectFlipperServerToStore( export function connectFlipperServerToStore(
server: FlipperServer, server: FlipperServer,
@@ -35,7 +36,7 @@ export function connectFlipperServerToStore(
console.warn(text); console.warn(text);
notification.open({ notification.open({
message: title, message: title,
description: description, description: <NotificationBody text={description} />,
type: type, type: type,
duration: 0, duration: 0,
key: text, key: text,
@@ -50,7 +51,7 @@ export function connectFlipperServerToStore(
} else { } else {
notification.error({ notification.error({
message: 'Connection error', message: 'Connection error',
description: <>{err.message ?? err}</>, description: <NotificationBody text={err.message ?? err} />,
duration: null, duration: null,
}); });
} }

View File

@@ -0,0 +1,49 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {CopyOutlined} from '@ant-design/icons';
import {Typography} from 'antd';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {theme} from 'flipper-plugin';
import * as React from 'react';
type NotificationbodyProps = {
text: string;
};
export const NotificationBody: React.FC<NotificationbodyProps> = ({text}) => {
const messageLoggedRef = React.useRef(false);
return (
<Typography.Paragraph
style={{color: 'inherit'}}
ellipsis={{
rows: 10,
tooltip: 'Message is too long. Please, find the full text in logs.',
onEllipsis: (ellipsis) => {
if (messageLoggedRef.current) {
return;
}
if (ellipsis) {
console.warn(
'Message is too long to fit in the notification box. Original text:',
text,
);
messageLoggedRef.current = true;
}
},
}}
copyable={{
onCopy: () => getRenderHostInstance().writeTextToClipboard(text),
icon: <CopyOutlined style={{color: theme.textColorSecondary}} />,
}}>
{text}
</Typography.Paragraph>
);
};

View File

@@ -14,6 +14,7 @@ import {setStaticView} from '../reducers/connections';
import {getStore} from '../store'; import {getStore} from '../store';
import {Layout} from '../ui'; import {Layout} from '../ui';
import {v4 as uuid} from 'uuid'; import {v4 as uuid} from 'uuid';
import {NotificationBody} from '../ui/components/NotificationBody';
const {Link} = Typography; const {Link} = Typography;
@@ -22,9 +23,10 @@ export function showErrorNotification(message: string, description?: string) {
notification.error({ notification.error({
key, key,
message, message,
description: ( description: description ? (
<NotificationBody text={description} />
) : (
<Layout.Container gap> <Layout.Container gap>
{description ?? <p>{description}</p>}
<p> <p>
See{' '} See{' '}
<Link <Link