| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {Heartbeat} from './heartbeat'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import * as stylex from '@stylexjs/stylex'; |
| b69ab31 | | | 11 | import {Button} from 'isl-components/Button'; |
| b69ab31 | | | 12 | import {ErrorNotice} from 'isl-components/ErrorNotice'; |
| b69ab31 | | | 13 | import {Icon} from 'isl-components/Icon'; |
| b69ab31 | | | 14 | import {Tooltip} from 'isl-components/Tooltip'; |
| b69ab31 | | | 15 | import {useAtomValue} from 'jotai'; |
| b69ab31 | | | 16 | import {Copyable} from './Copyable'; |
| b69ab31 | | | 17 | import {DropdownFields} from './DropdownFields'; |
| b69ab31 | | | 18 | import {Internal} from './Internal'; |
| b69ab31 | | | 19 | import {DEFAULT_HEARTBEAT_TIMEOUT_MS, useHeartbeat} from './heartbeat'; |
| b69ab31 | | | 20 | import {t, T} from './i18n'; |
| b69ab31 | | | 21 | import platform from './platform'; |
| b69ab31 | | | 22 | import {applicationinfo} from './serverAPIState'; |
| b69ab31 | | | 23 | |
| b69ab31 | | | 24 | import './BugButton.css'; |
| b69ab31 | | | 25 | |
| b69ab31 | | | 26 | const styles = stylex.create({ |
| b69ab31 | | | 27 | centered: { |
| b69ab31 | | | 28 | justifyContent: 'center', |
| b69ab31 | | | 29 | }, |
| b69ab31 | | | 30 | }); |
| b69ab31 | | | 31 | |
| b69ab31 | | | 32 | export function BugButton() { |
| b69ab31 | | | 33 | return ( |
| b69ab31 | | | 34 | <Tooltip |
| b69ab31 | | | 35 | trigger="click" |
| b69ab31 | | | 36 | component={dismiss => <BugDropdown dismiss={dismiss} />} |
| b69ab31 | | | 37 | group="topbar" |
| b69ab31 | | | 38 | placement="bottom"> |
| b69ab31 | | | 39 | <Button icon data-testid="bug-button"> |
| b69ab31 | | | 40 | <Icon icon="bug" /> |
| b69ab31 | | | 41 | </Button> |
| b69ab31 | | | 42 | </Tooltip> |
| b69ab31 | | | 43 | ); |
| b69ab31 | | | 44 | } |
| b69ab31 | | | 45 | |
| b69ab31 | | | 46 | function BugDropdown({dismiss}: {dismiss: () => void}) { |
| b69ab31 | | | 47 | const heartbeat = useHeartbeat(); |
| b69ab31 | | | 48 | |
| b69ab31 | | | 49 | return ( |
| b69ab31 | | | 50 | <DropdownFields |
| b69ab31 | | | 51 | title={<T>Help</T>} |
| b69ab31 | | | 52 | icon="bug" |
| b69ab31 | | | 53 | data-testid="bug-dropdown" |
| b69ab31 | | | 54 | className="bug-dropdown"> |
| b69ab31 | | | 55 | <ISLVersion /> |
| b69ab31 | | | 56 | <HeartbeatWarning heartbeat={heartbeat} /> |
| b69ab31 | | | 57 | <div className="bug-dropdown-actions"> |
| b69ab31 | | | 58 | <FileABug dismissBugDropdown={dismiss} heartbeat={heartbeat} /> |
| b69ab31 | | | 59 | </div> |
| b69ab31 | | | 60 | </DropdownFields> |
| b69ab31 | | | 61 | ); |
| b69ab31 | | | 62 | } |
| b69ab31 | | | 63 | |
| b69ab31 | | | 64 | function ISLVersion() { |
| b69ab31 | | | 65 | const info = useAtomValue(applicationinfo); |
| b69ab31 | | | 66 | if (info == null) { |
| b69ab31 | | | 67 | return <Icon icon="loading" />; |
| b69ab31 | | | 68 | } |
| b69ab31 | | | 69 | |
| b69ab31 | | | 70 | return ( |
| b69ab31 | | | 71 | <div className="bug-dropdown-version"> |
| b69ab31 | | | 72 | <Copyable children={`ISL version ${info.version} (${info.platformName})`} /> |
| b69ab31 | | | 73 | </div> |
| b69ab31 | | | 74 | ); |
| b69ab31 | | | 75 | } |
| b69ab31 | | | 76 | |
| b69ab31 | | | 77 | function HeartbeatWarning({heartbeat}: {heartbeat: Heartbeat}) { |
| b69ab31 | | | 78 | const appInfo = useAtomValue(applicationinfo); |
| b69ab31 | | | 79 | if (heartbeat.type === 'timeout') { |
| b69ab31 | | | 80 | return ( |
| b69ab31 | | | 81 | <> |
| b69ab31 | | | 82 | <ErrorNotice |
| b69ab31 | | | 83 | error={new Error(t(`Heartbeat timed out after ${DEFAULT_HEARTBEAT_TIMEOUT_MS}ms`))} |
| b69ab31 | | | 84 | title={t("Can't reach server — most features won't work")} |
| b69ab31 | | | 85 | description={t('The ISL server needs to be restarted')}></ErrorNotice> |
| b69ab31 | | | 86 | {appInfo && ( |
| b69ab31 | | | 87 | <div> |
| b69ab31 | | | 88 | <T |
| b69ab31 | | | 89 | replace={{ |
| b69ab31 | | | 90 | $logfile: ( |
| b69ab31 | | | 91 | <code> |
| b69ab31 | | | 92 | <Copyable className="log-file-path">{appInfo.logFilePath}</Copyable> |
| b69ab31 | | | 93 | </code> |
| b69ab31 | | | 94 | ), |
| b69ab31 | | | 95 | }}> |
| b69ab31 | | | 96 | Your log file is located at: $logfile |
| b69ab31 | | | 97 | </T> |
| b69ab31 | | | 98 | </div> |
| b69ab31 | | | 99 | )} |
| b69ab31 | | | 100 | </> |
| b69ab31 | | | 101 | ); |
| b69ab31 | | | 102 | } |
| b69ab31 | | | 103 | return null; |
| b69ab31 | | | 104 | } |
| b69ab31 | | | 105 | |
| b69ab31 | | | 106 | function FileABug({ |
| b69ab31 | | | 107 | dismissBugDropdown, |
| b69ab31 | | | 108 | heartbeat, |
| b69ab31 | | | 109 | }: { |
| b69ab31 | | | 110 | dismissBugDropdown: () => void; |
| b69ab31 | | | 111 | heartbeat: Heartbeat; |
| b69ab31 | | | 112 | }) { |
| b69ab31 | | | 113 | return Internal.FileABugButton != null ? ( |
| b69ab31 | | | 114 | <Internal.FileABugButton dismissBugDropdown={dismissBugDropdown} heartbeat={heartbeat} /> |
| b69ab31 | | | 115 | ) : ( |
| b69ab31 | | | 116 | <OSSFileABug /> |
| b69ab31 | | | 117 | ); |
| b69ab31 | | | 118 | } |
| b69ab31 | | | 119 | |
| b69ab31 | | | 120 | function OSSFileABug() { |
| b69ab31 | | | 121 | return ( |
| b69ab31 | | | 122 | <> |
| b69ab31 | | | 123 | <Button |
| b69ab31 | | | 124 | xstyle={styles.centered} |
| b69ab31 | | | 125 | onClick={() => { |
| b69ab31 | | | 126 | platform.openExternalLink('https://sapling-scm.com/docs/addons/isl'); |
| b69ab31 | | | 127 | }}> |
| b69ab31 | | | 128 | <Icon icon="book" slot="start" /> |
| b69ab31 | | | 129 | <T>View Documentation</T> |
| b69ab31 | | | 130 | </Button> |
| b69ab31 | | | 131 | <Button |
| b69ab31 | | | 132 | xstyle={styles.centered} |
| b69ab31 | | | 133 | onClick={() => { |
| b69ab31 | | | 134 | platform.openExternalLink('https://discord.gg/X6baZ94Vzh'); |
| b69ab31 | | | 135 | }}> |
| b69ab31 | | | 136 | <Icon icon="comment-discussion" slot="start" /> |
| b69ab31 | | | 137 | <T>Help and Feedback on Discord</T> |
| b69ab31 | | | 138 | </Button> |
| b69ab31 | | | 139 | <Button |
| b69ab31 | | | 140 | xstyle={styles.centered} |
| b69ab31 | | | 141 | onClick={() => { |
| b69ab31 | | | 142 | platform.openExternalLink('https://github.com/facebook/sapling/issues'); |
| b69ab31 | | | 143 | }}> |
| b69ab31 | | | 144 | <Icon icon="bug" slot="start" /> |
| b69ab31 | | | 145 | <T>Report an Issue on GitHub</T> |
| b69ab31 | | | 146 | </Button> |
| b69ab31 | | | 147 | </> |
| b69ab31 | | | 148 | ); |
| b69ab31 | | | 149 | } |