File tree Expand file tree Collapse file tree
apps/sim/app/workspace/[workspaceId] Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,6 +168,25 @@ describe('selection-aware resource context menus', () => {
168168 expect(menu).toContain('Delete 25 items')
169169 })
170170
171+ it('does not overstate an unknown select-all toggle count', () => {
172+ const menu = renderToStaticMarkup(
173+ <DocumentContextMenu
174+ isOpen
175+ position={POSITION}
176+ onClose={() => {}}
177+ hasDocument
178+ selectedCount={25}
179+ enabledCount={25}
180+ disabledCount={25}
181+ hasExactToggleCount={false}
182+ onToggleEnabled={() => {}}
183+ />
184+ )
185+
186+ expect(menu).toContain('Enable selected items')
187+ expect(menu).not.toContain('Enable 25 items')
188+ })
189+
171190 it('counts only the chunks affected by a multi-selection toggle', () => {
172191 const menu = renderToStaticMarkup(
173192 <ChunkContextMenu
Original file line number Diff line number Diff line change @@ -43,4 +43,16 @@ describe('selection labels', () => {
4343 })
4444 ).toBe('Disable 4 items')
4545 })
46+
47+ it('keeps the action selection-aware when the affected subset count is unknown', () => {
48+ expect(
49+ selectionToggleActionLabel({
50+ selectedCount: 10,
51+ enabledCount: 10,
52+ disabledCount: 10,
53+ isSelectedItemEnabled: true,
54+ hasExactAffectedCount: false,
55+ })
56+ ).toBe('Enable selected items')
57+ })
4658})
Original file line number Diff line number Diff line change @@ -22,15 +22,18 @@ interface SelectionToggleActionLabelOptions {
2222 enabledCount: number
2323 disabledCount: number
2424 isSelectedItemEnabled: boolean
25+ hasExactAffectedCount?: boolean
2526}
2627
2728export function selectionToggleActionLabel({
2829 selectedCount,
2930 enabledCount,
3031 disabledCount,
3132 isSelectedItemEnabled,
33+ hasExactAffectedCount = true,
3234}: SelectionToggleActionLabelOptions): string {
3335 if (selectedCount <= 1) return isSelectedItemEnabled ? 'Disable' : 'Enable'
34- if (disabledCount > 0) return selectionActionLabel('Enable', disabledCount)
35- return selectionActionLabel('Disable', enabledCount)
36+ const action = disabledCount > 0 ? 'Enable' : 'Disable'
37+ if (!hasExactAffectedCount) return `${action} selected items`
38+ return selectionActionLabel(action, disabledCount > 0 ? disabledCount : enabledCount)
3639}
Original file line number Diff line number Diff line change @@ -1505,6 +1505,7 @@ export function KnowledgeBase({
15051505 selectedCount={selectedDocumentCount}
15061506 enabledCount={enabledCount}
15071507 disabledCount={disabledCount}
1508+ hasExactToggleCount={!isSelectAllMode || enabledFilter !== 'all'}
15081509 onOpenInNewTab={
15091510 contextMenuDocument && selectedDocumentCount === 1
15101511 ? () => {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ interface DocumentContextMenuProps {
3333 selectedCount: number
3434 enabledCount?: number
3535 disabledCount?: number
36+ hasExactToggleCount?: boolean
3637}
3738
3839/**
@@ -60,13 +61,15 @@ export function DocumentContextMenu({
6061 selectedCount,
6162 enabledCount = 0,
6263 disabledCount = 0,
64+ hasExactToggleCount = true,
6365}: DocumentContextMenuProps) {
6466 const isMultiSelect = selectedCount > 1
6567 const toggleLabel = selectionToggleActionLabel({
6668 selectedCount,
6769 enabledCount,
6870 disabledCount,
6971 isSelectedItemEnabled: isDocumentEnabled,
72+ hasExactAffectedCount: hasExactToggleCount,
7073 })
7174
7275 const hasNavigationSection = !isMultiSelect && (!!onOpenInNewTab || !!onOpenSource)
You can’t perform that action at this time.
0 commit comments