Skip to content

Commit

Permalink
feat(commands): add activate()
Browse files Browse the repository at this point in the history
update command-react tests

needing to do `app.states.enableMapSet()` during jest and storybook seems complicated.
Need to see if it can be improved.
  • Loading branch information
unional committed Mar 28, 2022
1 parent 043ed29 commit 3ea3e10
Show file tree
Hide file tree
Showing 22 changed files with 148 additions and 648 deletions.
2 changes: 1 addition & 1 deletion common/config/rush/browser-approved-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
{
"name": "@just-web/app",
"allowedCategories": [ "production" ]
"allowedCategories": [ "libraries", "production" ]
},
{
"name": "@just-web/command",
Expand Down
11 changes: 9 additions & 2 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion components/command-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"storybook": "start-storybook -p 6006 -s public",
"test": "react-app-rewired test --watchAll=false",
"test:visual": "cross-env VISUAL_TEST=1 react-app-rewired test --watchAll=false",
"test:watch": "react-scripts test",
"test:watch": "react-app-rewired test",
"verify": "run-p build lint depcheck test",
"verify:build": "run-s clean build",
"verify:test": "run-s test test:visual"
Expand All @@ -39,6 +39,7 @@
"react-scripts/**/eslint-config-react-app": "7.0.0"
},
"dependencies": {
"@just-web/app": "workspace:*",
"@just-web/commands": "workspace:*",
"@just-web/platform": "workspace:*",
"react": "~17.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import app from '@just-web/app'
import { Command, KeyBinding, registerCommand } from '@just-web/commands'
import { FC } from 'react'
import { stub } from 'type-plus'
import CommandPalette, { CommandPaletteProps } from './CommandPalette'

app.states.enableMapSet()

export default {
component: CommandPalette
}
Expand All @@ -20,15 +23,15 @@ const simpleCmd = cmd({ id: 'core.simpleCommand', description: 'Simple command'
registerCommand(simpleCmd.id, simpleCmd)

const keyCmd = cmd({
description: 'Simple command',
id: 'core.simpleCommand',
description: 'Command with key',
id: 'core.keyedCommand',
key: 'ctrl+s'
})
registerCommand(keyCmd.id, keyCmd)

const macCmd = cmd({
description: 'Simple command',
id: 'core.simpleCommand',
description: 'Command with mac key override',
id: 'core.macCommand',
key: 'ctrl+s',
mac: 'cmd+s'
})
Expand All @@ -38,12 +41,12 @@ export const NoCommand = () => <Story commands={[]} />

export const OneCommand = () => <Story commands={[simpleCmd]} />

export const WithOneKey = () => <Story commands={[keyCmd, keyCmd, keyCmd]} />
export const WithKey = () => <Story commands={[keyCmd]} />

export const WithOverrideKeyInMac = () => <Story
commands={[macCmd, macCmd, macCmd]}
export const OverrideMacCommandInMac = () => <Story
commands={[keyCmd, macCmd]}
ctx={{ isMacOS: () => true }} />

export const WithoutOverrideKeyInMac = () => <Story
commands={[keyCmd, keyCmd]}
ctx={{ isMacOS: () => true }} />
export const OverrideMacCommandInWindow = () => <Story
commands={[keyCmd, macCmd]}
ctx={{ isMacOS: () => false }} />
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface CommandPaletteProps {
function toPaletteCommands(cmds: CommandPaletteProps['commands'], ctx: CommandPaletteCtx) {
const m = ctx.isMacOS()
return cmds.map(c => ({
name: c.id,
name: c.description,
key: m ? c.mac ?? c.key : c.key,
command: () => invokeCommand(c.id)
}))
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3ea3e10

Please sign in to comment.