| 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 {TypeaheadResult} from 'isl-components/Types'; |
| b69ab31 | | | 9 | import type {ReactNode} from 'react'; |
| b69ab31 | | | 10 | import type {BookmarkKind} from './Bookmark'; |
| b69ab31 | | | 11 | import type {Result, StableInfo} from './types'; |
| b69ab31 | | | 12 | |
| b69ab31 | | | 13 | import * as stylex from '@stylexjs/stylex'; |
| b69ab31 | | | 14 | import {Banner, BannerKind} from 'isl-components/Banner'; |
| b69ab31 | | | 15 | import {Button} from 'isl-components/Button'; |
| b69ab31 | | | 16 | import {Checkbox} from 'isl-components/Checkbox'; |
| b69ab31 | | | 17 | import {Dropdown} from 'isl-components/Dropdown'; |
| b69ab31 | | | 18 | import {InlineErrorBadge} from 'isl-components/ErrorNotice'; |
| b69ab31 | | | 19 | import {Icon} from 'isl-components/Icon'; |
| b69ab31 | | | 20 | import {Kbd} from 'isl-components/Kbd'; |
| b69ab31 | | | 21 | import {KeyCode, Modifier} from 'isl-components/KeyboardShortcuts'; |
| b69ab31 | | | 22 | import {Subtle} from 'isl-components/Subtle'; |
| b69ab31 | | | 23 | import {extractTokens} from 'isl-components/Tokens'; |
| b69ab31 | | | 24 | import {Tooltip} from 'isl-components/Tooltip'; |
| b69ab31 | | | 25 | import {Typeahead} from 'isl-components/Typeahead'; |
| b69ab31 | | | 26 | import {atom, useAtom, useAtomValue} from 'jotai'; |
| b69ab31 | | | 27 | import React, {useState} from 'react'; |
| b69ab31 | | | 28 | import {firstLine, notEmpty} from 'shared/utils'; |
| b69ab31 | | | 29 | import {spacing} from '../../components/theme/tokens.stylex'; |
| b69ab31 | | | 30 | import {Bookmark, getBookmarkAddons} from './Bookmark'; |
| b69ab31 | | | 31 | import { |
| b69ab31 | | | 32 | addManualStable, |
| b69ab31 | | | 33 | bookmarksDataStorage, |
| b69ab31 | | | 34 | fetchedStablesAtom, |
| b69ab31 | | | 35 | type MasterBookmarkVisibility, |
| b69ab31 | | | 36 | recommendedBookmarksAtom, |
| b69ab31 | | | 37 | recommendedBookmarksAvailableAtom, |
| b69ab31 | | | 38 | REMOTE_MASTER_BOOKMARK, |
| b69ab31 | | | 39 | remoteBookmarks, |
| b69ab31 | | | 40 | removeManualStable, |
| b69ab31 | | | 41 | } from './BookmarksData'; |
| b69ab31 | | | 42 | import serverAPI from './ClientToServerAPI'; |
| b69ab31 | | | 43 | import {Column, Row, ScrollY} from './ComponentUtils'; |
| b69ab31 | | | 44 | import {DropdownFields} from './DropdownFields'; |
| b69ab31 | | | 45 | import {hiddenMasterFeatureAvailableAtom, shouldHideMasterAtom} from './HiddenMasterData'; |
| b69ab31 | | | 46 | import {useCommandEvent} from './ISLShortcuts'; |
| b69ab31 | | | 47 | import {Internal} from './Internal'; |
| b69ab31 | | | 48 | import {T, t} from './i18n'; |
| b69ab31 | | | 49 | import {readAtom} from './jotaiUtils'; |
| b69ab31 | | | 50 | import {latestDag} from './serverAPIState'; |
| b69ab31 | | | 51 | |
| b69ab31 | | | 52 | const styles = stylex.create({ |
| b69ab31 | | | 53 | container: { |
| b69ab31 | | | 54 | alignItems: 'flex-start', |
| b69ab31 | | | 55 | gap: spacing.double, |
| b69ab31 | | | 56 | width: 500, |
| b69ab31 | | | 57 | maxWidth: 500, |
| b69ab31 | | | 58 | }, |
| b69ab31 | | | 59 | bookmarkGroup: { |
| b69ab31 | | | 60 | alignItems: 'flex-start', |
| b69ab31 | | | 61 | marginInline: spacing.half, |
| b69ab31 | | | 62 | gap: spacing.half, |
| b69ab31 | | | 63 | }, |
| b69ab31 | | | 64 | description: { |
| b69ab31 | | | 65 | marginBottom: spacing.half, |
| b69ab31 | | | 66 | }, |
| b69ab31 | | | 67 | masterBookmarkRow: { |
| b69ab31 | | | 68 | alignItems: 'center', |
| b69ab31 | | | 69 | gap: '8px', |
| b69ab31 | | | 70 | }, |
| b69ab31 | | | 71 | masterBookmarkDropdown: { |
| b69ab31 | | | 72 | fontSize: '11px', |
| b69ab31 | | | 73 | padding: '1px 2px', |
| b69ab31 | | | 74 | height: '20px', |
| b69ab31 | | | 75 | }, |
| b69ab31 | | | 76 | }); |
| b69ab31 | | | 77 | |
| b69ab31 | | | 78 | export function BookmarksManagerMenu() { |
| b69ab31 | | | 79 | const additionalToggles = useCommandEvent('ToggleBookmarksManagerDropdown'); |
| b69ab31 | | | 80 | const bookmarks = useAtomValue(remoteBookmarks); |
| b69ab31 | | | 81 | |
| b69ab31 | | | 82 | if (bookmarks.length < 2) { |
| b69ab31 | | | 83 | // No use showing bookmarks menu if there's only one remote bookmark |
| b69ab31 | | | 84 | return null; |
| b69ab31 | | | 85 | } |
| b69ab31 | | | 86 | |
| b69ab31 | | | 87 | const menuButton = ( |
| b69ab31 | | | 88 | <Tooltip |
| b69ab31 | | | 89 | component={dismiss => <BookmarksManager dismiss={dismiss} />} |
| b69ab31 | | | 90 | trigger="click" |
| b69ab31 | | | 91 | placement="bottom" |
| b69ab31 | | | 92 | group="topbar" |
| b69ab31 | | | 93 | title={ |
| b69ab31 | | | 94 | <T replace={{$shortcut: <Kbd keycode={KeyCode.M} modifiers={[Modifier.ALT]} />}}> |
| b69ab31 | | | 95 | Bookmarks Manager ($shortcut) |
| b69ab31 | | | 96 | </T> |
| b69ab31 | | | 97 | } |
| b69ab31 | | | 98 | additionalToggles={additionalToggles.asEventTarget()}> |
| b69ab31 | | | 99 | <Button icon data-testid="bookmarks-manager-button"> |
| b69ab31 | | | 100 | <Icon icon="bookmark" /> |
| b69ab31 | | | 101 | </Button> |
| b69ab31 | | | 102 | </Tooltip> |
| b69ab31 | | | 103 | ); |
| b69ab31 | | | 104 | |
| b69ab31 | | | 105 | const Reminder = Internal.RecommendedBookmarkPrompt; |
| b69ab31 | | | 106 | return Reminder ? <Reminder>{menuButton}</Reminder> : menuButton; |
| b69ab31 | | | 107 | } |
| b69ab31 | | | 108 | |
| b69ab31 | | | 109 | function BookmarksManager(_props: {dismiss: () => void}) { |
| b69ab31 | | | 110 | const bookmarks = useAtomValue(remoteBookmarks); |
| b69ab31 | | | 111 | const bookmarksData = useAtomValue(bookmarksDataStorage); |
| b69ab31 | | | 112 | const recommendedBookmarks = useAtomValue(recommendedBookmarksAtom); |
| b69ab31 | | | 113 | const recommendedBookmarksAvailable = useAtomValue(recommendedBookmarksAvailableAtom); |
| b69ab31 | | | 114 | const enableRecommended = bookmarksData.useRecommendedBookmark && recommendedBookmarksAvailable; |
| b69ab31 | | | 115 | |
| b69ab31 | | | 116 | // Place recommended bookmarks (and remote/master) first if enabled, then the rest |
| b69ab31 | | | 117 | const priority = new Set(recommendedBookmarks).add(REMOTE_MASTER_BOOKMARK); |
| b69ab31 | | | 118 | const orderedBookmarks = |
| b69ab31 | | | 119 | enableRecommended && recommendedBookmarks.size > 0 |
| b69ab31 | | | 120 | ? [...bookmarks.filter(b => priority.has(b)), ...bookmarks.filter(b => !priority.has(b))] |
| b69ab31 | | | 121 | : bookmarks; |
| b69ab31 | | | 122 | |
| b69ab31 | | | 123 | return ( |
| b69ab31 | | | 124 | <DropdownFields |
| b69ab31 | | | 125 | title={<T>Bookmarks Manager</T>} |
| b69ab31 | | | 126 | icon="bookmark" |
| b69ab31 | | | 127 | data-testid="bookmarks-manager-dropdown"> |
| b69ab31 | | | 128 | <Column xstyle={styles.container}> |
| b69ab31 | | | 129 | {Internal.RecommendedBookmarkSection?.()} |
| b69ab31 | | | 130 | <Section |
| b69ab31 | | | 131 | title={<T>Remote Bookmarks</T>} |
| b69ab31 | | | 132 | description={<T>Uncheck remote bookmarks you don't use to hide them</T>}> |
| b69ab31 | | | 133 | <BookmarksList bookmarks={orderedBookmarks} kind="remote" /> |
| b69ab31 | | | 134 | </Section> |
| b69ab31 | | | 135 | <StableLocationsSection /> |
| b69ab31 | | | 136 | </Column> |
| b69ab31 | | | 137 | </DropdownFields> |
| b69ab31 | | | 138 | ); |
| b69ab31 | | | 139 | } |
| b69ab31 | | | 140 | |
| b69ab31 | | | 141 | const latestPublicCommitAtom = atom(get => { |
| b69ab31 | | | 142 | const dag = get(latestDag); |
| b69ab31 | | | 143 | const latestHash = dag.heads(dag.public_()).toArray()[0]; |
| b69ab31 | | | 144 | return latestHash ? dag.get(latestHash) : undefined; |
| b69ab31 | | | 145 | }); |
| b69ab31 | | | 146 | |
| b69ab31 | | | 147 | function stableIsNewerThanMainWarning(latestPublicDate?: Date, info?: Result<StableInfo>) { |
| b69ab31 | | | 148 | const isNewerThanLatest = info?.value && latestPublicDate && info.value.date > latestPublicDate; |
| b69ab31 | | | 149 | return isNewerThanLatest ? ( |
| b69ab31 | | | 150 | <Banner kind={BannerKind.warning}> |
| b69ab31 | | | 151 | <T>Stable is newer than latest pulled commit. Pull to fetch latest.</T> |
| b69ab31 | | | 152 | </Banner> |
| b69ab31 | | | 153 | ) : undefined; |
| b69ab31 | | | 154 | } |
| b69ab31 | | | 155 | |
| b69ab31 | | | 156 | function StableLocationsSection() { |
| b69ab31 | | | 157 | const stableLocations = useAtomValue(fetchedStablesAtom); |
| b69ab31 | | | 158 | const latestPublic = useAtomValue(latestPublicCommitAtom); |
| b69ab31 | | | 159 | |
| b69ab31 | | | 160 | return ( |
| b69ab31 | | | 161 | <Section |
| b69ab31 | | | 162 | title={<T>Stable Locations</T>} |
| b69ab31 | | | 163 | description={ |
| b69ab31 | | | 164 | <T> |
| b69ab31 | | | 165 | Commits that have had successful builds and warmed up caches for a particular build target |
| b69ab31 | | | 166 | </T> |
| b69ab31 | | | 167 | }> |
| b69ab31 | | | 168 | <BookmarksList |
| b69ab31 | | | 169 | bookmarks={ |
| b69ab31 | | | 170 | stableLocations?.special |
| b69ab31 | | | 171 | ?.map(info => { |
| b69ab31 | | | 172 | if (info.value == null) { |
| b69ab31 | | | 173 | return undefined; |
| b69ab31 | | | 174 | } |
| b69ab31 | | | 175 | return { |
| b69ab31 | | | 176 | ...info.value, |
| b69ab31 | | | 177 | extra: stableIsNewerThanMainWarning(latestPublic?.date, info), |
| b69ab31 | | | 178 | }; |
| b69ab31 | | | 179 | }) |
| b69ab31 | | | 180 | .filter(notEmpty) ?? [] |
| b69ab31 | | | 181 | } |
| b69ab31 | | | 182 | kind="stable" |
| b69ab31 | | | 183 | /> |
| b69ab31 | | | 184 | {stableLocations?.manual && ( |
| b69ab31 | | | 185 | <BookmarksList |
| b69ab31 | | | 186 | bookmarks={Object.entries(stableLocations.manual)?.map(([name, info]) => { |
| b69ab31 | | | 187 | const deleteButton = ( |
| b69ab31 | | | 188 | <Tooltip title={t('Remove this stable location')}> |
| b69ab31 | | | 189 | <Button |
| b69ab31 | | | 190 | icon |
| b69ab31 | | | 191 | onClick={e => { |
| b69ab31 | | | 192 | removeManualStable(name); |
| b69ab31 | | | 193 | e.stopPropagation(); |
| b69ab31 | | | 194 | }}> |
| b69ab31 | | | 195 | <Icon icon="trash" /> |
| b69ab31 | | | 196 | </Button> |
| b69ab31 | | | 197 | </Tooltip> |
| b69ab31 | | | 198 | ); |
| b69ab31 | | | 199 | if (info == null) { |
| b69ab31 | | | 200 | return { |
| b69ab31 | | | 201 | kind: 'custom', |
| b69ab31 | | | 202 | custom: ( |
| b69ab31 | | | 203 | <Row> |
| b69ab31 | | | 204 | {name}: <Icon icon="loading" /> |
| b69ab31 | | | 205 | </Row> |
| b69ab31 | | | 206 | ), |
| b69ab31 | | | 207 | }; |
| b69ab31 | | | 208 | } |
| b69ab31 | | | 209 | if (info.error) { |
| b69ab31 | | | 210 | return { |
| b69ab31 | | | 211 | kind: 'custom', |
| b69ab31 | | | 212 | custom: ( |
| b69ab31 | | | 213 | <Row> |
| b69ab31 | | | 214 | {name}:{' '} |
| b69ab31 | | | 215 | <InlineErrorBadge error={info.error}> |
| b69ab31 | | | 216 | {firstLine(info.error.toString())} |
| b69ab31 | | | 217 | </InlineErrorBadge> |
| b69ab31 | | | 218 | {deleteButton} |
| b69ab31 | | | 219 | </Row> |
| b69ab31 | | | 220 | ), |
| b69ab31 | | | 221 | }; |
| b69ab31 | | | 222 | } |
| b69ab31 | | | 223 | return { |
| b69ab31 | | | 224 | ...info.value, |
| b69ab31 | | | 225 | extra: ( |
| b69ab31 | | | 226 | <Row> |
| b69ab31 | | | 227 | {deleteButton} |
| b69ab31 | | | 228 | {stableIsNewerThanMainWarning(latestPublic?.date, info)} |
| b69ab31 | | | 229 | </Row> |
| b69ab31 | | | 230 | ), |
| b69ab31 | | | 231 | }; |
| b69ab31 | | | 232 | })} |
| b69ab31 | | | 233 | kind="stable" |
| b69ab31 | | | 234 | /> |
| b69ab31 | | | 235 | )} |
| b69ab31 | | | 236 | {stableLocations?.repoSupportsCustomStables === true && <AddStableLocation />} |
| b69ab31 | | | 237 | </Section> |
| b69ab31 | | | 238 | ); |
| b69ab31 | | | 239 | } |
| b69ab31 | | | 240 | |
| b69ab31 | | | 241 | let typeaheadOptionsPromise: Promise<Result<Array<TypeaheadResult>>> | undefined; |
| b69ab31 | | | 242 | const getStableLocationsTypeaheadOptions = () => { |
| b69ab31 | | | 243 | if (typeaheadOptionsPromise != null) { |
| b69ab31 | | | 244 | return typeaheadOptionsPromise; |
| b69ab31 | | | 245 | } |
| b69ab31 | | | 246 | typeaheadOptionsPromise = (async () => { |
| b69ab31 | | | 247 | serverAPI.postMessage({type: 'fetchStableLocationAutocompleteOptions'}); |
| b69ab31 | | | 248 | const result = await serverAPI.nextMessageMatching( |
| b69ab31 | | | 249 | 'fetchedStableLocationAutocompleteOptions', |
| b69ab31 | | | 250 | () => true, |
| b69ab31 | | | 251 | ); |
| b69ab31 | | | 252 | return result.result; |
| b69ab31 | | | 253 | })(); |
| b69ab31 | | | 254 | return typeaheadOptionsPromise; |
| b69ab31 | | | 255 | }; |
| b69ab31 | | | 256 | |
| b69ab31 | | | 257 | const stableLocationsTypeaheadOptions = atom(getStableLocationsTypeaheadOptions); |
| b69ab31 | | | 258 | |
| b69ab31 | | | 259 | function AddStableLocation() { |
| b69ab31 | | | 260 | const [showingInput, setShowingInput] = useState(false); |
| b69ab31 | | | 261 | const [query, setQuery] = useState(''); |
| b69ab31 | | | 262 | const addRef = React.useRef<HTMLButtonElement>(null); |
| b69ab31 | | | 263 | return ( |
| b69ab31 | | | 264 | <div style={{paddingTop: 'var(--pad)'}}> |
| b69ab31 | | | 265 | {showingInput ? ( |
| b69ab31 | | | 266 | <div> |
| b69ab31 | | | 267 | <Subtle>{Internal.StableLocationAddInformation?.()}</Subtle> |
| b69ab31 | | | 268 | <Row> |
| b69ab31 | | | 269 | <Typeahead |
| b69ab31 | | | 270 | tokenString={query} |
| b69ab31 | | | 271 | setTokenString={setQuery} |
| b69ab31 | | | 272 | fetchTokens={async (query: string) => { |
| b69ab31 | | | 273 | const fetchStartTimestamp = Date.now(); |
| b69ab31 | | | 274 | const options = await readAtom(stableLocationsTypeaheadOptions); |
| b69ab31 | | | 275 | const normalized = query.toLowerCase(); |
| b69ab31 | | | 276 | return { |
| b69ab31 | | | 277 | fetchStartTimestamp, |
| b69ab31 | | | 278 | values: |
| b69ab31 | | | 279 | options.value?.filter( |
| b69ab31 | | | 280 | opt => |
| b69ab31 | | | 281 | opt.value.toLowerCase().includes(normalized) || |
| b69ab31 | | | 282 | opt.label.toLowerCase().includes(normalized), |
| b69ab31 | | | 283 | ) ?? [], |
| b69ab31 | | | 284 | }; |
| b69ab31 | | | 285 | }} |
| b69ab31 | | | 286 | onSaveNewToken={() => { |
| b69ab31 | | | 287 | addRef?.current?.focus(); |
| b69ab31 | | | 288 | }} |
| b69ab31 | | | 289 | autoFocus |
| b69ab31 | | | 290 | maxTokens={1} |
| b69ab31 | | | 291 | /> |
| b69ab31 | | | 292 | <Button |
| b69ab31 | | | 293 | ref={addRef} |
| b69ab31 | | | 294 | primary |
| b69ab31 | | | 295 | onClick={e => { |
| b69ab31 | | | 296 | // only expect one token |
| b69ab31 | | | 297 | const [[token]] = extractTokens(query); |
| b69ab31 | | | 298 | const stable = token.trim(); |
| b69ab31 | | | 299 | if (stable) { |
| b69ab31 | | | 300 | addManualStable(stable); |
| b69ab31 | | | 301 | setQuery(''); |
| b69ab31 | | | 302 | setShowingInput(false); |
| b69ab31 | | | 303 | } |
| b69ab31 | | | 304 | e.stopPropagation(); |
| b69ab31 | | | 305 | }}> |
| b69ab31 | | | 306 | <T>Add</T> |
| b69ab31 | | | 307 | </Button> |
| b69ab31 | | | 308 | </Row> |
| b69ab31 | | | 309 | </div> |
| b69ab31 | | | 310 | ) : ( |
| b69ab31 | | | 311 | <Button |
| b69ab31 | | | 312 | icon |
| b69ab31 | | | 313 | onClick={e => { |
| b69ab31 | | | 314 | e.stopPropagation(); |
| b69ab31 | | | 315 | setShowingInput(true); |
| b69ab31 | | | 316 | |
| b69ab31 | | | 317 | // Start fetching options as soon as we show the typeahead |
| b69ab31 | | | 318 | getStableLocationsTypeaheadOptions(); |
| b69ab31 | | | 319 | }}> |
| b69ab31 | | | 320 | <Icon icon="plus" /> |
| b69ab31 | | | 321 | <T>Add Stable Location</T> |
| b69ab31 | | | 322 | </Button> |
| b69ab31 | | | 323 | )} |
| b69ab31 | | | 324 | </div> |
| b69ab31 | | | 325 | ); |
| b69ab31 | | | 326 | } |
| b69ab31 | | | 327 | |
| b69ab31 | | | 328 | export function Section({ |
| b69ab31 | | | 329 | title, |
| b69ab31 | | | 330 | description, |
| b69ab31 | | | 331 | children, |
| b69ab31 | | | 332 | }: { |
| b69ab31 | | | 333 | title: ReactNode; |
| b69ab31 | | | 334 | description?: ReactNode; |
| b69ab31 | | | 335 | children: ReactNode; |
| b69ab31 | | | 336 | }) { |
| b69ab31 | | | 337 | return ( |
| b69ab31 | | | 338 | <Column xstyle={styles.bookmarkGroup}> |
| b69ab31 | | | 339 | <strong>{title}</strong> |
| b69ab31 | | | 340 | {description && <Subtle {...stylex.props(styles.description)}>{description}</Subtle>} |
| b69ab31 | | | 341 | {children} |
| b69ab31 | | | 342 | </Column> |
| b69ab31 | | | 343 | ); |
| b69ab31 | | | 344 | } |
| b69ab31 | | | 345 | |
| b69ab31 | | | 346 | function BookmarksList({ |
| b69ab31 | | | 347 | bookmarks, |
| b69ab31 | | | 348 | kind, |
| b69ab31 | | | 349 | }: { |
| b69ab31 | | | 350 | bookmarks: Array< |
| b69ab31 | | | 351 | | string |
| b69ab31 | | | 352 | | (StableInfo & {extra?: ReactNode; kind?: undefined}) |
| b69ab31 | | | 353 | | {kind: 'custom'; custom: ReactNode} |
| b69ab31 | | | 354 | >; |
| b69ab31 | | | 355 | kind: BookmarkKind; |
| b69ab31 | | | 356 | }) { |
| b69ab31 | | | 357 | const [bookmarksData, setBookmarksData] = useAtom(bookmarksDataStorage); |
| b69ab31 | | | 358 | const recommendedBookmarks = useAtomValue(recommendedBookmarksAtom); |
| b69ab31 | | | 359 | const recommendedBookmarksAvailable = useAtomValue(recommendedBookmarksAvailableAtom); |
| b69ab31 | | | 360 | const showWarningOnMaster = Internal.shouldCheckRebase?.() ?? false; |
| b69ab31 | | | 361 | const hiddenMasterFeatureAvailable = useAtomValue(hiddenMasterFeatureAvailableAtom); |
| b69ab31 | | | 362 | const shouldAutoHideMaster = useAtomValue(shouldHideMasterAtom); |
| b69ab31 | | | 363 | |
| b69ab31 | | | 364 | if (bookmarks.length == 0) { |
| b69ab31 | | | 365 | return null; |
| b69ab31 | | | 366 | } |
| b69ab31 | | | 367 | return ( |
| b69ab31 | | | 368 | <ScrollY maxSize={300}> |
| b69ab31 | | | 369 | <Column xstyle={styles.bookmarkGroup}> |
| b69ab31 | | | 370 | {bookmarks.map(bookmark => { |
| b69ab31 | | | 371 | if (typeof bookmark !== 'string' && bookmark.kind === 'custom') { |
| b69ab31 | | | 372 | return bookmark.custom; |
| b69ab31 | | | 373 | } |
| b69ab31 | | | 374 | const name = typeof bookmark === 'string' ? bookmark : bookmark.name; |
| b69ab31 | | | 375 | const extra = typeof bookmark === 'string' ? undefined : bookmark.extra; |
| b69ab31 | | | 376 | const enableRecommended = |
| b69ab31 | | | 377 | bookmarksData.useRecommendedBookmark && recommendedBookmarksAvailable; |
| b69ab31 | | | 378 | const isRecommended = recommendedBookmarks.has(name); |
| b69ab31 | | | 379 | const tooltipOverride = typeof bookmark === 'string' ? undefined : bookmark.info; |
| b69ab31 | | | 380 | const {icon, tooltip} = getBookmarkAddons( |
| b69ab31 | | | 381 | name, |
| b69ab31 | | | 382 | isRecommended, |
| b69ab31 | | | 383 | showWarningOnMaster, |
| b69ab31 | | | 384 | tooltipOverride, |
| b69ab31 | | | 385 | ); |
| b69ab31 | | | 386 | |
| b69ab31 | | | 387 | const disabled = |
| b69ab31 | | | 388 | kind === 'remote' && |
| b69ab31 | | | 389 | enableRecommended && |
| b69ab31 | | | 390 | !isRecommended && |
| b69ab31 | | | 391 | name !== REMOTE_MASTER_BOOKMARK; |
| b69ab31 | | | 392 | |
| b69ab31 | | | 393 | // For remote/master when hidden master feature is available, show 3-state dropdown |
| b69ab31 | | | 394 | if (name === REMOTE_MASTER_BOOKMARK && hiddenMasterFeatureAvailable) { |
| b69ab31 | | | 395 | const currentVisibility = bookmarksData.masterBookmarkVisibility ?? 'auto'; |
| b69ab31 | | | 396 | // Determine the label for "Auto" based on whether this repo would be auto-hidden |
| b69ab31 | | | 397 | const autoLabel = shouldAutoHideMaster ? t('Auto (hide)') : t('Auto (show)'); |
| b69ab31 | | | 398 | return ( |
| b69ab31 | | | 399 | <Row key={name} xstyle={styles.masterBookmarkRow}> |
| b69ab31 | | | 400 | <Bookmark fullLength kind={kind} tooltip={tooltip} icon={icon}> |
| b69ab31 | | | 401 | {name} |
| b69ab31 | | | 402 | </Bookmark> |
| b69ab31 | | | 403 | <Tooltip |
| b69ab31 | | | 404 | title={t( |
| b69ab31 | | | 405 | 'Control master branch visibility. "Auto" derives from the current repo checkout whether it should be shown or hidden.', |
| b69ab31 | | | 406 | )}> |
| b69ab31 | | | 407 | <Dropdown<{value: MasterBookmarkVisibility; name: string}> |
| b69ab31 | | | 408 | value={currentVisibility} |
| b69ab31 | | | 409 | xstyle={styles.masterBookmarkDropdown} |
| b69ab31 | | | 410 | options={[ |
| b69ab31 | | | 411 | {value: 'auto', name: autoLabel}, |
| b69ab31 | | | 412 | {value: 'show', name: t('Show')}, |
| b69ab31 | | | 413 | {value: 'hide', name: t('Hide')}, |
| b69ab31 | | | 414 | ]} |
| b69ab31 | | | 415 | onChange={(e: React.ChangeEvent<HTMLSelectElement>) => { |
| b69ab31 | | | 416 | const newVisibility = e.target.value as MasterBookmarkVisibility; |
| b69ab31 | | | 417 | setBookmarksData({ |
| b69ab31 | | | 418 | ...bookmarksData, |
| b69ab31 | | | 419 | masterBookmarkVisibility: newVisibility, |
| b69ab31 | | | 420 | }); |
| b69ab31 | | | 421 | }} |
| b69ab31 | | | 422 | /> |
| b69ab31 | | | 423 | </Tooltip> |
| b69ab31 | | | 424 | {extra} |
| b69ab31 | | | 425 | </Row> |
| b69ab31 | | | 426 | ); |
| b69ab31 | | | 427 | } |
| b69ab31 | | | 428 | |
| b69ab31 | | | 429 | return ( |
| b69ab31 | | | 430 | <Checkbox |
| b69ab31 | | | 431 | key={name} |
| b69ab31 | | | 432 | checked={!bookmarksData.hiddenRemoteBookmarks.includes(name)} |
| b69ab31 | | | 433 | disabled={disabled} |
| b69ab31 | | | 434 | onChange={checked => { |
| b69ab31 | | | 435 | let hiddenRemoteBookmarks = bookmarksData.hiddenRemoteBookmarks; |
| b69ab31 | | | 436 | |
| b69ab31 | | | 437 | if (!checked) { |
| b69ab31 | | | 438 | hiddenRemoteBookmarks = [...hiddenRemoteBookmarks, name]; |
| b69ab31 | | | 439 | } else { |
| b69ab31 | | | 440 | hiddenRemoteBookmarks = hiddenRemoteBookmarks.filter(b => b !== name); |
| b69ab31 | | | 441 | } |
| b69ab31 | | | 442 | |
| b69ab31 | | | 443 | setBookmarksData({...bookmarksData, hiddenRemoteBookmarks}); |
| b69ab31 | | | 444 | }}> |
| b69ab31 | | | 445 | <Bookmark fullLength key={name} kind={kind} tooltip={tooltip} icon={icon}> |
| b69ab31 | | | 446 | {name} |
| b69ab31 | | | 447 | </Bookmark> |
| b69ab31 | | | 448 | {extra} |
| b69ab31 | | | 449 | </Checkbox> |
| b69ab31 | | | 450 | ); |
| b69ab31 | | | 451 | })} |
| b69ab31 | | | 452 | </Column> |
| b69ab31 | | | 453 | </ScrollY> |
| b69ab31 | | | 454 | ); |
| b69ab31 | | | 455 | } |