Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

csv: implement file drag and drop #385

Merged
merged 11 commits into from
Feb 27, 2018

Conversation

n-riesco
Copy link
Contributor

@n-riesco n-riesco commented Feb 22, 2018

  • Accept and parse data URLs.

  • Added component <Filedrop>, so that it's possible to drop files into the URL box.

  • Added setting CSV_STORAGE_SIZE to limit the size of the CSV storage.

  • Added Datastores.disconnect(connection) to be invoked when a connection's tab is closed.

  • Implemented disconnect for CSV connectors, so that closing a connection's tab removes the CSV file from storage,

  • Converted CSV module to CommonJS, so that all the files that use
    const CSV = require('./csv.js') share the same CSV storage.

  • Remove bad connection files at startup.

Closes #383

* Added function `setSize(bytes)` to limit the size of the CSV storage.

* Converted CSV module to CommonJS, so that all the files that use
  `const CSV = require('.csv.js')` share the same CSV storage.

* Added spec to test `setSize(bytes)`.
* Added setting CSV_STORAGE_SIZE to limit the size of the CSV storage.
@n-riesco n-riesco changed the title csv: limit storage size csv: data URLS and limit storage size Feb 22, 2018
@n-riesco n-riesco changed the title csv: data URLS and limit storage size csv: data URLs and limit storage size Feb 22, 2018
* `connect` accepts and parses data URLs.

* Added spec to test connection to a data URL.

* Renamed `setSize` to `setStorageSize`.

* Removed CSVError.
* Now it's possible to drag files and drop them on the URL box.

* Removed packages `data-urls` and `whatwg-encoding`, because they would
  exhaust memory when parsing data URLs of 20MB.

* Improved the generation of a connection label when using data URLs.
* Added method Datastores.disconnect(connection) that gets invoked
  whenever a connection is removed by deleteConnectionById(id).

* Implemented disconnect for CSV connector, so that a disconnection
  removes the CSV file from the storage.

* Added spec for disconnect.
@n-riesco
Copy link
Contributor Author

@shannonlal This PR extends the CSV connector. Now, it's possible to drag files into the URL box. To do so, I've added a new component: <Filedrop>.

Another interesting thing in this PR is that I've extended the Datastores interface. Now, connectors can implement the method disconnect. disconnect is invoked when a connection tab is closed.


Would you like to review this PR when you find the time?

@n-riesco n-riesco changed the title csv: data URLs and limit storage size csv: implement file drag and drop Feb 23, 2018
Copy link
Contributor

@shannonlal shannonlal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@n-riesco Really good job. Most are my comments are just minor documentation/questions. I think it is good to go. 💃

}

/**
* Filedrop is an input component where users can type an URL or drop a file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General Comment. I like the style how you have documented the JSDocs and React class structure. I have noticed that there seems to be some inconsistency with the React Classes. Do we have a standard format? I have noticed some classes have PropTypes at the bottom. Is there a standard? Should we document this somewhere? If so where is a good place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shannonlal

I have noticed that there seems to be some inconsistency with the React Classes. Do we have a standard format? I have noticed some classes have PropTypes at the bottom. Is there a standard? Should we document this somewhere? If so where is a good place?

We don't have any guidelines. I'd keep them in a file: CODING_GUIDELINES.md.

I don't want the guidelines to become a burden (it's easier for us to tell contributors to use given files as models; e.g: we could chose one of the files in the project as a model for stateless components, another file for stateful components, and another for components that use redux). Also, by burden, I mean:

  • For example, the burden of prescribing that PropTypes go at the top is OK, because it's just a copy'n'paste.
  • But, for example, I don't think the burden of prescribing all React components should be class components is worth it (i.e. it's OK, and some would say better, that stateless components are written as functional components).


/**
* Filedrop is an input component where users can type an URL or drop a file
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks clean and easy to understand. Do you think this component is worth having a Jest test for or is this overkill?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just added the tests

@@ -70,13 +71,24 @@ export function query(queryObject, connection) {
}

/*
* connect functions attempt to ping the connection and
* return a promise that is empty
* connect attempts to ping the connection and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this JSDocs format? Should it be @params {object} connection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a commit to format it as JSDoc

* connect functions attempt to ping the connection and
* return a promise that is empty
* connect attempts to ping the connection and
* returns a promise that resolves to the connection object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@returns {promise} an empty promise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on the connector and it's likely to change once Falcon becomes smarter about the connections it creates (at the moment, most of the connectors create a new connection for every request, which is OK if the DB driver implements a pool or the request is stateless).

I'll reword it, so that it only states that the promise resolves once the connection succeeds.

}


/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you have two comment blocks for this function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first block declares the type CSVConnection and the second block declares the function connect. See that CSVConnection is also used in the declarations of disconnect, query, tables and schemas.

@n-riesco
Copy link
Contributor Author

@shannonlal I've added tests for <Filedrop>. I'll wait for you to review them before merging.

@@ -0,0 +1,135 @@
jest.unmock('../../../../../app/components/Settings/UserConnections/filedrop.jsx');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good job

@shannonlal
Copy link
Contributor

@n-riesco Really good job. 💃 . Just curious. Your thoughts about Jest and enzyme as UI testing framework?

@n-riesco
Copy link
Contributor Author

n-riesco commented Feb 27, 2018

@shannonlal

Just curious. Your thoughts about Jest and enzyme as UI testing framework?

Testing the initial mount is convenient, but:

  • testing subsequent changes can be rather repetitive (this is the reason why I defined getCurrentInput())
  • and testing asynchronous changes can be rather hacky (I couldn't find any API to register a callback to be triggered when a component is updated)

@n-riesco n-riesco merged commit 8d75c91 into plotly:master Feb 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSV: let users upload a CSV file
2 participants