-
Notifications
You must be signed in to change notification settings - Fork 351
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
Import/export saved favorites #964
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b4a57e0
added needed dependencies, allowed symlinked packages in webpack, upd…
huboneo 9a7d60d
Migrated part of #951
huboneo e8a2751
Allow static scripts
huboneo e6f679c
bugfix update folder name clears all folders
huboneo 18a3218
added unit tests
huboneo 480a8a3
Import favorite logic for updating state
huboneo fbc3740
Merge branch 'master' into feature-export-favorites
huboneo 5dc7e2a
Fixed broken tests and updated saved-scripts version
huboneo 53df189
Merge branch 'master' into feature-export-favorites
huboneo 7b43b83
bugfix filedrop
huboneo eec4f61
bugfix duplicate cmd chars
huboneo 17afbe4
Bugfixes for IE
huboneo f849b95
webpack fixes for lambda parser
huboneo 627e478
bugfix webpack PNG loading
huboneo 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 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 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 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 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 |
---|---|---|
|
@@ -124,26 +124,30 @@ | |
}, | ||
"dependencies": { | ||
"@neo4j/browser-lambda-parser": "^1.0.3", | ||
"@relate-by-ui/css": "^1.0.4", | ||
"@relate-by-ui/saved-scripts": "^1.0.3", | ||
"ascii-data-table": "^2.1.1", | ||
"classnames": "^2.2.5", | ||
"codemirror": "^5.29.0", | ||
"core-js": "3", | ||
"cypher-codemirror": "1.1.5", | ||
"d3": "3", | ||
"dateformat": "^3.0.3", | ||
"deepmerge": "^2.1.1", | ||
"dnd-core": "^2.5.1", | ||
"dompurify": "^1.0.11", | ||
"file-saver": "^1.3.8", | ||
"firebase": "^5.8.3", | ||
"isomorphic-fetch": "^2.2.1", | ||
"jsonic": "^0.3.0", | ||
"jszip": "^3.2.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to verify that this works in IE 11. |
||
"lodash-es": "^4.17.15", | ||
"mockdate": "^2.0.5", | ||
"neo4j-driver": "^1.7.5", | ||
"react": "^16.9.0", | ||
"react-addons-pure-render-mixin": "^15.0.2", | ||
"react-dnd": "^2.5.1", | ||
"react-dnd-html5-backend": "^2.5.1", | ||
"react-dnd": "9.3.2", | ||
"react-dnd-html5-backend": "9.3.2", | ||
"react-dom": "^16.8.1", | ||
"react-icons": "^2.2.1", | ||
"react-redux": "^5.0.7", | ||
|
@@ -155,6 +159,7 @@ | |
"regenerator-runtime": "^0.13.2", | ||
"rxjs": "^5.4.2", | ||
"save-as": "^0.1.7", | ||
"semantic-ui-react": "^0.88.0", | ||
"semver": "^5.5.0", | ||
"styled-components": "^4.0.0", | ||
"stylis": "^3.4.10", | ||
|
This file contains 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 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,129 @@ | ||
/* | ||
* Copyright (c) 2002-2019 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* This file is part of Neo4j. | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
import { | ||
assign, | ||
compact, | ||
endsWith, | ||
filter, | ||
flatMap, | ||
includes, | ||
join, | ||
keyBy, | ||
map, | ||
reverse, | ||
split, | ||
startsWith, | ||
tail, | ||
values | ||
} from 'lodash-es' | ||
import JSZip from 'jszip' | ||
import uuid from 'uuid' | ||
|
||
import { CYPHER_FILE_EXTENSION } from 'shared/services/export-favorites' | ||
|
||
/** | ||
* Extracts folders from favorites | ||
* @param {Object[]} favorites | ||
* @return {string[]} | ||
*/ | ||
export function getFolderNamesFromFavorites (favorites) { | ||
return compact(map(favorites, 'folderName')) | ||
} | ||
|
||
/** | ||
* Returns new folder objects for those who do not have a matching name | ||
* @param {string[]} folderNames | ||
* @param {Object[]} allFolders | ||
* @return {Object[]} | ||
*/ | ||
export function getMissingFoldersFromNames (folderNames, allFolders) { | ||
const existingNames = map(allFolders, 'name') | ||
|
||
return map( | ||
filter(folderNames, folderName => !includes(existingNames, folderName)), | ||
name => ({ | ||
name, | ||
id: uuid.v4() | ||
}) | ||
) | ||
} | ||
|
||
/** | ||
* Creates a LOAD_FAVORITES payload complete with folder IDs when applicable | ||
* @param {Object[]} favoritesToAdd | ||
* @param {Object[]} allFolders | ||
* @return {Object[]} | ||
*/ | ||
export function createLoadFavoritesPayload (favoritesToAdd, allFolders) { | ||
const allFavoriteFolders = keyBy(allFolders, 'name') | ||
|
||
return map(favoritesToAdd, ({ id, contents, folderName }) => | ||
assign( | ||
{ | ||
id, | ||
content: contents | ||
}, | ||
folderName in allFavoriteFolders | ||
? { folder: allFavoriteFolders[folderName].id } | ||
: {} | ||
) | ||
) | ||
} | ||
|
||
/** | ||
* Extracts all .cypher files from a .zip archive and converts them to user scripts | ||
* @param {File[]} uploads uploaded .zip files | ||
* @return {Promise<Object[]>} | ||
*/ | ||
export async function readZipFiles (uploads) { | ||
const archives = await Promise.all(map(uploads, JSZip.loadAsync)) | ||
const allFiles = flatMap(archives, ({ files }) => values(files)) | ||
const onlyCypherFiles = filter( | ||
allFiles, | ||
({ name }) => | ||
!startsWith(name, '__MACOSX') && endsWith(name, CYPHER_FILE_EXTENSION) | ||
) | ||
|
||
return Promise.all( | ||
map(onlyCypherFiles, file => | ||
file.async('string').then(fileContentToFavoriteFactory(file)) | ||
) | ||
) | ||
} | ||
|
||
/** | ||
* Factory function returning a file to user script object mapper | ||
* @param {File} file | ||
* @return {Function} user scripts mapper | ||
*/ | ||
export function fileContentToFavoriteFactory (file) { | ||
/** | ||
* Maps .zip archive file contents to a user script object | ||
* @param {String} contents file contents | ||
* @return {Object} user scripts object | ||
*/ | ||
return contents => { | ||
const pathWithoutLeadingSlash = startsWith(file.name, '/') | ||
? file.name.slice(1) | ||
: file.name | ||
const pathParts = split(pathWithoutLeadingSlash, '/') | ||
const folderName = join(reverse(tail(reverse(pathParts))), '/') | ||
|
||
return { id: uuid.v4(), contents, folderName } | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit worried that this might break something but from my tests it all seems fine.
We should verify each step in the build pipeline after this is merged.