Skip to content

Commit

Permalink
A bunch more polish; don't store API key in doc, fork doc if needed, …
Browse files Browse the repository at this point in the history
…more instructions
  • Loading branch information
dsagal committed Mar 11, 2024
1 parent 2b2f61e commit 9c7540c
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions spreadsheet-com-migration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ function onReady(fn) {
}
}

function setKey(key) {
grist.setOption('scApiKey', key);
scApiKey.set(key);
};

async function fetchSCAttachment(url) {
const fullUrl = new URL('/att', baseUrl);
fullUrl.searchParams.set('key', lambdaKey);
Expand Down Expand Up @@ -79,13 +74,11 @@ onReady(async () => {
requiredAccess: 'full'
});

grist.onOptions((options, settings) => {
scApiKey.set(options.scApiKey);
});

const docId = await grist.docApi.getDocName();
storePrefix = `spreadsheet-com-migration-${docId}:`;

scApiKey.set(store.get(storePrefix + 'scApiKey') || '');

const workbooksObs = Observable.create(null, []);
const selectedWorkbookId = Observable.create(null, null);

Expand Down Expand Up @@ -119,7 +112,14 @@ onReady(async () => {
dom.maybe(stepper.getObs(4), () => [
dom('p', `Congratulations, the import is done!`),
dom('p', `
Some notes. This tool is able to migrate most data types, including relations
If you see a "Save Copy" button in the top bar, this is a good time to save your copy.
`),
dom('p', `
To remove the Migration Tool, use the "Remove" option in the menu next to the page name,
then select "Delete data and this page".
`),
dom('p', `
Some notes: This tool is able to migrate most data types, including relations
(known as "references" in Grist), and attachments. Formulas are imported as values.
Grist supports powerful formulas with a slightly different approach. Read about it at
`, dom('a', {href: 'https://support.getgrist.com/formulas/'}, 'formulas'),
Expand Down Expand Up @@ -178,6 +178,11 @@ function stepConnect(owner, isComplete, workbooksObs, callbacks) {

const cacheKey = storePrefix + 'workbooks';

function setKey(key) {
store.set(storePrefix + 'scApiKey', key);
scApiKey.set(key);
}

async function doConnect() {
const workbooks = await getWorkbooks();
console.warn("workbooks", workbooks);
Expand Down Expand Up @@ -336,6 +341,15 @@ function stepCheckImport(owner, isComplete, selectedWorkbook) {

async function doRemoveConflicts(conflicts) {
store.set(cacheImportDoneKey, false);
// Let's make sure we can make changes to the document; if it's a template or fiddle, we will
// fork it now.
try {
await grist.docApi.applyUserActions([['RemoveTable', '_Dummy_']]);
} catch (e) {
// Ignore.
}


for (const tableId of conflicts.values()) {
await grist.docApi.applyUserActions([['RemoveTable', tableId]]);
}
Expand Down Expand Up @@ -538,7 +552,7 @@ const cssButton = styled('button', `
}
`);

const cssApiKeyBlock = styled('div', `
const cssApiKeyBlock = styled('p', `
display: flex;
align-items: center;
`);
Expand Down

0 comments on commit 9c7540c

Please sign in to comment.