Skip to content

Commit

Permalink
rework file path for scripts, useEffect dependency arrays and pass in…
Browse files Browse the repository at this point in the history
… prop to pass Editor test
  • Loading branch information
Jas Kuner committed Oct 9, 2020
1 parent 8a5cfd8 commit 20789b5
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 25,469 deletions.
25,406 changes: 0 additions & 25,406 deletions package-lock.json

This file was deleted.

8 changes: 6 additions & 2 deletions src/browser/modules/Editor/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface ActionButtonProps {
buttons: ActionButton[]
width?: number
editorValue: () => string
isRelateAvailable: boolean
}

interface ActionButton {
Expand All @@ -41,10 +42,13 @@ interface ActionButton {
const ActionButtons = ({
buttons,
width = 24,
editorValue
editorValue,
isRelateAvailable
}: ActionButtonProps): JSX.Element => (
<ActionButtonSection>
<ProjectFilesButton width={width} editorValue={editorValue} />
{isRelateAvailable && (
<ProjectFilesButton width={width} editorValue={editorValue} />
)}
{buttons.map((btn: ActionButton) => (
<EditorButton
data-testid={`editor-${btn.title.split(' ')[0]}`}
Expand Down
7 changes: 6 additions & 1 deletion src/browser/modules/Editor/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ export class Editor extends Component {
width={16}
buttons={buttons}
editorValue={() => this.getEditorValue()}
isRelateAvilable={this.props.isRelateAvilable}
/>
</Header>
<EditorWrapper fullscreen={isFullscreen} cardSize={isCardSize}>
Expand Down Expand Up @@ -566,7 +567,11 @@ const mapStateToProps = state => {
],
procedures: state.meta.procedures.map(schemaConvert.toProcedure)
},
enableMultiStatementMode: shouldEnableMultiStatementMode(state)
enableMultiStatementMode: shouldEnableMultiStatementMode(state),
isRelateAvilable:
state.app.relateUrl &&
state.app.relateApiToken &&
state.app.neo4jDesktopProjectId
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/browser/modules/Editor/EditorFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function EditorFrame({ bus }: EditorFrameProps): JSX.Element {
return () => {
isStillMounted = false
}
}, [])
}, [bus])

useEffect(() => {
let isStillMounted = true
Expand All @@ -189,7 +189,7 @@ export function EditorFrame({ bus }: EditorFrameProps): JSX.Element {
return () => {
isStillMounted = false
}
})
}, [bus, activeProjectFile])

function discardEditor() {
sizeState !== 'LINE' && setSize('LINE')
Expand Down
95 changes: 45 additions & 50 deletions src/browser/modules/Editor/ProjectFilesButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ const ProjectFileButton = ({
return () => {
isStillMounted = false
}
}, [])
}, [bus])

useEffect(() => {
// to report an error in the EditorFrame
bus && bus.send(PROJECT_FILE_ERROR, '')
}, [error])
}, [bus, error])

useEffect(() => {
// bus sends message too quickly before ProjectFiles is mounted,
Expand All @@ -137,63 +137,58 @@ const ProjectFileButton = ({
bus.send(SAVE_PROJECT_FILE, editorValue())
setSaveModeClick(false)
}
})
}, [bus, isSaveModeClick, isProjectFilesMounted])

if (!isRelateAvailable) return null

return (
<>
<EditorButton
data-testid={`editor-${PROJECT_EDITOR_BUTTON_TITLE.split(' ')[0]}`}
onClick={async () => {
if (editorValue().length) {
if (isEditMode && activeRelateFile) {
// edit mode
bus.send(EDIT_PROJECT_FILE_START, '') // display status in the EditorFrame
try {
const { data } = await addFile({
variables: {
projectId,
fileUpload: new File(
[editorValue()],
activeRelateFile.name
),
destination: isWindows
? `${activeRelateFile.directory}\\${activeRelateFile.name}`
: `${activeRelateFile.directory}/${activeRelateFile.name}`,
overwrite: true
}
})
const addedFile = {
name: data.addProjectFile.name,
directory: data.addProjectFile.directory,
extension: data.addProjectFile.extension
<EditorButton
data-testid={`editor-${PROJECT_EDITOR_BUTTON_TITLE.split(' ')[0]}`}
onClick={async () => {
if (editorValue().length) {
if (isEditMode && activeRelateFile) {
// edit mode
bus.send(EDIT_PROJECT_FILE_START, '') // display status in the EditorFrame
try {
const { data } = await addFile({
variables: {
projectId,
fileUpload: new File([editorValue()], activeRelateFile.name),
destination: isWindows
? `${activeRelateFile.directory}\\${activeRelateFile.name}`
: `${activeRelateFile.directory}/${activeRelateFile.name}`,
overwrite: true
}
setActiveRelateFile(addedFile)
setEditMode(true)
bus.send(EDIT_PROJECT_FILE_END, '')
} catch (e) {
console.log(e)
})
const addedFile = {
name: data.addProjectFile.name,
directory: data.addProjectFile.directory,
extension: data.addProjectFile.extension
}
} else {
// save mode
if (!isDrawerOpen) {
toggleDrawer()
}
setSaveModeClick(true)
setActiveRelateFile(addedFile)
setEditMode(true)
bus.send(EDIT_PROJECT_FILE_END, '')
} catch (e) {
console.log(e)
}
} else {
// save mode
if (!isDrawerOpen) {
toggleDrawer()
}
setSaveModeClick(true)
}
}}
title={
isEditMode && activeRelateFile
? PROJECT_EDIT_EDITOR_BUTTON_TITLE
: PROJECT_SAVE_EDITOR_BUTTON_TITLE
}
icon={floppyDisk}
key={`editor${PROJECT_EDITOR_BUTTON_TITLE}`}
width={width}
/>
</>
}}
title={
isEditMode && activeRelateFile
? PROJECT_EDIT_EDITOR_BUTTON_TITLE
: PROJECT_SAVE_EDITOR_BUTTON_TITLE
}
icon={floppyDisk}
key={`editor${PROJECT_EDITOR_BUTTON_TITLE}`}
width={width}
/>
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/browser/modules/Sidebar/ProjectFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ const ProjectFiles = ({ bus, projectId }: ProjectFiles) => {
return () => {
isStillMounted = false
}
}, [])
}, [bus])

useEffect(() => {
// send mounted/unmounted message
bus && bus.send(PROJECT_FILES_MOUNTED, '')
return () => bus && bus.send(PROJECT_FILES_UNMOUNTED, '')
}, [])
}, [bus])

return (
<Drawer id="db-project-files">
Expand Down
9 changes: 6 additions & 3 deletions src/browser/modules/Sidebar/ProjectsFilesScripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { filter, size, omit } from 'lodash-es'

import * as editor from 'shared/modules/editor/editorDuck'
import { executeCommand } from 'shared/modules/commands/commandsDuck'
import { SLASH, CYPHER_FILE_EXTENSION } from 'shared/services/export-favorites'
import { CYPHER_FILE_EXTENSION, DOT } from 'shared/services/export-favorites'
import {
ProjectFilesQueryVars,
ProjectFileMutationVars,
Expand Down Expand Up @@ -166,10 +166,13 @@ function ProjectFilesScripts(props: ProjectFilesScripts): JSX.Element {
]),
scripts: projectFiles,
isProjectFiles: true,
scriptsNamespace: SLASH,
scriptsNamespace: DOT,
title: 'Project Files',
onRemoveScript: async (favorite: Favorite) => {
const directory = favorite.path.substring(1) // remove SLASH from path
const directory =
favorite.path.length == 1 && favorite.path === DOT
? DOT
: favorite.path.substring(1) // remove DOT from path
const filePath = isWindows
? `${directory}\\${favorite.name}`
: `${directory}/${favorite.name}`
Expand Down
4 changes: 2 additions & 2 deletions src/browser/modules/Sidebar/project-files.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/
import remote from 'services/remote'
import { SLASH, CYPHER_FILE_EXTENSION } from 'shared/services/export-favorites'
import { CYPHER_FILE_EXTENSION, DOT } from 'shared/services/export-favorites'
import uuid from 'uuid'
import { split, trim, head, startsWith } from 'lodash-es'
import {
Expand Down Expand Up @@ -61,7 +61,7 @@ export const mapProjectFileToFavorites = async ({
id: uuid.v4(),
name,
directory,
path: directory.startsWith('.') ? SLASH : `${SLASH}${directory}`, // add SLASH to show files/folders
path: directory.startsWith(DOT) ? directory : `${DOT}${directory}`, // works with scriptsNamespace
contents: await getProjectFileContents(
downloadToken,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export const SLASH = '/'
export const NEW_LINE = '\n'
export const COMMENT_PREFIX = '//'
export const CYPHER_FILE_EXTENSION = '.cypher'
export const DOT = '.'
2 changes: 1 addition & 1 deletion src/shared/services/export-favorites/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export {
exportFavorites,
mapOldFavoritesAndFolders
} from './export-favorites.utils'
export { SLASH, CYPHER_FILE_EXTENSION } from './export-favorites.constants'
export { SLASH, CYPHER_FILE_EXTENSION, DOT } from './export-favorites.constants'

0 comments on commit 20789b5

Please sign in to comment.