From 7bbb9437046f7c32e51c88ed687c949beff99916 Mon Sep 17 00:00:00 2001 From: "Forbes-Smith, Nick (Data61, Clayton)" Date: Mon, 9 Mar 2020 18:03:16 +1100 Subject: [PATCH 1/8] Fixed dragdrop component --- lib/ReactViewModels/ViewState.ts | 1 + lib/ReactViews/DragDropFile.jsx | 77 +++++++++-------- lib/ReactViews/DragDropNotification.jsx | 82 ++++++++++--------- .../StandardUserInterface.jsx | 9 +- 4 files changed, 86 insertions(+), 83 deletions(-) diff --git a/lib/ReactViewModels/ViewState.ts b/lib/ReactViewModels/ViewState.ts index bcd7d91abcd..3b59680b9c6 100644 --- a/lib/ReactViewModels/ViewState.ts +++ b/lib/ReactViewModels/ViewState.ts @@ -54,6 +54,7 @@ export default class ViewState { @observable mobileMenuVisible: boolean = false; @observable explorerPanelAnimating: boolean = false; @observable topElement: string = "FeatureInfo"; + @observable lastUploadedFiles: any[] = []; @observable storyBuilderShown: boolean = false; // Flesh out later diff --git a/lib/ReactViews/DragDropFile.jsx b/lib/ReactViews/DragDropFile.jsx index 0691d4e1b2e..73effca545c 100644 --- a/lib/ReactViews/DragDropFile.jsx +++ b/lib/ReactViews/DragDropFile.jsx @@ -1,67 +1,64 @@ import React from "react"; -import createReactClass from "create-react-class"; import PropTypes from "prop-types"; import classNames from "classnames"; -import ObserveModelMixin from "./ObserveModelMixin"; import addUserFiles from "../Models/addUserFiles"; import { Trans, withTranslation } from "react-i18next"; -import Styles from "./drag-drop-file.scss"; +import { observer } from "mobx-react"; +import { flow, action } from "mobx"; -const DragDropFile = createReactClass({ - displayName: "DragDropFile", - mixins: [ObserveModelMixin], +import Styles from "./drag-drop-file.scss"; - propTypes: { +@observer +class DragDropFile extends React.Component { + static propTypes = { terria: PropTypes.object, viewState: PropTypes.object - }, + }; - target: null, + target = null; - handleDrop(e) { + handleDrop = flow(function*(e) { e.preventDefault(); e.stopPropagation(); - addUserFiles( + const addedCatalogItems = yield addUserFiles( e.dataTransfer.files, this.props.terria, this.props.viewState, null - ).then(addedCatalogItems => { - if (addedCatalogItems.length > 0) { - this.props.viewState.myDataIsUploadView = false; - if (this.props.viewState.explorerPanelIsVisible) { - this.props.viewState.viewCatalogMember(addedCatalogItems[0]); - this.props.viewState.openUserData(); - } else { - this.notifyUpload(addedCatalogItems); - } + ); + + if (addedCatalogItems.length > 0) { + this.props.viewState.myDataIsUploadView = false; + if (this.props.viewState.explorerPanelIsVisible) { + this.props.viewState.viewCatalogMember(addedCatalogItems[0]); + this.props.viewState.openUserData(); + } else { + // update last batch of uploaded files + this.props.viewState.lastUploadedFiles = addedCatalogItems.map( + item => item.name + ); } - }); + } this.props.viewState.isDraggingDroppingFile = false; - }, - - notifyUpload(addedCatalogItems) { - // update last batch of uploaded files - this.props.viewState.lastUploadedFiles = addedCatalogItems.map( - item => item.name - ); - }, + }); + @action handleDragEnter(e) { e.preventDefault(); e.stopPropagation(); e.dataTransfer.dropEffect = "copy"; this.lastTarget = e.target; - }, + } handleDragOver(e) { e.preventDefault(); - }, + } + @action handleDragLeave(e) { e.preventDefault(); if (e.screenX === 0 && e.screenY === 0) { @@ -70,20 +67,21 @@ const DragDropFile = createReactClass({ if (e.target === document || e.target === this.lastTarget) { this.props.viewState.isDraggingDroppingFile = false; } - }, + } + @action handleMouseLeave() { this.props.viewState.isDraggingDroppingFile = false; - }, + } render() { return (
); } -}); - +} module.exports = withTranslation()(DragDropFile); diff --git a/lib/ReactViews/DragDropNotification.jsx b/lib/ReactViews/DragDropNotification.jsx index 730cd6c24e9..66ce957638c 100644 --- a/lib/ReactViews/DragDropNotification.jsx +++ b/lib/ReactViews/DragDropNotification.jsx @@ -1,53 +1,58 @@ "use strict"; -import ObserveModelMixin from "./ObserveModelMixin"; import React from "react"; -import createReactClass from "create-react-class"; import PropTypes from "prop-types"; import classNames from "classnames"; import Icon from "./Icon.jsx"; import Styles from "./drag-drop-notification.scss"; -const DragDropNotification = createReactClass({ - displayName: "DragDropNotification", - mixins: [ObserveModelMixin], - propTypes: { - viewState: PropTypes.object, - lastUploadedFiles: PropTypes.array - }, +import { observer } from "mobx-react"; +import { reaction } from "mobx"; - notificationTimeout: null, - - getInitialState() { - return { +@observer +class DragDropNotification extends React.Component { + constructor(props) { + super(props); + this.state = { showNotification: false }; - }, + } - /* eslint-disable-next-line camelcase */ - UNSAFE_componentWillReceiveProps(newProps) { - if (this.props.lastUploadedFiles !== newProps.lastUploadedFiles) { - clearTimeout(this.notificationTimeout); - // show notification, restart timer - this.setState({ - showNotification: true - }); - // initialise new time out - this.notificationTimeout = setTimeout(() => { + static propTypes = { + viewState: PropTypes.object + }; + + notificationTimeout = null; + lastUploadedFilesReaction = null; + + componentDidMount() { + this.lastUploadedFilesReaction = reaction( + () => this.props.viewState.lastUploadedFiles, + () => { + clearTimeout(this.notificationTimeout); + // show notification, restart timer this.setState({ - showNotification: false + showNotification: true }); - }, 5000); - } - }, + // initialise new time out + this.notificationTimeout = setTimeout(() => { + this.setState({ + showNotification: false + }); + }, 5000); + } + ); + } componentWillUnmount() { clearTimeout(this.notificationTimeout); - }, + this.lastUploadedFilesReaction() + } handleHover() { // reset timer on hover clearTimeout(this.notificationTimeout); - }, + + } handleMouseLeave() { this.notificationTimeout = setTimeout(() => { @@ -55,22 +60,22 @@ const DragDropNotification = createReactClass({ showNotification: false }); }, 4000); - }, + } handleClick() { this.props.viewState.openUserData(); - }, + } render() { - const fileNames = this.props.lastUploadedFiles.join(","); + const fileNames = this.props.viewState.lastUploadedFiles.join(","); return ( ); } -}); +} + module.exports = DragDropNotification; diff --git a/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx b/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx index 7ca88206221..5cca17a6534 100644 --- a/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx +++ b/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx @@ -7,8 +7,8 @@ import combine from "terriajs-cesium/Source/Core/combine"; import { terriaTheme } from "./StandardTheme"; import arrayContains from "../../Core/arrayContains"; import Branding from "../SidePanel/Branding"; -// import DragDropFile from '../DragDropFile'; -// import DragDropNotification from './../DragDropNotification'; +import DragDropFile from '../DragDropFile'; +import DragDropNotification from './../DragDropNotification'; import ExplorerWindow from "../ExplorerWindow/ExplorerWindow"; import FeatureInfoPanel from "../FeatureInfo/FeatureInfoPanel"; import FeedbackForm from "../Feedback/FeedbackForm"; @@ -339,14 +339,13 @@ const StandardUserInterface = observer( viewState={this.props.viewState} />
- {/* */} + /> {showStoryPanel && ( )} From e7021d90591f591bd0c7e4e996ade1e4b236d93e Mon Sep 17 00:00:00 2001 From: "Forbes-Smith, Nick (Data61, Clayton)" Date: Thu, 12 Mar 2020 15:36:14 +1100 Subject: [PATCH 2/8] start cleaning up createCatalogItemFromFile --- lib/Models/createCatalogItemFromFileOrUrl.ts | 26 ++++++++++++-------- lib/Models/createCatalogItemFromUrl.ts | 23 +++-------------- test/Models/createCatalogItemFromUrlSpec.ts | 4 +-- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/lib/Models/createCatalogItemFromFileOrUrl.ts b/lib/Models/createCatalogItemFromFileOrUrl.ts index 3d239f478dd..f2185783ee1 100644 --- a/lib/Models/createCatalogItemFromFileOrUrl.ts +++ b/lib/Models/createCatalogItemFromFileOrUrl.ts @@ -30,16 +30,22 @@ export default function createCatalogItemFromFileOrUrl( } if (dataType === "auto") { - return createCatalogItemFromUrl(name, terria, isUrl).then(newItem => { - //##Doesn't work for file uploads - if (!isDefined(newItem)) { - return tryConversionService(name, terria, viewState, confirmConversion); - } else { - // It's a file or service we support directly - // In some cases (web services), the item will already have been loaded by this point. - return loadItem(newItem, fileOrUrl); - } - }); + if (isUrl) { + return createCatalogItemFromUrl(name, terria).then(newItem => { + //##Doesn't work for file uploads + if (!isDefined(newItem)) { + return tryConversionService(name, terria, viewState, confirmConversion); + } else { + // It's a file or service we support directly + // In some cases (web services), the item will already have been loaded by this point. + return loadItem(newItem, fileOrUrl); + } + }); + } else { + throw 'Auto datatype is not implemented for Files' + } + + } else if (dataType === "other") { // user explicitly chose "Other (use conversion service)" return getConfirmation( diff --git a/lib/Models/createCatalogItemFromUrl.ts b/lib/Models/createCatalogItemFromUrl.ts index 8a2bd50ec83..de42ef5282e 100644 --- a/lib/Models/createCatalogItemFromUrl.ts +++ b/lib/Models/createCatalogItemFromUrl.ts @@ -8,26 +8,9 @@ import UrlReference from "./UrlReference"; export default function createCatalogItemFromUrl( url: string, terria: Terria, - allowLoad: boolean, - _index?: number -): Promise { - return createCatalogItemFromUrlWithOptions( - url, - terria, - allowLoad, - {}, - _index - ); -} - -export function createCatalogItemFromUrlWithOptions( - url: string, - terria: Terria, - allowLoad: boolean, - options: { + _index?: number, options: { id?: string; - }, - _index?: number + } = {} ): Promise { const item = upsertModelFromJson( CatalogMemberFactory, @@ -40,7 +23,7 @@ export function createCatalogItemFromUrlWithOptions( name: url, url: url, localId: options.id || url, - allowLoad: allowLoad + allowLoad: true } ); diff --git a/test/Models/createCatalogItemFromUrlSpec.ts b/test/Models/createCatalogItemFromUrlSpec.ts index 57148c3e61f..c3eb8807a1a 100644 --- a/test/Models/createCatalogItemFromUrlSpec.ts +++ b/test/Models/createCatalogItemFromUrlSpec.ts @@ -33,7 +33,7 @@ describe("createCatalogItemFromUrl", function() { it("should create an item of the first registered type", function(done) { const url = "test/WMS/single_metadata_url.xml"; - createCatalogItemFromUrl(url, terria, true).then(item => { + createCatalogItemFromUrl(url, terria).then(item => { expect(item).toBeDefined(); if (item !== undefined) { @@ -49,7 +49,7 @@ describe("createCatalogItemFromUrl", function() { it("should create an item of the second registered type", function(done) { const url = "test/geoJSON/bike_racks.geojson"; - createCatalogItemFromUrl(url, terria, true).then(item => { + createCatalogItemFromUrl(url, terria).then(item => { expect(item).toBeDefined(); if (item !== undefined) { expect(item instanceof UrlReference).toBe(true); From c459b05e702771077ec4c9d3a33b0db80593dc46 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Thu, 9 Apr 2020 12:27:00 +1000 Subject: [PATCH 3/8] drag drop file now working --- lib/Models/CsvCatalogItem.ts | 11 ++-- lib/Models/GtfsCatalogItem.ts | 4 +- lib/Models/createCatalogItemFromFileOrUrl.ts | 58 +++++++++---------- lib/Models/createCatalogItemFromUrl.ts | 9 ++- lib/ReactViews/drag-drop-file.scss.d.ts | 13 +++++ .../drag-drop-notification.scss.d.ts | 12 ++++ test/Models/createCatalogItemFromUrlSpec.ts | 4 +- 7 files changed, 66 insertions(+), 45 deletions(-) create mode 100644 lib/ReactViews/drag-drop-file.scss.d.ts create mode 100644 lib/ReactViews/drag-drop-notification.scss.d.ts diff --git a/lib/Models/CsvCatalogItem.ts b/lib/Models/CsvCatalogItem.ts index 4a6e79e51cc..c433b8dc4f9 100644 --- a/lib/Models/CsvCatalogItem.ts +++ b/lib/Models/CsvCatalogItem.ts @@ -15,6 +15,7 @@ import StratumOrder from "./StratumOrder"; import Terria from "./Terria"; import AutoRefreshingMixin from "../ModelMixins/AutoRefreshingMixin"; import isDefined from "../Core/isDefined"; +import { BaseModel } from "./Model"; // Types of CSVs: // - Points - Latitude and longitude columns or address @@ -44,8 +45,8 @@ export default class CsvCatalogItem extends TableMixin( private _csvFile?: File; - constructor(id: string | undefined, terria: Terria) { - super(id, terria); + constructor(id: string | undefined, terria: Terria, sourceReference?: BaseModel) { + super(id, terria, sourceReference); this.strata.set( automaticTableStylesStratumName, new TableAutomaticStylesStratum(this) @@ -126,11 +127,11 @@ export default class CsvCatalogItem extends TableMixin( protected forceLoadTableData(): Promise { if (this.csvString !== undefined) { return Csv.parseString(this.csvString, true); - } else if (this.url !== undefined) { - return Csv.parseUrl(proxyCatalogItemUrl(this, this.url, "1d"), true); } else if (this._csvFile !== undefined) { return Csv.parseFile(this._csvFile, true); - } else { + } else if (this.url !== undefined) { + return Csv.parseUrl(proxyCatalogItemUrl(this, this.url, "1d"), true); + } else { return Promise.reject( new TerriaError({ sender: this, diff --git a/lib/Models/GtfsCatalogItem.ts b/lib/Models/GtfsCatalogItem.ts index 3fe6c341a53..a7e54d4f0be 100644 --- a/lib/Models/GtfsCatalogItem.ts +++ b/lib/Models/GtfsCatalogItem.ts @@ -299,8 +299,8 @@ export default class GtfsCatalogItem extends AsyncMappableMixin( return new ModelGraphics(options); } - constructor(id: string | undefined, terria: Terria) { - super(id, terria); + constructor(id: string | undefined, terria: Terria, sourceReference?: BaseModel) { + super(id, terria, sourceReference); // We should only poll when our map items have consumers onBecomeObserved(this, "mapItems", () => { this.disposer = reaction( diff --git a/lib/Models/createCatalogItemFromFileOrUrl.ts b/lib/Models/createCatalogItemFromFileOrUrl.ts index f2185783ee1..b9ee7054106 100644 --- a/lib/Models/createCatalogItemFromFileOrUrl.ts +++ b/lib/Models/createCatalogItemFromFileOrUrl.ts @@ -10,6 +10,8 @@ import createCatalogItemFromUrl from "./createCatalogItemFromUrl"; import { BaseModel } from "./Model"; import Terria from "./Terria"; import upsertModelFromJson from "./upsertModelFromJson"; +import UrlReference from "./UrlReference"; +import ReferenceMixin from "../ModelMixins/ReferenceMixin"; export default function createCatalogItemFromFileOrUrl( terria: Terria, @@ -30,22 +32,15 @@ export default function createCatalogItemFromFileOrUrl( } if (dataType === "auto") { - if (isUrl) { - return createCatalogItemFromUrl(name, terria).then(newItem => { - //##Doesn't work for file uploads - if (!isDefined(newItem)) { - return tryConversionService(name, terria, viewState, confirmConversion); - } else { - // It's a file or service we support directly - // In some cases (web services), the item will already have been loaded by this point. - return loadItem(newItem, fileOrUrl); - } - }); - } else { - throw 'Auto datatype is not implemented for Files' - } - - + return createCatalogItemFromUrl(name, terria, isUrl).then(newItem => { + if (!isDefined(newItem)) { + return tryConversionService(name, terria, viewState, confirmConversion); + } else { + // It's a file or service we support directly + // In some cases (web services), the item will already have been loaded by this point. + return loadItem(newItem, fileOrUrl); + } + }); } else if (dataType === "other") { // user explicitly chose "Other (use conversion service)" return getConfirmation( @@ -166,29 +161,30 @@ function getConfirmation( }); } -function loadItem(newCatalogItem: BaseModel, fileOrUrl: File | string) { +async function loadItem( + newCatalogItem: BaseModel, + fileOrUrl: File | string +): Promise { + if ( + ReferenceMixin.is(newCatalogItem) && + newCatalogItem.target !== undefined + ) { + return loadItem(newCatalogItem.target, fileOrUrl); + } + if (typeof fileOrUrl === "string") { newCatalogItem.setTrait(CommonStrata.user, "url", fileOrUrl); - } else { - if (hasFileInput(newCatalogItem)) { - newCatalogItem.setFileInput(fileOrUrl); - } - // TODO - // newCatalogItem.dataSourceUrl = fileOrUrl.name; - // newCatalogItem.dataUrlType = "local"; + } else if (hasFileInput(newCatalogItem)) { + newCatalogItem.setFileInput(fileOrUrl); } - if (CatalogMemberMixin.isMixedInto(newCatalogItem)) { - return newCatalogItem.loadMetadata().then(() => newCatalogItem); - } else { - return Promise.resolve(newCatalogItem); - } + return newCatalogItem; } -interface HasFileInput extends BaseModel { +export interface HasFileInput extends BaseModel { setFileInput(file: File): void; } -function hasFileInput(model: BaseModel): model is HasFileInput { +export function hasFileInput(model: BaseModel): model is HasFileInput { return "setFileInput" in model; } diff --git a/lib/Models/createCatalogItemFromUrl.ts b/lib/Models/createCatalogItemFromUrl.ts index de42ef5282e..aa6c2b514b6 100644 --- a/lib/Models/createCatalogItemFromUrl.ts +++ b/lib/Models/createCatalogItemFromUrl.ts @@ -8,9 +8,8 @@ import UrlReference from "./UrlReference"; export default function createCatalogItemFromUrl( url: string, terria: Terria, - _index?: number, options: { - id?: string; - } = {} + isUrl: boolean, + _index?: number ): Promise { const item = upsertModelFromJson( CatalogMemberFactory, @@ -22,8 +21,8 @@ export default function createCatalogItemFromUrl( type: UrlReference.type, name: url, url: url, - localId: options.id || url, - allowLoad: true + localId: url, + allowLoad: isUrl } ); diff --git a/lib/ReactViews/drag-drop-file.scss.d.ts b/lib/ReactViews/drag-drop-file.scss.d.ts new file mode 100644 index 00000000000..a13d68a2c4b --- /dev/null +++ b/lib/ReactViews/drag-drop-file.scss.d.ts @@ -0,0 +1,13 @@ +// This file is automatically generated. +// Please do not change this file! +interface CssExports { + 'caption': string; + 'drop-zone': string; + 'dropZone': string; + 'heading': string; + 'inner': string; + 'is-active': string; + 'isActive': string; +} +declare var cssExports: CssExports; +export = cssExports; diff --git a/lib/ReactViews/drag-drop-notification.scss.d.ts b/lib/ReactViews/drag-drop-notification.scss.d.ts new file mode 100644 index 00000000000..29e5d697a22 --- /dev/null +++ b/lib/ReactViews/drag-drop-notification.scss.d.ts @@ -0,0 +1,12 @@ +// This file is automatically generated. +// Please do not change this file! +interface CssExports { + 'action': string; + 'filename': string; + 'icon': string; + 'info': string; + 'isActive': string; + 'notification': string; +} +declare var cssExports: CssExports; +export = cssExports; diff --git a/test/Models/createCatalogItemFromUrlSpec.ts b/test/Models/createCatalogItemFromUrlSpec.ts index c3eb8807a1a..57148c3e61f 100644 --- a/test/Models/createCatalogItemFromUrlSpec.ts +++ b/test/Models/createCatalogItemFromUrlSpec.ts @@ -33,7 +33,7 @@ describe("createCatalogItemFromUrl", function() { it("should create an item of the first registered type", function(done) { const url = "test/WMS/single_metadata_url.xml"; - createCatalogItemFromUrl(url, terria).then(item => { + createCatalogItemFromUrl(url, terria, true).then(item => { expect(item).toBeDefined(); if (item !== undefined) { @@ -49,7 +49,7 @@ describe("createCatalogItemFromUrl", function() { it("should create an item of the second registered type", function(done) { const url = "test/geoJSON/bike_racks.geojson"; - createCatalogItemFromUrl(url, terria).then(item => { + createCatalogItemFromUrl(url, terria, true).then(item => { expect(item).toBeDefined(); if (item !== undefined) { expect(item instanceof UrlReference).toBe(true); From b274bef628d1a6a9034afec2f572653456ad64da Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Thu, 9 Apr 2020 12:59:17 +1000 Subject: [PATCH 4/8] run prettier and rename things --- lib/Models/CsvCatalogItem.ts | 8 +++- lib/Models/GtfsCatalogItem.ts | 6 ++- lib/Models/UrlReference.ts | 12 ++--- lib/Models/createCatalogItemFromFileOrUrl.ts | 4 +- ...romUrl.ts => createUrlReferenceFromUrl.ts} | 11 +++-- lib/Models/registerCatalogMembers.ts | 44 +++++++++---------- lib/ReactViews/DragDropNotification.jsx | 7 ++- .../StandardUserInterface.jsx | 14 +++--- test/Models/TerriaSpec.ts | 4 +- test/Models/createCatalogItemFromUrlSpec.ts | 12 ++--- 10 files changed, 63 insertions(+), 59 deletions(-) rename lib/Models/{createCatalogItemFromUrl.ts => createUrlReferenceFromUrl.ts} (84%) diff --git a/lib/Models/CsvCatalogItem.ts b/lib/Models/CsvCatalogItem.ts index c433b8dc4f9..4c28a7c7219 100644 --- a/lib/Models/CsvCatalogItem.ts +++ b/lib/Models/CsvCatalogItem.ts @@ -45,7 +45,11 @@ export default class CsvCatalogItem extends TableMixin( private _csvFile?: File; - constructor(id: string | undefined, terria: Terria, sourceReference?: BaseModel) { + constructor( + id: string | undefined, + terria: Terria, + sourceReference?: BaseModel + ) { super(id, terria, sourceReference); this.strata.set( automaticTableStylesStratumName, @@ -131,7 +135,7 @@ export default class CsvCatalogItem extends TableMixin( return Csv.parseFile(this._csvFile, true); } else if (this.url !== undefined) { return Csv.parseUrl(proxyCatalogItemUrl(this, this.url, "1d"), true); - } else { + } else { return Promise.reject( new TerriaError({ sender: this, diff --git a/lib/Models/GtfsCatalogItem.ts b/lib/Models/GtfsCatalogItem.ts index a7e54d4f0be..7d3aaeac2e2 100644 --- a/lib/Models/GtfsCatalogItem.ts +++ b/lib/Models/GtfsCatalogItem.ts @@ -299,7 +299,11 @@ export default class GtfsCatalogItem extends AsyncMappableMixin( return new ModelGraphics(options); } - constructor(id: string | undefined, terria: Terria, sourceReference?: BaseModel) { + constructor( + id: string | undefined, + terria: Terria, + sourceReference?: BaseModel + ) { super(id, terria, sourceReference); // We should only poll when our map items have consumers onBecomeObserved(this, "mapItems", () => { diff --git a/lib/Models/UrlReference.ts b/lib/Models/UrlReference.ts index 9ad5cf0060b..e4e84a3418f 100644 --- a/lib/Models/UrlReference.ts +++ b/lib/Models/UrlReference.ts @@ -9,7 +9,7 @@ import ModelTraits from "../Traits/ModelTraits"; import UrlReferenceTraits from "../Traits/UrlReferenceTraits"; import StratumOrder from "./StratumOrder"; import CatalogMemberMixin from "../ModelMixins/CatalogMemberMixin"; -import { mapping } from "./createCatalogItemFromUrl"; +import { mapping } from "./createUrlReferenceFromUrl"; import updateModelFromJson from "./updateModelFromJson"; const urlRecordStratum = "url-record"; @@ -40,7 +40,7 @@ export default class UrlReference extends UrlMixin( return Promise.resolve(undefined); } - const target = UrlReference.createCatalogItemFromUrlReference( + const target = UrlReference.createUrlReferenceFromUrlReference( this, this.uniqueId, this.url, @@ -51,7 +51,7 @@ export default class UrlReference extends UrlMixin( return Promise.resolve(target); } - private static createCatalogItemFromUrlReference( + private static createUrlReferenceFromUrlReference( sourceReference: BaseModel, id: string, url: string, @@ -68,7 +68,7 @@ export default class UrlReference extends UrlMixin( (mapping[index].matcher && !mapping[index].matcher(url)) || (mapping[index].requiresLoad && !allowLoad) ) { - return UrlReference.createCatalogItemFromUrlReference( + return UrlReference.createUrlReferenceFromUrlReference( sourceReference, id, url, @@ -85,7 +85,7 @@ export default class UrlReference extends UrlMixin( ); if (item === undefined) { - return UrlReference.createCatalogItemFromUrlReference( + return UrlReference.createUrlReferenceFromUrlReference( sourceReference, id, url, @@ -105,7 +105,7 @@ export default class UrlReference extends UrlMixin( .loadMetadata() .then(() => item) .catch(e => { - return UrlReference.createCatalogItemFromUrlReference( + return UrlReference.createUrlReferenceFromUrlReference( sourceReference, id, url, diff --git a/lib/Models/createCatalogItemFromFileOrUrl.ts b/lib/Models/createCatalogItemFromFileOrUrl.ts index b9ee7054106..cfc7e32fca4 100644 --- a/lib/Models/createCatalogItemFromFileOrUrl.ts +++ b/lib/Models/createCatalogItemFromFileOrUrl.ts @@ -6,7 +6,7 @@ import CatalogMemberMixin from "../ModelMixins/CatalogMemberMixin"; import ViewState from "../ReactViewModels/ViewState"; import CatalogMemberFactory from "./CatalogMemberFactory"; import CommonStrata from "./CommonStrata"; -import createCatalogItemFromUrl from "./createCatalogItemFromUrl"; +import createUrlReferenceFromUrl from "./createUrlReferenceFromUrl"; import { BaseModel } from "./Model"; import Terria from "./Terria"; import upsertModelFromJson from "./upsertModelFromJson"; @@ -32,7 +32,7 @@ export default function createCatalogItemFromFileOrUrl( } if (dataType === "auto") { - return createCatalogItemFromUrl(name, terria, isUrl).then(newItem => { + return createUrlReferenceFromUrl(name, terria, isUrl).then(newItem => { if (!isDefined(newItem)) { return tryConversionService(name, terria, viewState, confirmConversion); } else { diff --git a/lib/Models/createCatalogItemFromUrl.ts b/lib/Models/createUrlReferenceFromUrl.ts similarity index 84% rename from lib/Models/createCatalogItemFromUrl.ts rename to lib/Models/createUrlReferenceFromUrl.ts index aa6c2b514b6..ec5e548adc8 100644 --- a/lib/Models/createCatalogItemFromUrl.ts +++ b/lib/Models/createUrlReferenceFromUrl.ts @@ -2,15 +2,14 @@ import Terria from "./Terria"; import CommonStrata from "./CommonStrata"; import upsertModelFromJson from "./upsertModelFromJson"; import CatalogMemberFactory from "./CatalogMemberFactory"; -import { BaseModel } from "./Model"; import UrlReference from "./UrlReference"; -export default function createCatalogItemFromUrl( +export default function createUrlReferenceFromUrl( url: string, terria: Terria, - isUrl: boolean, + allowLoad: boolean, _index?: number -): Promise { +): Promise { const item = upsertModelFromJson( CatalogMemberFactory, terria, @@ -22,7 +21,7 @@ export default function createCatalogItemFromUrl( name: url, url: url, localId: url, - allowLoad: isUrl + allowLoad: allowLoad } ); @@ -48,7 +47,7 @@ interface MappingEntry { export const mapping: MappingEntry[] = []; -createCatalogItemFromUrl.register = function( +createUrlReferenceFromUrl.register = function( matcher: Matcher, type: string, requiresLoad?: boolean diff --git a/lib/Models/registerCatalogMembers.ts b/lib/Models/registerCatalogMembers.ts index fefcea53641..c705e03b86f 100644 --- a/lib/Models/registerCatalogMembers.ts +++ b/lib/Models/registerCatalogMembers.ts @@ -7,7 +7,7 @@ import CatalogGroup from "./CatalogGroupNew"; import CatalogMemberFactory from "./CatalogMemberFactory"; import Cesium3DTilesCatalogItem from "./Cesium3DTilesCatalogItem"; import CesiumTerrainCatalogItem from "./CesiumTerrainCatalogItem"; -import createCatalogItemFromUrl from "./createCatalogItemFromUrl"; +import createUrlReferenceFromUrl from "./createUrlReferenceFromUrl"; import CsvCatalogItem from "./CsvCatalogItem"; import CzmlCatalogItem from "./CzmlCatalogItem"; import GeoJsonCatalogItem from "./GeoJsonCatalogItem"; @@ -88,103 +88,103 @@ export default function registerCatalogMembers() { CompositeCatalogItem ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("csv"), CsvCatalogItem.type ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("czm"), CzmlCatalogItem.type ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("czml"), CzmlCatalogItem.type ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("geojson"), GeoJsonCatalogItem.type ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("json"), GeoJsonCatalogItem.type ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("kml"), KmlCatalogItem.type ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("kmz"), KmlCatalogItem.type ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("topojson"), GeoJsonCatalogItem.type ); // These items work by trying to match a URL, then loading the data. If it fails, they move on. - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/wms/i), WebMapServiceCatalogGroup.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/arcgis\/rest\/.*\/MapServer\/\d+\b/i), ArcGisMapServerCatalogItem.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/arcgis\/rest\/.*\/FeatureServer\/\d+\b/i), ArcGisFeatureServerCatalogItem.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/arcgis\/rest\/.*\/FeatureServer(\/.*)?$/i), ArcGisFeatureServerCatalogGroup.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/arcgis\/rest\/.*\/\d+\b/i), ArcGisMapServerCatalogItem.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/rest\/.*\/MapServer\/\d+\b/i), ArcGisMapServerCatalogItem.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/rest\/.*\/FeatureServer\/\d+\b/i), ArcGisFeatureServerCatalogItem.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/rest\/.*\/FeatureServer(\/.*)?$/i), ArcGisFeatureServerCatalogGroup.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesUrl(/\/rest\/.*\/\d+\b/i), ArcGisMapServerCatalogItem.type, true ); // These don't even try to match a URL, they're just total fallbacks. We really, really want something to work. - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( s => true, WebMapServiceCatalogGroup.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( s => true, ArcGisMapServerCatalogItem.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( s => true, ArcGisFeatureServerCatalogItem.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( s => true, ArcGisFeatureServerCatalogGroup.type, true diff --git a/lib/ReactViews/DragDropNotification.jsx b/lib/ReactViews/DragDropNotification.jsx index 66ce957638c..be7c368c3b0 100644 --- a/lib/ReactViews/DragDropNotification.jsx +++ b/lib/ReactViews/DragDropNotification.jsx @@ -45,13 +45,12 @@ class DragDropNotification extends React.Component { componentWillUnmount() { clearTimeout(this.notificationTimeout); - this.lastUploadedFilesReaction() + this.lastUploadedFilesReaction(); } handleHover() { // reset timer on hover clearTimeout(this.notificationTimeout); - } handleMouseLeave() { @@ -86,8 +85,8 @@ class DragDropNotification extends React.Component { {fileNames} {'"'} {" "} - {this.props.viewState.lastUploadedFiles.length > 1 ? "have" : "has"} been added - to My data + {this.props.viewState.lastUploadedFiles.length > 1 ? "have" : "has"}{" "} + been added to My data ); diff --git a/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx b/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx index 2b894cdf1a4..0d34d0d027a 100644 --- a/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx +++ b/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx @@ -7,8 +7,8 @@ import combine from "terriajs-cesium/Source/Core/combine"; import { terriaTheme } from "./StandardTheme"; import arrayContains from "../../Core/arrayContains"; import Branding from "../SidePanel/Branding"; -import DragDropFile from '../DragDropFile'; -import DragDropNotification from './../DragDropNotification'; +import DragDropFile from "../DragDropFile"; +import DragDropNotification from "./../DragDropNotification"; import ExplorerWindow from "../ExplorerWindow/ExplorerWindow"; import FeatureInfoPanel from "../FeatureInfo/FeatureInfoPanel"; import FeedbackForm from "../Feedback/FeedbackForm"; @@ -356,12 +356,10 @@ const StandardUserInterface = observer( /> - + terria={this.props.terria} + viewState={this.props.viewState} + /> + {showStoryPanel && ( )} diff --git a/test/Models/TerriaSpec.ts b/test/Models/TerriaSpec.ts index b14bd07bf69..fb947b71407 100644 --- a/test/Models/TerriaSpec.ts +++ b/test/Models/TerriaSpec.ts @@ -11,7 +11,7 @@ import { BaseModel } from "../../lib/Models/Model"; import { runInAction } from "mobx"; import ImagerySplitDirection from "terriajs-cesium/Source/Scene/ImagerySplitDirection"; import UrlReference from "../../lib/Models/UrlReference"; -import createCatalogItemFromUrl from "../../lib/Models/createCatalogItemFromUrl"; +import createUrlReferenceFromUrl from "../../lib/Models/createUrlReferenceFromUrl"; import SimpleCatalogItem from "../Helpers/SimpleCatalogItem"; import PickedFeatures from "../../lib/Map/PickedFeatures"; import Feature from "../../lib/Models/Feature"; @@ -47,7 +47,7 @@ describe("Terria", function() { ); CatalogMemberFactory.register(UrlReference.type, UrlReference); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( s => true, WebMapServiceCatalogItem.type, true diff --git a/test/Models/createCatalogItemFromUrlSpec.ts b/test/Models/createCatalogItemFromUrlSpec.ts index 57148c3e61f..b8e7f581689 100644 --- a/test/Models/createCatalogItemFromUrlSpec.ts +++ b/test/Models/createCatalogItemFromUrlSpec.ts @@ -1,12 +1,12 @@ import Terria from "../../lib/Models/Terria"; -import createCatalogItemFromUrl from "../../lib/Models/createCatalogItemFromUrl"; +import createUrlReferenceFromUrl from "../../lib/Models/createUrlReferenceFromUrl"; import WebMapServiceCatalogGroup from "../../lib/Models/WebMapServiceCatalogGroup"; import GeoJsonCatalogItem from "../../lib/Models/GeoJsonCatalogItem"; import CatalogMemberFactory from "../../lib/Models/CatalogMemberFactory"; import { matchesExtension } from "../../lib/Models/registerCatalogMembers"; import UrlReference from "../../lib/Models/UrlReference"; -describe("createCatalogItemFromUrl", function() { +describe("createUrlReferenceFromUrl", function() { let terria: Terria; beforeEach(function() { @@ -19,12 +19,12 @@ describe("createCatalogItemFromUrl", function() { CatalogMemberFactory.register(GeoJsonCatalogItem.type, GeoJsonCatalogItem); CatalogMemberFactory.register(UrlReference.type, UrlReference); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( s => true, WebMapServiceCatalogGroup.type, true ); - createCatalogItemFromUrl.register( + createUrlReferenceFromUrl.register( matchesExtension("geojson"), GeoJsonCatalogItem.type, true @@ -33,7 +33,7 @@ describe("createCatalogItemFromUrl", function() { it("should create an item of the first registered type", function(done) { const url = "test/WMS/single_metadata_url.xml"; - createCatalogItemFromUrl(url, terria, true).then(item => { + createUrlReferenceFromUrl(url, terria, true).then(item => { expect(item).toBeDefined(); if (item !== undefined) { @@ -49,7 +49,7 @@ describe("createCatalogItemFromUrl", function() { it("should create an item of the second registered type", function(done) { const url = "test/geoJSON/bike_racks.geojson"; - createCatalogItemFromUrl(url, terria, true).then(item => { + createUrlReferenceFromUrl(url, terria, true).then(item => { expect(item).toBeDefined(); if (item !== undefined) { expect(item instanceof UrlReference).toBe(true); From 2803409042db10b22223acd0f8aa45343f37528f Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Fri, 17 Apr 2020 17:31:52 +1000 Subject: [PATCH 5/8] add tests for createCatalogItemFromFileOrUrl --- lib/Models/addUserFiles.ts | 2 +- lib/Models/createCatalogItemFromFileOrUrl.ts | 6 +-- test/Models/createCatalogItemFromUrlSpec.ts | 50 ++++++++++++++++++-- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/lib/Models/addUserFiles.ts b/lib/Models/addUserFiles.ts index e5ec054312b..7109e4db1d4 100644 --- a/lib/Models/addUserFiles.ts +++ b/lib/Models/addUserFiles.ts @@ -11,7 +11,7 @@ import TerriaError from "../Core/TerriaError"; import isDefined from "../Core/isDefined"; interface FileType { - value: String; + value: string; } export default function addUserFiles( diff --git a/lib/Models/createCatalogItemFromFileOrUrl.ts b/lib/Models/createCatalogItemFromFileOrUrl.ts index cfc7e32fca4..f09929d0ea6 100644 --- a/lib/Models/createCatalogItemFromFileOrUrl.ts +++ b/lib/Models/createCatalogItemFromFileOrUrl.ts @@ -2,7 +2,6 @@ import i18next from "i18next"; import { runInAction } from "mobx"; import isDefined from "../Core/isDefined"; import TerriaError from "../Core/TerriaError"; -import CatalogMemberMixin from "../ModelMixins/CatalogMemberMixin"; import ViewState from "../ReactViewModels/ViewState"; import CatalogMemberFactory from "./CatalogMemberFactory"; import CommonStrata from "./CommonStrata"; @@ -10,15 +9,14 @@ import createUrlReferenceFromUrl from "./createUrlReferenceFromUrl"; import { BaseModel } from "./Model"; import Terria from "./Terria"; import upsertModelFromJson from "./upsertModelFromJson"; -import UrlReference from "./UrlReference"; import ReferenceMixin from "../ModelMixins/ReferenceMixin"; export default function createCatalogItemFromFileOrUrl( terria: Terria, viewState: ViewState, fileOrUrl: File | string, - dataType: any, - confirmConversion: boolean + dataType?: string, + confirmConversion: boolean = false ): Promise { dataType = isDefined(dataType) ? dataType : "auto"; diff --git a/test/Models/createCatalogItemFromUrlSpec.ts b/test/Models/createCatalogItemFromUrlSpec.ts index b8e7f581689..2371d5e4087 100644 --- a/test/Models/createCatalogItemFromUrlSpec.ts +++ b/test/Models/createCatalogItemFromUrlSpec.ts @@ -5,9 +5,13 @@ import GeoJsonCatalogItem from "../../lib/Models/GeoJsonCatalogItem"; import CatalogMemberFactory from "../../lib/Models/CatalogMemberFactory"; import { matchesExtension } from "../../lib/Models/registerCatalogMembers"; import UrlReference from "../../lib/Models/UrlReference"; +import CsvCatalogItem from "../../lib/Models/CsvCatalogItem"; +import ViewState from "../../lib/ReactViewModels/ViewState"; +import createCatalogItemFromFileOrUrl from "../../lib/Models/createCatalogItemFromFileOrUrl"; describe("createUrlReferenceFromUrl", function() { let terria: Terria; + let viewState: ViewState; beforeEach(function() { terria = new Terria(); @@ -17,6 +21,7 @@ describe("createUrlReferenceFromUrl", function() { WebMapServiceCatalogGroup ); CatalogMemberFactory.register(GeoJsonCatalogItem.type, GeoJsonCatalogItem); + CatalogMemberFactory.register(CsvCatalogItem.type, CsvCatalogItem); CatalogMemberFactory.register(UrlReference.type, UrlReference); createUrlReferenceFromUrl.register( @@ -24,14 +29,19 @@ describe("createUrlReferenceFromUrl", function() { WebMapServiceCatalogGroup.type, true ); + createUrlReferenceFromUrl.register( matchesExtension("geojson"), - GeoJsonCatalogItem.type, - true + GeoJsonCatalogItem.type + ); + + createUrlReferenceFromUrl.register( + matchesExtension("csv"), + CsvCatalogItem.type ); }); - it("should create an item of the first registered type", function(done) { + it("should create an item of the first registered type (WMSGroup)", function(done) { const url = "test/WMS/single_metadata_url.xml"; createUrlReferenceFromUrl(url, terria, true).then(item => { expect(item).toBeDefined(); @@ -46,7 +56,7 @@ describe("createUrlReferenceFromUrl", function() { }); }); - it("should create an item of the second registered type", function(done) { + it("should create an item of the second registered type (GeoJSON)", function(done) { const url = "test/geoJSON/bike_racks.geojson"; createUrlReferenceFromUrl(url, terria, true).then(item => { @@ -60,4 +70,36 @@ describe("createUrlReferenceFromUrl", function() { done(); }); }); + + it("should create an catalog item (CSVCatalogItem) from Url without specifying a dataType", function(done) { + const url = "test/csv/lat_lon_val.csv"; + + createCatalogItemFromFileOrUrl(terria, viewState, url).then(item => { + expect(item).toBeDefined(); + if (item !== undefined) { + expect(item instanceof CsvCatalogItem).toBe(true); + } + done(); + }); + }); + + it("should create an catalog item (CSVCatalogItem) from File (csv) without specifying a dataType", function(done) { + const fileUrl = "test/csv/lat_lon_val.csv"; + + fetch(fileUrl) + .then(res => res.blob()) + .then(blob => { + let file: File = Object.assign(blob, { + lastModified: 0, + name: "lat_lon_val.csv" + }); + createCatalogItemFromFileOrUrl(terria, viewState, file).then(item => { + expect(item).toBeDefined(); + if (item !== undefined) { + expect(item instanceof CsvCatalogItem).toBe(true); + } + done(); + }); + }); + }); }); From d960b3643aee689e46511e70521c16e3cfd4bc73 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Fri, 17 Apr 2020 17:34:37 +1000 Subject: [PATCH 6/8] update changes.md --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f51a0c53dd9..d3d813e6b5a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ Change Log ========== ### MobX Development + +* Fixed DragDropFile and `createCatalogItemFromFileOrUrl` which wasn't enabled/working in mobx, added tests for `createCatalogItemFromFileOrUrl` and renamed `createCatalogItemFromUrl` to `createUrlRefernceFromUrl`. * Fixed bug in StratumOrder where `sortBottomToTop` would sort strata in the wrong order. * Allow member re-ordering via GroupMixin's `moveMemberToIndex` * Fixed a bug where `updateModelFromJson` would ignore its `replaceStratum` parameter. From 2393f8387d2c3f89bcce8cc36f288f729b8d8b6a Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Fri, 17 Apr 2020 18:27:07 +1000 Subject: [PATCH 7/8] remove unused param --- lib/Models/createUrlReferenceFromUrl.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Models/createUrlReferenceFromUrl.ts b/lib/Models/createUrlReferenceFromUrl.ts index ec5e548adc8..21a6eefe836 100644 --- a/lib/Models/createUrlReferenceFromUrl.ts +++ b/lib/Models/createUrlReferenceFromUrl.ts @@ -7,8 +7,7 @@ import UrlReference from "./UrlReference"; export default function createUrlReferenceFromUrl( url: string, terria: Terria, - allowLoad: boolean, - _index?: number + allowLoad: boolean ): Promise { const item = upsertModelFromJson( CatalogMemberFactory, From 2d9e8d6396225b0427cb3c3ee79c926d88f8bda8 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Mon, 20 Apr 2020 11:10:27 +1000 Subject: [PATCH 8/8] fixed test --- lib/Core/loadBlob.ts | 2 +- test/Models/createCatalogItemFromUrlSpec.ts | 27 ++++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/Core/loadBlob.ts b/lib/Core/loadBlob.ts index 7c67443e41e..dfacd1d8ff4 100644 --- a/lib/Core/loadBlob.ts +++ b/lib/Core/loadBlob.ts @@ -3,7 +3,7 @@ import Resource from "terriajs-cesium/Source/Core/Resource"; export default function loadBlob( urlOrResource: string, - headers: any + headers?: any ): Promise { return makeRealPromise( Resource.fetchBlob({ url: urlOrResource, headers: headers }) diff --git a/test/Models/createCatalogItemFromUrlSpec.ts b/test/Models/createCatalogItemFromUrlSpec.ts index 2371d5e4087..5b63ded6cdf 100644 --- a/test/Models/createCatalogItemFromUrlSpec.ts +++ b/test/Models/createCatalogItemFromUrlSpec.ts @@ -8,6 +8,7 @@ import UrlReference from "../../lib/Models/UrlReference"; import CsvCatalogItem from "../../lib/Models/CsvCatalogItem"; import ViewState from "../../lib/ReactViewModels/ViewState"; import createCatalogItemFromFileOrUrl from "../../lib/Models/createCatalogItemFromFileOrUrl"; +import loadBlob from "../../lib/Core/loadBlob"; describe("createUrlReferenceFromUrl", function() { let terria: Terria; @@ -86,20 +87,18 @@ describe("createUrlReferenceFromUrl", function() { it("should create an catalog item (CSVCatalogItem) from File (csv) without specifying a dataType", function(done) { const fileUrl = "test/csv/lat_lon_val.csv"; - fetch(fileUrl) - .then(res => res.blob()) - .then(blob => { - let file: File = Object.assign(blob, { - lastModified: 0, - name: "lat_lon_val.csv" - }); - createCatalogItemFromFileOrUrl(terria, viewState, file).then(item => { - expect(item).toBeDefined(); - if (item !== undefined) { - expect(item instanceof CsvCatalogItem).toBe(true); - } - done(); - }); + loadBlob(fileUrl).then(blob => { + let file: File = Object.assign(blob, { + lastModified: 0, + name: "lat_lon_val.csv" }); + createCatalogItemFromFileOrUrl(terria, viewState, file).then(item => { + expect(item).toBeDefined(); + if (item !== undefined) { + expect(item instanceof CsvCatalogItem).toBe(true); + } + done(); + }); + }); }); });