fix(unify): null binary field on editor blocks launchpad from opening (#20920)

This commit is contained in:
David Munechika
2022-04-11 12:32:51 -04:00
committed by GitHub
parent 7a993d2597
commit 1d3e2f758f
7 changed files with 28 additions and 7 deletions

View File

@@ -249,6 +249,10 @@ describe('App: Settings', () => {
binary: '/usr/bin/well-known',
name: 'Well known editor',
},
{
id: 'null-binary-editor',
name: 'Null binary editor',
},
]
ctx.coreData.localSettings.preferences.preferredEditorBinary = undefined
@@ -306,6 +310,23 @@ describe('App: Settings', () => {
cy.get('[data-cy="custom-editor"]').should('not.exist')
})
it('handles null binary field in editor', () => {
cy.contains('Choose your editor...').click()
cy.contains('Null binary editor').click()
cy.withRetryableCtx((ctx) => {
expect((ctx.actions.localSettings.setPreferences as SinonStub).lastCall.lastArg).to.include('{"preferredEditorBinary":null')
})
// navigate away and come back
// preferred editor selected from dropdown should have been persisted
cy.visitApp()
cy.get('[href="#/settings"]').click()
cy.wait(200)
cy.get('[data-cy="Device Settings"]').click()
cy.get('[data-cy="custom-editor"]').should('not.exist')
})
})
})

View File

@@ -35,7 +35,7 @@ const { t } = useI18n()
const setPreferredBinaryEditor = useMutation(ExternalEditorSettings_SetPreferredEditorBinaryDocument)
function handleChoseEditor (binary: string) {
function handleChoseEditor (binary: string | null) {
setPreferredBinaryEditor.executeMutation({ value: JSON.stringify({ preferredEditorBinary: binary }) })
}

View File

@@ -126,7 +126,7 @@ type Editor = ChooseExternalEditorFragment['localSettings']['availableEditors'][
type EditorType = 'found' | 'custom'
const selectedWellKnownEditor: Editor | undefined = props.gql.localSettings.availableEditors.find((editor) => {
return editor.binary === props.gql.localSettings.preferences.preferredEditorBinary
return editor.binary && editor.binary === props.gql.localSettings.preferences.preferredEditorBinary
})
const customBinary = ref<string>(
@@ -144,7 +144,7 @@ const selectedEditor = ref<Editor | undefined>(
)
const emit = defineEmits<{
(e: 'choseEditor', binary: string): void
(e: 'choseEditor', binary: string | null): void
}>()
watch(customBinary, (val) => {

View File

@@ -36,7 +36,7 @@
>
<ChooseExternalEditor
:gql="props.gql"
@chose-editor="val => preferredEditor = val"
@chose-editor="val => preferredEditor = val ?? ''"
/>
</div>

View File

@@ -467,7 +467,7 @@ type DevState {
"""Represents an editor on the local machine"""
type Editor {
"""Binary that opens the editor"""
binary: String!
binary: String
id: String!
"""name of editor"""

View File

@@ -10,7 +10,7 @@ export const Editor = objectType({
description: 'name of editor',
})
t.nonNull.string('binary', {
t.string('binary', {
description: 'Binary that opens the editor',
})
},

View File

@@ -1,6 +1,6 @@
export interface Editor {
id: string
binary: string
binary?: string | null | undefined
name: string
}