-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify
@flatfile/javascript
onboarding (#853)
* feat: initial pass at startFlatfile * feat: fix types * adds data returning to the onData CB * gets record hooks working * restructures data egress * adds sheet option and creates a workbook from a sheet * data egress start * adds stream and inChunks methods * removes a code comment * adds new example app for the simplest of use cases * adds onCancel * updated egress * styling from Friday demo * fail job if error is caught * reworks some things * add proper detail to tsignore comment * handle empty state for onRecordHook and onSubmit * refactor onSubmit stuff --------- Co-authored-by: brentkulwicki <[email protected]> Co-authored-by: Brent Kulwicki <[email protected]>
- Loading branch information
1 parent
565a8da
commit 87ce826
Showing
12 changed files
with
559 additions
and
30 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
h3 { | ||
margin-left: auto; | ||
margin-right: auto; | ||
text-align: center; | ||
margin-top: 48px; | ||
} | ||
|
||
#flatfileButton { | ||
color: #ffffff; | ||
background-color: #3b2fc9; | ||
padding: 10px; | ||
border: 1px solid #3b2fc9; | ||
border-radius: 6px; | ||
} | ||
|
||
#flatfileButton:hover { | ||
background-color: #090B2F; | ||
border: 1px solid #090B2F; | ||
cursor: pointer; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
#raw_output { | ||
position: relative; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
width: 50%; | ||
padding: 64px; | ||
margin: 32px 0; | ||
border: 1px solid #c1c6d1; | ||
border-radius: 4px; | ||
font-family: "Monaco", monospace; | ||
background-color: #31383d; | ||
color: #fff; | ||
height: 500px; | ||
} | ||
|
||
p { | ||
text-align: center; | ||
} |
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,81 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Your Page Title</title> | ||
<script src="../../packages/javascript/dist/index.js"></script> | ||
<link rel="stylesheet" type="text/css" href="index.css"> | ||
<script> | ||
window.openFlatfile = ({ publishableKey, environmentId }) => { | ||
const output = document.getElementById('raw_output') | ||
const sheet = { | ||
name: 'Contacts', | ||
slug: 'contacts', | ||
fields: [ | ||
{ | ||
key: 'firstName', | ||
type: 'string', | ||
label: 'First Name', | ||
}, | ||
{ | ||
key: 'lastName', | ||
type: 'string', | ||
label: 'Last Name', | ||
}, | ||
{ | ||
key: 'email', | ||
type: 'string', | ||
label: 'Email', | ||
}, | ||
], | ||
} | ||
if (!publishableKey) { | ||
throw new Error( | ||
'You must provide a publishable key - pass through in index.html' | ||
) | ||
} | ||
|
||
const flatfileOptions = { | ||
publishableKey, | ||
environmentId, | ||
sheet, | ||
onSubmit: async (job, sheet) => { | ||
const data = await sheet.allData() | ||
output.value = JSON.stringify(data, " ", 2) | ||
console.log('onSubmit', data) | ||
}, | ||
onRecordHook: (record, event) => { | ||
const firstName = record.get('firstName') | ||
const lastName = record.get('lastName') | ||
if (firstName && !lastName) { | ||
record.set('lastName', 'Rock') | ||
record.addInfo('lastName', 'Welcome to the Rock fam') | ||
} | ||
return record | ||
}, | ||
onCancel: () => { | ||
console.log('cancel') | ||
}, | ||
} | ||
|
||
window.FlatFileJavaScript.startFlatfile(flatfileOptions) | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<h3>We heard you like Rocks? So do we. Tell us about this 👇</h3> | ||
<div class="container"> | ||
<button | ||
id="flatfileButton" | ||
onclick="openFlatfile({ publishableKey: 'pk_c7ea3ee12a4f4636b99dcf48429b541b', environmentId: 'us_env_HuwLrKpB'})" | ||
> | ||
Import stuff | ||
</button> | ||
</div> | ||
<label for="raw_output"></label> | ||
<textarea id="raw_output">Your raw output will appear here.</textarea> | ||
<br> | ||
<p>*In order for this to work properly, you must have the JavaScript package built locally.</p> | ||
</body> | ||
</html> |
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,16 @@ | ||
{ | ||
"name": "simplest-flatfile", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "main.js", | ||
"scripts": { | ||
"start": "parcel index.html" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"dotenv": "^16.3.1", | ||
"parcel": "^2.3.1" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.