-
Notifications
You must be signed in to change notification settings - Fork 127
Basic importRoam #888
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
Merged
raineorshine
merged 12 commits into
cybersemics:dev
from
anmolarora1:865_import_from_roam
Nov 6, 2020
Merged
Basic importRoam #888
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f65dd8a
adds basic functions to import from roam json format and respective t…
anmolarora1 b93a349
adds explicit type conversions
anmolarora1 cf72843
minor refactoring
anmolarora1 1e9fe57
adds created and lastUpdated properties
anmolarora1 6e9385f
renames exportWithoutRoot to removeRoot
anmolarora1 3582af5
save create-email and edit-email as '=create-email' and '=edit-email…
anmolarora1 28d44da
replaces duplicate functions with removeRoot
anmolarora1 5260876
adds tests for contextIndex and defaults for created/lastupdated prop…
anmolarora1 20fad6e
renames importRoam to roamJsonToBlocks
anmolarora1 aba5991
adds validateRoam
anmolarora1 ddafbfd
refactors roamJsonToBlocks and respective tests
anmolarora1 0679694
binds roamJsonToBlocks and validateRoam to importText
anmolarora1 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 hidden or 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,17 @@ | ||
declare module 'roam' { | ||
interface RoamBlock { | ||
uid: string, | ||
string: string, | ||
'create-email': string, | ||
'create-time': number, | ||
children?: RoamBlock[], | ||
'edit-time'?: number, | ||
'edit-email'?: string, | ||
} | ||
|
||
interface RoamPage { | ||
title: string, | ||
children: RoamBlock[], | ||
} | ||
|
||
} |
This file contains hidden or 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 hidden or 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,8 @@ | ||
/** | ||
* Remove root, de-indent (trim), and append newline to make tests cleaner. | ||
*/ | ||
export const removeRoot = exported => exported.slice(exported.indexOf('\n')) | ||
.split('\n') | ||
.map(line => line.slice(2)) | ||
.join('\n') | ||
+ '\n' |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
import { | ||
importText, | ||
} from '../../action-creators' | ||
import { removeRoot } from '../../test-helpers/removeRoot' | ||
|
||
const RANKED_ROOT = [{ value: ROOT_TOKEN, rank: 0 }] | ||
const initialState = { | ||
|
@@ -57,13 +58,7 @@ const importExport = async text => { | |
const exported = exportContext(state, [ROOT_TOKEN], 'text/plaintext') | ||
|
||
// remove root, de-indent (trim), and append newline to make tests cleaner | ||
const exportedWithoutRoot = exported.slice(exported.indexOf('\n')) | ||
.split('\n') | ||
.map(line => line.slice(2)) | ||
.join('\n') | ||
+ '\n' | ||
|
||
return exportedWithoutRoot | ||
return removeRoot(exported) | ||
} | ||
|
||
it('initialSettings', async () => { | ||
|
@@ -128,3 +123,97 @@ it('two root thoughts', async () => { | |
expect(exported.trim()) | ||
.toBe(text) | ||
}) | ||
|
||
it('imports Roam json', async () => { | ||
const roamString = JSON.stringify([ | ||
{ | ||
title: 'Fruits', | ||
children: [ | ||
{ | ||
string: 'Apple', | ||
'create-email': '[email protected]', | ||
'edit-email': '[email protected]', | ||
'create-time': 1600111381583, | ||
'edit-time': 1600111381580, | ||
uid: 'UK11200', | ||
}, | ||
{ | ||
string: 'Orange', | ||
'create-email': '[email protected]', | ||
'edit-email': '[email protected]', | ||
'create-time': 1600111383054, | ||
'edit-time': 1600111383050, | ||
uid: 'UK11233', | ||
}, | ||
{ | ||
string: 'Banana', | ||
'create-email': '[email protected]', | ||
'edit-email': '[email protected]', | ||
'create-time': 1600111383911, | ||
'edit-time': 1600111383910, | ||
uid: 'HMN_YQtZZ', | ||
} | ||
], | ||
}, | ||
{ | ||
title: 'Veggies', | ||
children: [ | ||
{ | ||
string: 'Broccoli', | ||
'create-email': '[email protected]', | ||
'edit-email': '[email protected]', | ||
'create-time': 1600111381600, | ||
'edit-time': 1600111381599, | ||
uid: 'BK11200', | ||
}, | ||
{ | ||
string: 'Spinach', | ||
'create-email': '[email protected]', | ||
'edit-email': '[email protected]', | ||
'create-time': 1600111389054, | ||
'edit-time': 1600111389050, | ||
uid: 'BK11233', | ||
} | ||
], | ||
} | ||
]) | ||
// /** | ||
// * Parses Roam and generates { contextIndexUpdates, thoughtIndexUpdates } that can be sync'd to state. | ||
// */ | ||
// export const importRoam = (state: State, simplePath: SimplePath, roam: RoamPage[]) => { | ||
// const thoughtsJSON = roamJsonToBlocks(roam) | ||
// return importJSON(state, simplePath, thoughtsJSON, { skipRoot: false }) | ||
// } | ||
|
||
const exported = await importExport(roamString) | ||
expect(exported) | ||
.toBe(` | ||
- Fruits | ||
- Apple | ||
- =create-email | ||
- [email protected] | ||
- =edit-email | ||
- [email protected] | ||
- Orange | ||
- =create-email | ||
- [email protected] | ||
- =edit-email | ||
- [email protected] | ||
- Banana | ||
- =create-email | ||
- [email protected] | ||
- =edit-email | ||
- [email protected] | ||
- Veggies | ||
- Broccoli | ||
- =create-email | ||
- [email protected] | ||
- =edit-email | ||
- [email protected] | ||
- Spinach | ||
- =create-email | ||
- [email protected] | ||
- =edit-email | ||
- [email protected] | ||
`) | ||
}) |
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.
Old code should be removed