-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Add keyboard shortcuts for quick actions in data browser #3073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4ff7448
feat
mtrezza d987a98
feat
mtrezza af068c0
setting
mtrezza 788d126
fix
mtrezza c0c573b
style
mtrezza dfb2846
style
mtrezza f741e87
Update README.md
mtrezza 9c4f919
review fixes
mtrezza 779fb99
Update KeyboardShortcutsSettings.react.js
mtrezza cd8a88d
fix
mtrezza da42fb1
fix
mtrezza 5568991
fix
mtrezza 246bfbb
Merge branch 'alpha' into feat/keybinding
mtrezza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
234 changes: 234 additions & 0 deletions
234
src/dashboard/Settings/KeyboardShortcutsSettings.react.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| /* | ||
| * Copyright (c) 2016-present, Parse, LLC | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the license found in the LICENSE file in | ||
| * the root directory of this source tree. | ||
| */ | ||
| import DashboardView from 'dashboard/DashboardView.react'; | ||
| import Field from 'components/Field/Field.react'; | ||
| import Fieldset from 'components/Fieldset/Fieldset.react'; | ||
| import FormButton from 'components/FormButton/FormButton.react'; | ||
| import Label from 'components/Label/Label.react'; | ||
| import React from 'react'; | ||
| import TextInput from 'components/TextInput/TextInput.react'; | ||
| import Toolbar from 'components/Toolbar/Toolbar.react'; | ||
| import Notification from 'dashboard/Data/Browser/Notification.react'; | ||
| import styles from 'dashboard/Settings/Settings.scss'; | ||
| import KeyboardShortcutsManager, { DEFAULT_SHORTCUTS, isValidShortcut, createShortcut } from 'lib/KeyboardShortcutsPreferences'; | ||
|
|
||
| export default class KeyboardShortcutsSettings extends DashboardView { | ||
| constructor() { | ||
| super(); | ||
| this.section = 'App Settings'; | ||
| this.subsection = 'Keyboard Shortcuts'; | ||
|
|
||
| this.state = { | ||
| dataBrowserReloadData: '', | ||
| dataBrowserToggleInfoPanels: '', | ||
| hasChanges: false, | ||
| message: null, | ||
| loading: true, | ||
| }; | ||
|
|
||
| this.manager = null; | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| if (this.context) { | ||
| this.manager = new KeyboardShortcutsManager(this.context); | ||
| this.loadShortcuts(); | ||
| } | ||
| } | ||
|
|
||
| async loadShortcuts() { | ||
| if (!this.context || !this.manager) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const shortcuts = await this.manager.getKeyboardShortcuts(this.context.applicationId); | ||
| this.setState({ | ||
| dataBrowserReloadData: shortcuts.dataBrowserReloadData?.key || '', | ||
| dataBrowserToggleInfoPanels: shortcuts.dataBrowserToggleInfoPanels?.key || '', | ||
| hasChanges: false, | ||
| loading: false, | ||
| }); | ||
| } catch (error) { | ||
| console.error('Failed to load keyboard shortcuts:', error); | ||
| this.showNote('Failed to load keyboard shortcuts', true); | ||
| this.setState({ loading: false }); | ||
| } | ||
| } | ||
|
|
||
| handleFieldChange(field, value) { | ||
| this.setState({ | ||
| [field]: value, | ||
| hasChanges: true, | ||
| }); | ||
| } | ||
|
|
||
| handleInputFocus(event) { | ||
| // Auto-select the text when focusing on the input | ||
| if (event.target.value) { | ||
| event.target.select(); | ||
| } | ||
| } | ||
|
|
||
| async handleSave() { | ||
| if (!this.context || !this.manager) { | ||
| return; | ||
| } | ||
|
|
||
| // Create shortcut objects from the key strings | ||
| const shortcuts = { | ||
| dataBrowserReloadData: this.state.dataBrowserReloadData ? createShortcut(this.state.dataBrowserReloadData) : null, | ||
| dataBrowserToggleInfoPanels: this.state.dataBrowserToggleInfoPanels ? createShortcut(this.state.dataBrowserToggleInfoPanels) : null, | ||
| }; | ||
|
|
||
| // Validate shortcuts (only if they are set) | ||
| if (shortcuts.dataBrowserReloadData && !isValidShortcut(shortcuts.dataBrowserReloadData)) { | ||
| this.showNote('Invalid key for "Reload Data". Please enter a valid key.', true); | ||
| return; | ||
| } | ||
|
|
||
| if (shortcuts.dataBrowserToggleInfoPanels && !isValidShortcut(shortcuts.dataBrowserToggleInfoPanels)) { | ||
| this.showNote('Invalid key for "Toggle Panels". Please enter a valid key.', true); | ||
| return; | ||
| } | ||
|
|
||
| // Check for duplicates (only if both are set) | ||
| if (shortcuts.dataBrowserReloadData && shortcuts.dataBrowserToggleInfoPanels && | ||
| shortcuts.dataBrowserReloadData.key.toLowerCase() === shortcuts.dataBrowserToggleInfoPanels.key.toLowerCase()) { | ||
| this.showNote('Keyboard shortcuts must be unique. Please use different keys.', true); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await this.manager.saveKeyboardShortcuts(this.context.applicationId, shortcuts); | ||
| this.setState({ hasChanges: false }); | ||
| this.showNote('Keyboard shortcuts saved successfully!', false); | ||
| } catch (error) { | ||
| console.error('Failed to save keyboard shortcuts:', error); | ||
| this.showNote('Failed to save keyboard shortcuts. Please try again.', true); | ||
| } | ||
| } | ||
|
|
||
| async handleReset() { | ||
| if (!this.context || !this.manager) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await this.manager.resetKeyboardShortcuts(this.context.applicationId); | ||
| await this.loadShortcuts(); | ||
| this.showNote('Keyboard shortcuts reset to defaults', false); | ||
| } catch (error) { | ||
| console.error('Failed to reset keyboard shortcuts:', error); | ||
| this.showNote('Failed to reset keyboard shortcuts. Please try again.', true); | ||
| } | ||
| } | ||
|
|
||
| showNote(message, isError = false) { | ||
| if (!message) { | ||
| return; | ||
| } | ||
|
|
||
| clearTimeout(this.noteTimeout); | ||
|
|
||
| this.setState({ message: { text: message, isError } }); | ||
|
|
||
| this.noteTimeout = setTimeout(() => { | ||
| this.setState({ message: null }); | ||
| }, 3500); | ||
| } | ||
|
|
||
| renderContent() { | ||
| if (this.state.loading) { | ||
| return ( | ||
| <div> | ||
| <Toolbar section="Settings" subsection="Keyboard Shortcuts" /> | ||
| <div className={styles.settings_page}> | ||
| <div>Loading keyboard shortcuts...</div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (this.manager && !this.manager.isServerConfigEnabled()) { | ||
| return ( | ||
| <div> | ||
| <Toolbar section="Settings" subsection="Keyboard Shortcuts" /> | ||
| <div className={styles.settings_page}> | ||
| <Notification | ||
| note="Server configuration is not enabled for this app. Please add a 'config' section to your app configuration to use keyboard shortcuts." | ||
| isErrorNote={true} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <Toolbar section="Settings" subsection="Keyboard Shortcuts" /> | ||
| <Notification note={this.state.message?.text} isErrorNote={this.state.message?.isError} /> | ||
| <div className={styles.settings_page}> | ||
| <Fieldset | ||
| legend="Data Browser" | ||
| description="Leave empty to disable a shortcut." | ||
| > | ||
| <Field | ||
| labelWidth={62} | ||
| label={<Label | ||
| text="Reload Data" | ||
| description={'Reloads the data browser table data.'} | ||
| /> | ||
| } | ||
| input={ | ||
| <TextInput | ||
| placeholder={DEFAULT_SHORTCUTS.dataBrowserReloadData.key} | ||
| value={this.state.dataBrowserReloadData} | ||
| onChange={this.handleFieldChange.bind(this, 'dataBrowserReloadData')} | ||
| onFocus={this.handleInputFocus.bind(this)} | ||
| maxLength={1} | ||
| /> | ||
| } | ||
| /> | ||
| <Field | ||
| labelWidth={62} | ||
| label={ | ||
| <Label | ||
| text="Toggle Info Panels" | ||
| description={'Shows/hides the info panels.'} | ||
| /> | ||
| } | ||
| input={ | ||
| <TextInput | ||
| placeholder={DEFAULT_SHORTCUTS.dataBrowserToggleInfoPanels.key} | ||
| value={this.state.dataBrowserToggleInfoPanels} | ||
| onChange={this.handleFieldChange.bind(this, 'dataBrowserToggleInfoPanels')} | ||
| onFocus={this.handleInputFocus.bind(this)} | ||
| maxLength={1} | ||
| /> | ||
| } | ||
| /> | ||
| </Fieldset> | ||
|
|
||
| <div className={styles.form_buttons}> | ||
| <FormButton | ||
| value="Save Shortcuts" | ||
| disabled={!this.state.hasChanges} | ||
| onClick={this.handleSave.bind(this)} | ||
| /> | ||
| <FormButton | ||
| value="Reset to Defaults" | ||
| onClick={this.handleReset.bind(this)} | ||
| color="white" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.