Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1757 new routing #3494

Closed
wants to merge 35 commits into from
Closed

1757 new routing #3494

wants to merge 35 commits into from

Conversation

soyarsauce
Copy link
Contributor

@soyarsauce soyarsauce commented Jun 12, 2019

Adds routing such that catalog navigation can be traversed with browser history, and subsequently telling terriajshow to resolve URLs for a given catalog link

A demo of this in action with the 3 separate versions on one deployment is at (VPN required)
http://152.83.140.90:3001/catalog/54a553b4

, if you click into any of the catalog items and hit refresh you’ll see the metadata directly from the initial HTML served up, before javascript takes over and makes the rest of the UI interactive

Sitemap now autogenerated (after specifying appBaseUrl under config.json's parameters object)
http://152.83.140.90:3001/sitemap.xml

Attempts to resolve #1757

Also see:
TerriaJS/terriajs-server#106
TerriaJS/TerriaMap#342

@soyarsauce soyarsauce marked this pull request as ready for review June 26, 2019 00:14
Copy link
Member

@kring kring left a comment

Choose a reason for hiding this comment

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

This is really cool! Mostly nitpicky comments below, but there are some bigger-picture things to discuss as well:

  1. It has long been possible to deploy TerriaMap to a static web server, and we don't want to lose that ability. Does that mean providing an option to turn off the routing? Or making it (optionally?) use the hash portion of the URL instead of the path portion?
  2. The need to specify an appBaseUrl isn't great, and is a breaking change. The Investor Map staging site, for instance, is available at both https://inv-staging.nm.terria.io/ and https://inv-staging.nm.terria.io/investormap/. NEII has something similar happening. Why do we need to know the base URL? I thought it was for the sitemap, but a quick google seems to indicate sitemaps can use relative URLs too.
  3. As mentioned briefly in the comments below, I don't want to see the routing become yet another "source of truth". We need to be clear about where the state (whether catalog is open, which item is selected) comes from. Maybe you are, but it wasn't clear to me while looking at the code.
  4. The mobx branch 😱. There will be conflicts. Some of this will be different there.

lib/ReactViewModels/ViewState.js Outdated Show resolved Hide resolved
lib/ReactViews/ExplorerWindow/ExplorerWindow.jsx Outdated Show resolved Hide resolved
return (
this.props.item.uniqueId ===
URI.decode(this.props.match.params.catalogMemberId)
);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe there's a good reason for this that isn't apparent to me, but it seems to me the UI should determine which catalog item is selected based on the userDataPreviewedItem or the previewedItem properties, just as it did before. Routing should affect the values of those properties as necessary.

When the UI derives its state from multiple (potentially conflicting) places (e.g. routing and the view state), it can quickly get confusing which one is authoritative.

if (!bool && this.location && this.location.pathname !== "/") {
setTimeout(() => {
this.history.push("/");
}, 300);
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need a 300ms delay?

module.exports = DataCatalogItem;
module.exports = {
default: withRouter(DataCatalogItem),
DataCatalogItem: withRouter(DataCatalogItem),
Copy link
Member

Choose a reason for hiding this comment

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

Probably not a huge problem, but if I'm not mistaken calling withRouter twice will create two separate but identical functions. Better to avoid that I think.

@@ -4,7 +4,7 @@ import React from "react";
import createReactClass from "create-react-class";
import PropTypes from "prop-types";
import ObserveModelMixin from "../ObserveModelMixin";
import DataCatalogItem from "./DataCatalogItem.jsx";
import { DataCatalogItem } from "./DataCatalogItem.jsx";
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why you had to change this, since we're also exporting it as default. Maybe use ES exports for DataCatalogItem.jsx instead of mixing CJS and ES?

lib/ReactViews/Preview/DataPreviewMap.jsx Outdated Show resolved Hide resolved
@soyarsauce
Copy link
Contributor Author

Thanks for bringing these up @kring

  • It has long been possible to deploy TerriaMap to a static web server, and we don't want to lose that ability. Does that mean providing an option to turn off the routing? Or making it (optionally?) use the hash portion of the URL instead of the path portion?

We have a couple of options. In fact with the PRs as they are, it is still possible to deploy this new configuration of TerriaMap to a static web server & have it work for basic catalogs that don't query a server for layers - it gets tricky once we start to support that too. I see a few options:

  • extend TerriaMap's new generate-init-routes.js rely on getting a response from the remote services, so that it can query its layers, so we know what other routes to serve up an index.html - but this might be more effort than its worth at the moment given the upcoming changes + seeing how it plays out with magda, & even then it is still kind of separate to the "backendless", "static TerriaMap"
  • depending on how much control a given user has over their "static web server", we simply provide configuration examples for rewriting URLs on common static web servers (apache+/.htaccess, nginx, other)
  • as you said, do some sort of detection or build env variable for routing on browserhistory vs hash, but this is the least ideal situation as we want proper-path-URLs for discoverability (through crawling)
  • The need to specify an appBaseUrl isn't great, and is a breaking change. The Investor Map staging site, for instance, is available at both https://inv-staging.nm.terria.io/ and https://inv-staging.nm.terria.io/investormap/. NEII has something similar happening. Why do we need to know the base URL? I thought it was for the sitemap, but a quick google seems to indicate sitemaps can use relative URLs too.

The appBaseUrl is actually optional & not required - and serves the purpose of

  • the sitemap as you say
  • cross-domain-canonical-references
    Sitemaps can in fact be relative, I thought it wouldn't hurt to help crawlers determine which version of a duplicate deployment to use as the canonical reference. I thought about the case of same deployment to 'different hosts' but not the 'same host+different' path - are those two Investor Map staging-deployments the exact same? What would the benefit of that be?

The new default added to devserverconfig.json for baseHref of "/" is if we served up a TerriaMap that wasn't on root (e.g. on /renewables/), without knowing the baseHref we can't tell the browser the correct place to load build/TerriaMap.js from, and any subsequent relative links (e.g. /renewables/catalog/xyz)

  • As mentioned briefly in the comments below, I don't want to see the routing become yet another "source of truth". We need to be clear about where the state (whether catalog is open, which item is selected) comes from. Maybe you are, but it wasn't clear to me while looking at the code.

I haven't had much success without making the URL the absolute truth for these sort of things, & I tried to 'subscribe' to routing changes via RoutingListener.jsx & update viewState that way, there's certainly more room to make it clearer & I'll revisit that

  • The mobx branch 😱. There will be conflicts. Some of this will be different there.

......yes 😵

# Conflicts:
#	lib/ReactViewModels/ViewState.js
#	lib/ReactViews/DataCatalog/CatalogItem.jsx
#	lib/ReactViews/SidePanel/SidePanel.jsx
#	lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx
#	package.json
#	test/ReactViews/StandardUserInterfaceSpec.jsx
# Conflicts:
#	doc/customizing/client-side-config.md
#	lib/ReactViewModels/ViewState.js
#	lib/ReactViews/DataCatalog/CatalogItem.jsx
#	lib/ReactViews/SidePanel/SidePanel.jsx
#	lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx
#	package.json
#	test/ReactViews/StandardUserInterfaceSpec.jsx
@soyarsauce
Copy link
Contributor Author

At present time this is postponed indefinitely for pre-mobx(mastere), and will be fully re-implemented in mobx.

@soyarsauce
Copy link
Contributor Author

(Barring merging it with even safer defaults of everything-off-by-default)

@soyarsauce soyarsauce mentioned this pull request Sep 3, 2020
2 tasks
@tephenavies
Copy link
Member

Won't be merged/implemented in version 7. PR to implement functionality in version 8 is #4961.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EPIC] SEO: Make datasets findable on search engines
5 participants