From 35c145463a6650363e4604789ff8d4e8c47f51e9 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Tue, 28 Mar 2023 07:00:20 -0700 Subject: [PATCH] Limit notification length Summary: See https://fb.workplace.com/groups/flippersupport/permalink/1593262167821102/ Reviewed By: antonk52 Differential Revision: D44459787 fbshipit-source-id: ef14e560c523fddf4f815d0faafa37e44dc416b8 --- .../src/chrome/UpdateIndicator.tsx | 5 +- .../src/dispatcher/flipperServer.tsx | 5 +- .../src/ui/components/NotificationBody.tsx | 49 +++++++++++++++++++ .../src/utils/notifications.tsx | 6 ++- 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 desktop/flipper-ui-core/src/ui/components/NotificationBody.tsx diff --git a/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx b/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx index cebab7698..fdaaa3851 100644 --- a/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx +++ b/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx @@ -16,6 +16,7 @@ import {useStore} from '../utils/useStore'; import {getAppVersion} from '../utils/info'; import {checkForUpdate} from '../fb-stubs/checkForUpdate'; import {getRenderHostInstance} from 'flipper-frontend-core'; +import {NotificationBody} from '../ui/components/NotificationBody'; export type VersionCheckResult = | { @@ -71,7 +72,7 @@ export default function UpdateIndicator() { placement: 'bottomLeft', key: 'launchermsg', message: 'Launch problem', - description: launcherMsg.message, + description: , duration: null, }); } else { @@ -79,7 +80,7 @@ export default function UpdateIndicator() { placement: 'bottomLeft', key: 'launchermsg', message: 'Flipper version warning', - description: launcherMsg.message, + description: , duration: null, }); } diff --git a/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx b/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx index fefc9b9b2..fd7f6254b 100644 --- a/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx +++ b/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx @@ -24,6 +24,7 @@ import {ClientDescription, timeout} from 'flipper-common'; import {reportPlatformFailures} from 'flipper-common'; import {sideEffect} from '../utils/sideEffect'; import {waitFor} from '../utils/waitFor'; +import {NotificationBody} from '../ui/components/NotificationBody'; export function connectFlipperServerToStore( server: FlipperServer, @@ -35,7 +36,7 @@ export function connectFlipperServerToStore( console.warn(text); notification.open({ message: title, - description: description, + description: , type: type, duration: 0, key: text, @@ -50,7 +51,7 @@ export function connectFlipperServerToStore( } else { notification.error({ message: 'Connection error', - description: <>{err.message ?? err}, + description: , duration: null, }); } diff --git a/desktop/flipper-ui-core/src/ui/components/NotificationBody.tsx b/desktop/flipper-ui-core/src/ui/components/NotificationBody.tsx new file mode 100644 index 000000000..e38f027bb --- /dev/null +++ b/desktop/flipper-ui-core/src/ui/components/NotificationBody.tsx @@ -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 = ({text}) => { + const messageLoggedRef = React.useRef(false); + + return ( + { + 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: , + }}> + {text} + + ); +}; diff --git a/desktop/flipper-ui-core/src/utils/notifications.tsx b/desktop/flipper-ui-core/src/utils/notifications.tsx index 1109dca20..8044809f6 100644 --- a/desktop/flipper-ui-core/src/utils/notifications.tsx +++ b/desktop/flipper-ui-core/src/utils/notifications.tsx @@ -14,6 +14,7 @@ import {setStaticView} from '../reducers/connections'; import {getStore} from '../store'; import {Layout} from '../ui'; import {v4 as uuid} from 'uuid'; +import {NotificationBody} from '../ui/components/NotificationBody'; const {Link} = Typography; @@ -22,9 +23,10 @@ export function showErrorNotification(message: string, description?: string) { notification.error({ key, message, - description: ( + description: description ? ( + + ) : ( - {description ??

{description}

}

See{' '}