From 81423d2e663a08f88fac045ffeb6d32c5264f542 Mon Sep 17 00:00:00 2001 From: tidy-dev <75402236+tidy-dev@users.noreply.github.com> Date: Wed, 23 Aug 2023 10:47:49 -0400 Subject: [PATCH] Tidying --- app/src/ui/dropdown-select-button.tsx | 36 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/app/src/ui/dropdown-select-button.tsx b/app/src/ui/dropdown-select-button.tsx index f7c7ad2f31..2ae0a57a4e 100644 --- a/app/src/ui/dropdown-select-button.tsx +++ b/app/src/ui/dropdown-select-button.tsx @@ -4,7 +4,7 @@ import { Button } from './lib/button' import { Octicon } from './octicons' import * as OcticonSymbol from './octicons/octicons.generated' import { MenuPane } from './app-menu' -import { MenuItem } from '../models/app-menu' +import { ICheckboxMenuItem, MenuItem } from '../models/app-menu' import { ClickSource, SelectionSource } from './lib/list' export interface IDropdownSelectButtonOption { @@ -237,6 +237,27 @@ export class DropdownSelectButton extends React.Component< ) } + private getMenuItems( + options: ReadonlyArray, + checkedOptionId: string | undefined + ): ReadonlyArray { + const defaultCheckBoxMenuItem: ICheckboxMenuItem = { + type: 'checkbox', + id: '', + label: '', + checked: false, + enabled: true, + visible: true, + accelerator: null, + accessKey: null, + } + + return options.map(({ id, label }) => { + const checked = checkedOptionId === id + return { ...defaultCheckBoxMenuItem, ...{ id, label, checked } } + }) + } + private renderSplitButtonOptions() { const { showButtonOptions, @@ -244,23 +265,14 @@ export class DropdownSelectButton extends React.Component< selectedOption, optionsPositionBottom: bottom, } = this.state + if (!showButtonOptions) { return } const { options } = this.props - const items: ReadonlyArray = options.map(o => ({ - type: 'checkbox', - id: o.id, - enabled: true, - visible: true, - label: o.label, - accelerator: null, - accessKey: null, - checked: checkedOption?.id === o.id, - })) - + const items = this.getMenuItems(options, checkedOption?.id) const selectedItem = items.find(i => i.id === selectedOption?.id) const openClass = bottom !== undefined ? 'open-top' : 'open-bottom' const classes = classNames('dropdown-select-button-options', openClass)