Skip to content

Commit 8ee005b

Browse files
committed
BUGFIX: Reevaluate command query when changed instead of selecting option
Previously it was not possible to adjust the search via keyboard after a command query had been updated and the results were already displayed. Now when changing the query, a dirty state is set in the UI and „Enter“ will start a new query.
1 parent 249d6c5 commit 8ee005b

File tree

8 files changed

+35
-7
lines changed

8 files changed

+35
-7
lines changed

packages/commandbar/src/Theme.module.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@
2828
--textOnGray: #fff;
2929
--textOnWhite: #252525;
3030
--primaryBlue: #00adee;
31+
--success: #00a338;
32+
--warn: #ff8700;
3133
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
3+
export function IconRepeat() {
4+
return (
5+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
6+
<path
7+
fill="currentColor"
8+
d="M0 224c0 17.7 14.3 32 32 32s32-14.3 32-32c0-53 43-96 96-96H320v32c0 12.9 7.8 24.6 19.8 29.6s25.7 2.2 34.9-6.9l64-64c12.5-12.5 12.5-32.8 0-45.3l-64-64c-9.2-9.2-22.9-11.9-34.9-6.9S320 19.1 320 32V64H160C71.6 64 0 135.6 0 224zm512 64c0-17.7-14.3-32-32-32s-32 14.3-32 32c0 53-43 96-96 96H192V352c0-12.9-7.8-24.6-19.8-29.6s-25.7-2.2-34.9 6.9l-64 64c-12.5 12.5-12.5 32.8 0 45.3l64 64c9.2 9.2 22.9 11.9 34.9 6.9s19.8-16.6 19.8-29.6V448H352c88.4 0 160-71.6 160-160z"
9+
/>
10+
</svg>
11+
);
12+
}

packages/commandbar/src/components/Icons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export { IconNeos } from './IconNeos';
33
export { IconSpinner } from './IconSpinner';
44
export { IconStar } from './IconStar';
55
export { IconPlay } from './IconPlay';
6+
export { IconRepeat } from './IconRepeat';

packages/commandbar/src/components/SearchBox/SearchBox.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@
5454
.executeButton:hover svg {
5555
color: var(--primaryBlue);
5656
}
57+
58+
.commandQueryDirty {
59+
color: var(--warn);
60+
}

packages/commandbar/src/components/SearchBox/SearchBox.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { useSignalEffect } from '@preact/signals';
33

44
import { useCommandBarState, STATUS, useIntl, useCommandExecutor } from '../../state';
55
import IconWrapper from '../IconWrapper/IconWrapper';
6+
import { IconPlay, IconRepeat } from '../Icons';
67

78
import * as styles from './SearchBox.module.css';
8-
import { IconPlay } from '../Icons';
99

1010
// Timer helper for debouncing updates of command query results
1111
let updateResultsTimer = null;
@@ -96,15 +96,17 @@ const SearchBox: React.FC = () => {
9696
</button>
9797
)}
9898
{state.status.value === STATUS.DISPLAYING_RESULT &&
99-
state.commands.value[state.resultCommandId.value]?.executeManually && (
99+
state.commands.value[state.resultCommandId.value]?.executeManually &&
100+
!state.activeCommandId.value && (
100101
<button
101-
className={styles.executeButton}
102+
className={[
103+
styles.executeButton,
104+
state.commandQueryDirty.value ? styles.commandQueryDirty : '',
105+
].join(' ')}
102106
onClick={() => executeCommand(state.resultCommandId.value)}
103107
title={translate('SearchBox.execute.title', 'Execute the command')}
104108
>
105-
<IconWrapper>
106-
<IconPlay />
107-
</IconWrapper>
109+
<IconWrapper>{state.commandQueryDirty.value ? <IconPlay /> : <IconRepeat />}</IconWrapper>
108110
</button>
109111
)}
110112
</>

packages/commandbar/src/state/CommandBarExecutor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const CommandBarExecutor: React.FC<CommandInputContextProps> = ({ childre
6868
let commandId = state.availableCommandIds.value[state.highlightedItem.value];
6969
if (state.status.value === STATUS.DISPLAYING_RESULT) {
7070
// If there are options the command to execute is the highlighted option
71-
if (Object.values(state.result.value.options).length) {
71+
if (!state.commandQueryDirty.value && Object.values(state.result.value.options).length) {
7272
commandId = Object.keys(state.result.value.options)[state.highlightedOption.value];
7373
} else {
7474
// If there are no options we run the command which generated the result again

packages/commandbar/src/state/CommandBarStateProvider.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface CommandBarContextValues {
1919
activeCommandMessage: ReadonlySignal<string>;
2020
availableCommandIds: ReadonlySignal<CommandId[]>;
2121
commandQuery: ReadonlySignal<string>;
22+
commandQueryDirty: ReadonlySignal<boolean>;
2223
commands: ReadonlySignal<FlatCommandList>;
2324
expanded: ReadonlySignal<boolean>;
2425
favouriteCommands: ReadonlySignal<CommandId[]>;
@@ -56,6 +57,7 @@ function createAppState(initialState: CommandBarState) {
5657
const activeCommandMessage = computed(() => commandBarState.value.activeCommandMessage);
5758
const availableCommandIds = computed(() => commandBarState.value.availableCommandIds);
5859
const commandQuery = computed(() => commandBarState.value.commandQuery);
60+
const commandQueryDirty = computed(() => commandBarState.value.commandQueryDirty);
5961
const commands = computed(() => commandBarState.value.commands);
6062
const expanded = computed(() => commandBarState.value.expanded);
6163
const favouriteCommands = computed(() => commandBarState.value.favouriteCommands);
@@ -75,6 +77,7 @@ function createAppState(initialState: CommandBarState) {
7577
activeCommandMessage,
7678
availableCommandIds,
7779
commandQuery,
80+
commandQueryDirty,
7881
commands,
7982
expanded,
8083
favouriteCommands,
@@ -104,6 +107,7 @@ export const CommandBarStateProvider: React.FC<CommandBarContextProps> = ({
104107
activeCommandMessage: null,
105108
availableCommandIds: Object.keys(commands),
106109
commandQuery: '',
110+
commandQueryDirty: false,
107111
commands: flattenCommands(commands),
108112
expanded: false,
109113
favouriteCommands: userPreferences.favouriteCommands,

packages/commandbar/src/state/commandBarReducer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type CommandBarState = MachineState & {
2222
activeCommandMessage: string;
2323
availableCommandIds: CommandId[];
2424
commandQuery: string;
25+
commandQueryDirty: boolean;
2526
commands: FlatCommandList;
2627
expanded: boolean;
2728
favouriteCommands: CommandId[];
@@ -89,6 +90,7 @@ function runAction(action: ACTION, nextState: CommandBarState, event: CommandBar
8990
case ACTION.SET_COMMAND_QUERY:
9091
assert(event.type === TRANSITION.UPDATE_COMMAND_QUERY);
9192
nextState.commandQuery = event.commandQuery;
93+
nextState.commandQueryDirty = true;
9294
break;
9395
case ACTION.EXPAND:
9496
nextState.expanded = true;
@@ -113,6 +115,7 @@ function runAction(action: ACTION, nextState: CommandBarState, event: CommandBar
113115
...event.result,
114116
};
115117
nextState.resultCommandId = nextState.activeCommandId;
118+
nextState.commandQueryDirty = false;
116119
break;
117120
case ACTION.RESET_OPTION_HIGHLIGHT:
118121
nextState.highlightedOption = 0;

0 commit comments

Comments
 (0)