@lingk/sync 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,6 +67,8 @@ module.exports =
67
67
  value: true
68
68
  });
69
69
 
70
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
71
+
70
72
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
71
73
 
72
74
  var _react = __webpack_require__(1);
@@ -99,6 +101,13 @@ module.exports =
99
101
 
100
102
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
101
103
 
104
+ function formatBytes(a, b) {
105
+ if (0 === a) return "0 Bytes";var c = 1024,
106
+ d = b || 2,
107
+ e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
108
+ f = Math.floor(Math.log(a) / Math.log(c));return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
109
+ }
110
+
102
111
  // SKIP ON SERVER-SIDE RENDERING
103
112
  var codemirror = null;
104
113
  if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
@@ -170,6 +179,7 @@ module.exports =
170
179
  wizard = _props.wizard,
171
180
  adapterSecret = _props.adapterSecret,
172
181
  checkOauthCreds = _props.checkOauthCreds,
182
+ metadata = _props.metadata,
173
183
  getOauthUrl = _props.getOauthUrl,
174
184
  generateNewAdapterSecret = _props.generateNewAdapterSecret,
175
185
  setCsvFields = _props.setCsvFields,
@@ -194,7 +204,7 @@ module.exports =
194
204
 
195
205
  var isOauth = config.credentials && config.credentials.length === 1 && config.credentials[0] === 'Oauth';
196
206
 
197
- var isSFTP = config.credentials && config.credentials.length === 1 && config.credentials[0] === 'SFTP';
207
+ var isFlatFile = config.credentials && config.credentials.length === 1 && config.credentials[0] === 'FlatFile';
198
208
 
199
209
  var isGoogle = config.type.startsWith('Google');
200
210
 
@@ -216,9 +226,10 @@ module.exports =
216
226
  return getOauthUrl(urlType, providerType);
217
227
  },
218
228
  checkOauthCreds: checkOauthCreds, envCheckResult: envCheckResult,
219
- checking: checking, inputs: inputs }) : isSFTP ? _react2.default.createElement(SFTP, { wizard: wizard, onCheck: check,
229
+ checking: checking, inputs: inputs }) : isFlatFile ? _react2.default.createElement(FlatFile, { wizard: wizard, onCheck: check, metadata: metadata,
220
230
  checking: checking, setCsvFields: setCsvFields,
221
- providerType: providerType }) : isGoogle ? _react2.default.createElement(Google, { config: config, creds: creds, onChange: this.onChange,
231
+ providerType: providerType, inputs: inputs,
232
+ accountKey: accountKey, tenantKey: tenantKey }) : isGoogle ? _react2.default.createElement(Google, { config: config, creds: creds, onChange: this.onChange,
222
233
  credsDisabledCheck: credsDisabledCheck, inputs: inputs,
223
234
  onCheck: check }) : _react2.default.createElement(
224
235
  'div',
@@ -399,64 +410,91 @@ module.exports =
399
410
  );
400
411
  };
401
412
 
402
- var SFTP = function (_Component2) {
403
- _inherits(SFTP, _Component2);
413
+ var FlatFile = function (_Component2) {
414
+ _inherits(FlatFile, _Component2);
404
415
 
405
416
  // react-dropzone
406
417
  // papaparse
407
418
 
408
- function SFTP() {
409
- _classCallCheck(this, SFTP);
419
+ function FlatFile() {
420
+ _classCallCheck(this, FlatFile);
410
421
 
411
- var _this3 = _possibleConstructorReturn(this, (SFTP.__proto__ || Object.getPrototypeOf(SFTP)).call(this));
422
+ var _this3 = _possibleConstructorReturn(this, (FlatFile.__proto__ || Object.getPrototypeOf(FlatFile)).call(this));
412
423
 
413
424
  _this3.onDrop = function (fs) {
414
- var _this3$props = _this3.props,
415
- setCsvFields = _this3$props.setCsvFields,
416
- providerType = _this3$props.providerType,
417
- wizard = _this3$props.wizard;
418
-
419
- var m = wizard['metadata'] || [];
420
- var files = [].concat(_toConsumableArray(_this3.state.files));
425
+ var meta = [].concat(_toConsumableArray(_this3.state.meta));
421
426
  var counter = 0;
427
+ var fileContents = [].concat(_toConsumableArray(_this3.state.fileContents));
428
+ var contentCounter = 0;
422
429
  fs.forEach(function (file) {
423
430
  _papaparse2.default.parse(file, {
424
431
  header: true,
432
+ dynamicTyping: true,
425
433
  complete: function complete(result) {
426
- m = m.concat({
427
- name: file.name.split('.')[0],
428
- type: file.name.split('.')[0],
434
+ meta = meta.concat({
435
+ name: file.name,
436
+ type: file.name.substr(0, file.name.lastIndexOf('.')).split(' ').join(),
437
+ byteSize: file.size,
429
438
  properties: result.meta.fields.map(function (f) {
430
439
  return {
431
440
  label: f,
432
- name: f,
433
- type: 'string'
441
+ name: f.split(' ').join(),
442
+ type: result.data[0] && _typeof(result.data[0][f])
434
443
  };
435
- })
444
+ }),
445
+ delimiter: result.meta.delimiter
436
446
  });
437
- files = files.concat(file);
438
447
  counter += 1;
439
448
  if (counter === fs.length) {
440
- _this3.setState({ files: files });
441
- setCsvFields(m, providerType);
449
+ // after last one is done
450
+ _this3.setState({ meta: meta });
442
451
  }
443
452
  }
444
453
  });
454
+ var reader = new FileReader();
455
+ reader.addEventListener("loadend", function (event) {
456
+ fileContents = fileContents.concat(event.target.result);
457
+ contentCounter += 1;
458
+ if (contentCounter === fs.length) {
459
+ _this3.setState({ fileContents: fileContents });
460
+ }
461
+ });
462
+ reader.readAsText(file);
463
+ });
464
+ };
465
+
466
+ _this3.upload = function () {
467
+ var _this3$props = _this3.props,
468
+ setCsvFields = _this3$props.setCsvFields,
469
+ providerType = _this3$props.providerType;
470
+
471
+ _this3.setState({ uploading: true });
472
+ setCsvFields(_this3.state.meta, _this3.state.fileContents, providerType).then(function () {
473
+ _this3.setState({ meta: [], uploading: false });
445
474
  });
446
475
  };
447
476
 
448
477
  _this3.state = {
449
- files: []
478
+ meta: [],
479
+ fileContents: [],
480
+ uploading: false
450
481
  };
451
482
  return _this3;
452
483
  }
453
484
 
454
- _createClass(SFTP, [{
485
+ _createClass(FlatFile, [{
455
486
  key: 'render',
456
487
  value: function render() {
457
- var files = this.state.files;
488
+ var _state = this.state,
489
+ meta = _state.meta,
490
+ uploading = _state.uploading;
491
+ var _props2 = this.props,
492
+ metadata = _props2.metadata,
493
+ inputs = _props2.inputs;
458
494
 
459
- var hasFile = files && files.length > 0;
495
+ var Button = inputs.Button;
496
+ var Spinner = inputs.Spinner;
497
+ var hasFile = meta && meta.length > 0;
460
498
  return _react2.default.createElement(
461
499
  'div',
462
500
  null,
@@ -478,32 +516,78 @@ module.exports =
478
516
  'aside',
479
517
  { style: { marginLeft: 30, display: 'inline-block' } },
480
518
  _react2.default.createElement(
481
- 'h3',
482
- { style: { marginTop: 10 } },
483
- 'Dropped files'
519
+ 'div',
520
+ null,
521
+ _react2.default.createElement(
522
+ 'h3',
523
+ { style: { marginTop: 10, display: 'inline-block', verticalAlign: 'top' } },
524
+ 'Dropped files'
525
+ ),
526
+ _react2.default.createElement(
527
+ Button,
528
+ {
529
+ onClick: this.upload,
530
+ style: { marginTop: 4, marginLeft: 20, verticalAlign: 'top', height: 36 },
531
+ disabled: uploading },
532
+ _react2.default.createElement(
533
+ 'span',
534
+ { style: { display: 'inline-block', verticalAlign: 'top', marginTop: 3 } },
535
+ 'Upload'
536
+ ),
537
+ '\xA0\xA0',
538
+ _react2.default.createElement(UploadIcon, null)
539
+ ),
540
+ uploading && _react2.default.createElement(
541
+ 'div',
542
+ { style: { paddingLeft: 12, paddingTop: 12, display: 'inline-block' } },
543
+ _react2.default.createElement(Spinner, null)
544
+ )
484
545
  ),
485
546
  _react2.default.createElement(
486
547
  'ul',
487
548
  null,
488
- files.map(function (f, i) {
549
+ meta.map(function (f, i) {
489
550
  return _react2.default.createElement(
490
551
  'li',
491
552
  { key: i },
492
553
  f.name,
493
554
  ' - ',
494
- f.size,
495
- ' bytes'
555
+ formatBytes(f.byteSize)
496
556
  );
497
557
  })
498
558
  )
559
+ ),
560
+ !uploading && metadata && metadata.length > 0 && _react2.default.createElement(
561
+ 'div',
562
+ {
563
+ style: { marginLeft: 20, display: 'inline-block', marginTop: 13, verticalAlign: 'top' } },
564
+ _react2.default.createElement(
565
+ 'strong',
566
+ { style: { marginRight: 5 } },
567
+ metadata && metadata.length
568
+ ),
569
+ _react2.default.createElement(
570
+ 'span',
571
+ null,
572
+ 'file' + (metadata.length === 1 ? '' : 's') + ' uploaded'
573
+ )
499
574
  )
500
575
  );
501
576
  }
502
577
  }]);
503
578
 
504
- return SFTP;
579
+ return FlatFile;
505
580
  }(_react.Component);
506
581
 
582
+ var UploadIcon = function UploadIcon() {
583
+ return _react2.default.createElement(
584
+ 'svg',
585
+ { fill: '#666', height: '24', viewBox: '0 0 24 24', width: '24' },
586
+ _react2.default.createElement('path', { d: 'M0 0h24v24H0z', fill: 'none' }),
587
+ _react2.default.createElement('path', { d: 'M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z' })
588
+ );
589
+ };
590
+
507
591
  var Oauth = function (_Component3) {
508
592
  _inherits(Oauth, _Component3);
509
593
 
@@ -550,15 +634,15 @@ module.exports =
550
634
  }, {
551
635
  key: 'render',
552
636
  value: function render() {
553
- var _props2 = this.props,
554
- wizard = _props2.wizard,
555
- onGenerateUrl = _props2.onGenerateUrl,
556
- onCheck = _props2.onCheck,
557
- providerType = _props2.providerType,
558
- checking = _props2.checking,
559
- creds = _props2.creds,
560
- inputs = _props2.inputs,
561
- envCheckResult = _props2.envCheckResult;
637
+ var _props3 = this.props,
638
+ wizard = _props3.wizard,
639
+ onGenerateUrl = _props3.onGenerateUrl,
640
+ onCheck = _props3.onCheck,
641
+ providerType = _props3.providerType,
642
+ checking = _props3.checking,
643
+ creds = _props3.creds,
644
+ inputs = _props3.inputs,
645
+ envCheckResult = _props3.envCheckResult;
562
646
 
563
647
  var Spinner = inputs.Spinner;
564
648
  var Button = inputs.Button;
@@ -750,13 +834,13 @@ module.exports =
750
834
  value: function render() {
751
835
  var _this8 = this;
752
836
 
753
- var _props3 = this.props,
754
- generateNewAdapterSecret = _props3.generateNewAdapterSecret,
755
- tenantKey = _props3.tenantKey,
756
- accountKey = _props3.accountKey,
757
- providerType = _props3.providerType,
758
- secret = _props3.secret,
759
- inputs = _props3.inputs;
837
+ var _props4 = this.props,
838
+ generateNewAdapterSecret = _props4.generateNewAdapterSecret,
839
+ tenantKey = _props4.tenantKey,
840
+ accountKey = _props4.accountKey,
841
+ providerType = _props4.providerType,
842
+ secret = _props4.secret,
843
+ inputs = _props4.inputs;
760
844
 
761
845
  var Spinner = inputs.Spinner;
762
846
  var Button = inputs.Button;