Skip to content

Commit

Permalink
fix(code-editor): minor ux issues (#11598)
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy committed Mar 16, 2022
1 parent 9d1d8fd commit bcaefe5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion modules/code-editor/src/backend/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const FileTypes: { [type: string]: FileDefinition } = {
shouldSyncToDisk: true
},
canDelete: file => {
return !file.name.endsWith('.json')
return !['package.json', 'package-lock.json'].includes(file.name)
}
},
main_config: {
Expand Down
22 changes: 10 additions & 12 deletions modules/code-editor/src/views/full/components/NewFileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ const NewFileModal: FC<Props> = props => {
e.preventDefault()

const finalName = name.endsWith('.js') || name.endsWith('.json') ? name : `${name}.js`

let content
switch (props.selectedType) {
case 'action_legacy':
content = legacyAction
break
case 'action_http':
content = httpAction
break
default:
content = ' '
break
const isJson = finalName.endsWith('.json')
const isJs = finalName.endsWith('.js')

let content = ' '
if (props.selectedType === 'action_legacy' && isJs) {
content = legacyAction
} else if (props.selectedType === 'action_http' && isJs) {
content = httpAction
} else if (isJson) {
content = '{\n\t\n}'
}

await props.openFile({
Expand Down
18 changes: 13 additions & 5 deletions modules/code-editor/src/views/full/utils/wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path'

import { EditableFile } from '../../../backend/typings'
import { HOOK_SIGNATURES } from '../../../typings/hooks'

Expand All @@ -12,13 +14,14 @@ const ACTION_LEGACY_SIGNATURE =

const wrapper = {
add: (file: EditableFile, content: string) => {
const { type, hookType, botId } = file
const { type, hookType, name } = file
const isJs = path.extname(name) === '.js'

if (type === 'action_legacy') {
if (type === 'action_legacy' && isJs) {
return `${ACTION_LEGACY_SIGNATURE} {\n ${START_COMMENT}\n\n${content}\n\n ${END_COMMENT}\n}`
} else if (type === 'action_http') {
} else if (type === 'action_http' && isJs) {
return `${ACTION_HTTP_SIGNATURE} {\n ${START_COMMENT}\n\n${content}\n\n ${END_COMMENT}\n}`
} else if (type === 'hook' && HOOK_SIGNATURES[hookType]) {
} else if (type === 'hook' && HOOK_SIGNATURES[hookType] && isJs) {
let signature = HOOK_SIGNATURES[hookType]
if (signature.includes('\n')) {
signature = `${signature.substring(0, signature.length - 1)}\n)`
Expand Down Expand Up @@ -98,9 +101,14 @@ const getContentZone = (lines: string[]) => {
startLine += 2
}

const endLine = findLastIndex(lines, x => x.includes(END_COMMENT))
let endLine = findLastIndex(lines, x => x.includes(END_COMMENT))
const noContent = startLine > endLine

// Fix for files which doesn't have wrappers
if (endLine === -1) {
endLine = lines.length
}

return { startLine, endLine, noContent }
}

Expand Down

0 comments on commit bcaefe5

Please sign in to comment.