Skip to content

Commit

Permalink
Simplify how we detect app version, and include the info on more pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Sep 15, 2023
1 parent a34f163 commit 021b953
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 49 deletions.
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Names and regions should match above.

1. Update `GCS_BUCKET` in `backend/app.yaml`
2. Run `gcloud projects describe $PROJECT | grep projectNumber` and use the result to update `PROJECT_NUMBER` in `backend/app.yaml`
3. Create the files to deploy: `VITE_ON_GCP="true" VITE_RESOURCE_BASE="https://$PROJECT.ew.r.appspot.com/data" npm run build && cd backend && rm -rf dist && cp -R ../dist .`
3. Create the files to deploy: `VITE_RESOURCE_BASE="https://$PROJECT.ew.r.appspot.com/data" npm run build && cd backend && rm -rf dist && cp -R ../dist .`
- Note we could make Cloud Build do this, but we'd have to get `wasm-pack` and other things set up there first
- GH Actions will eventually trigger CI deployments for our test environment, and we've already done the work of configuring that build environment
4. `gcloud app --project=$PROJECT deploy --quiet` (takes a minute or two)
Expand Down
21 changes: 3 additions & 18 deletions src/lib/browse/AppVersion.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
<script lang="ts">
import { HelpButton } from "lib/common";
import { appVersion, HelpButton } from "lib/common";
let version = "unknown";
if (window.location.hostname == "localhost") {
version = "Local development";
} else if (window.location.hostname == "acteng.github.io") {
if (window.location.pathname == "/atip/browse.html") {
version = "Current development (public)";
} else {
let parts = window.location.pathname.split("/");
if (parts.length == 4 && parts[1] == "atip") {
version = `Development branch: ${parts[2]}`;
}
}
} else if (window.location.hostname.endsWith(".appspot.com")) {
// TODO Include a git commit, build timestamp, or similar
version = "Test (on GCP)";
}
let version = appVersion();
</script>

<p>
Expand All @@ -33,7 +18,7 @@
Please contact <a href="mailto:dcarlino@turing.ac.uk">Dustin</a>
and
<a href="mailto:Peter.York@activetravelengland.gov.uk">Pete</a>
about any problems, ideas, or feedback for this site.
about any problems, ideas, or feedback for this site.
</p>
</HelpButton>
</p>
14 changes: 0 additions & 14 deletions src/lib/browse/LoggedIn.svelte

This file was deleted.

17 changes: 17 additions & 0 deletions src/lib/common/LoggedIn.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script lang="ts">
import Cookies from "js-cookie";
import { appVersion } from "lib/common";
import { ErrorMessage } from "lib/govuk";
let email = Cookies.get("email");
</script>

{#if appVersion() == "Test (on GCP)"}
{#if email}
<p>Logged in as {email}</p>
{:else}
<ErrorMessage
errorMessage="You shouldn't be able to view this app without being logged in!"
/>
{/if}
{/if}
9 changes: 0 additions & 9 deletions src/lib/common/data_getter.ts

This file was deleted.

30 changes: 30 additions & 0 deletions src/lib/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { FeatureCollection, Polygon } from "geojson";
import authoritiesUrl from "../../../assets/authorities.geojson?url";

export { default as BaselayerSwitcher } from "./BaselayerSwitcher.svelte";
export { default as CollapsibleCard } from "./CollapsibleCard.svelte";
export { default as ColorLegend } from "./ColorLegend.svelte";
Expand All @@ -9,7 +12,34 @@ export { default as HelpButton } from "./HelpButton.svelte";
export { default as InteractiveLayer } from "./InteractiveLayer.svelte";
export { default as Layout } from "./Layout.svelte";
export { default as Legend } from "./Legend.svelte";
export { default as LoggedIn } from "./LoggedIn.svelte";
export { default as MapLibreMap } from "./MapLibreMap.svelte";
export { default as Modal } from "./Modal.svelte";
export { default as StreetViewController } from "./StreetViewController.svelte";
export { default as ZoomOutMap } from "./ZoomOutMap.svelte";

export async function getAuthoritiesGeoJson(): Promise<
FeatureCollection<Polygon>
> {
const resp = await fetch(authoritiesUrl);
return await resp.json();
}

export function appVersion(): string {
if (window.location.hostname == "localhost") {
return "Local development";
} else if (window.location.hostname == "acteng.github.io") {
let parts = window.location.pathname.split("/");
if (parts.length == 3 && parts[0] == "" && parts[1] == "atip") {
return "Current development (public)";
}
if (parts.length == 4 && parts[0] == "" && parts[1] == "atip") {
return `Development branch: ${parts[2]}`;
}
} else if (window.location.hostname.endsWith(".appspot.com")) {
// TODO Include a git commit, build timestamp, or similar
return "Test (on GCP)";
}

return "Unknown";
}
6 changes: 5 additions & 1 deletion src/pages/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import type { FeatureCollection, Polygon } from "geojson";
import BoundaryLayer from "lib/BoundaryLayer.svelte";
import {
appVersion,
BaselayerSwitcher,
CollapsibleCard,
getAuthoritiesGeoJson,
Layout,
Legend,
LoggedIn,
MapLibreMap,
ZoomOutMap,
} from "lib/common";
import { getAuthoritiesGeoJson } from "lib/common/data_getter";
import HoverLayer from "lib/draw/HoverLayer.svelte";
import InterventionLayer from "lib/draw/InterventionLayer.svelte";
import Toolbox from "lib/draw/Toolbox.svelte";
Expand Down Expand Up @@ -115,6 +117,8 @@
Instructions
</SecondaryButton>
</div>
<p>App version: {appVersion()}</p>
<LoggedIn />
<p>{schemaTitle(schema)} mode</p>
<div style="display: flex; justify-content: space-between">
<h1>{authorityName}</h1>
Expand Down
7 changes: 4 additions & 3 deletions src/pages/BrowseSchemes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import Filters from "lib/browse/Filters.svelte";
import LayerControls from "lib/browse/LayerControls.svelte";
import LoadRemoteSchemeData from "lib/browse/LoadRemoteSchemeData.svelte";
import LoggedIn from "lib/browse/LoggedIn.svelte";
import SchemeCard from "lib/browse/SchemeCard.svelte";
import authorityNamesList from "../../assets/authority_names.json";
import "../style/main.css";
import {
appVersion,
FileInput,
InteractiveLayer,
Layout,
LoggedIn,
MapLibreMap,
ZoomOutMap,
} from "lib/common";
Expand Down Expand Up @@ -96,9 +97,9 @@
<ZoomOutMap boundaryGeojson={$gjScheme} />
</div>
<AppVersion />
{#if import.meta.env.VITE_ON_GCP === "true"}
<LoggedIn />
{#if appVersion() == "Test (on GCP)"}
<LoadRemoteSchemeData {loadFile} />
<LoggedIn />
{/if}
<FileInput label="Load schemes from GeoJSON" id="load-geojson" {loadFile} />
<ErrorMessage {errorMessage} />
Expand Down
7 changes: 5 additions & 2 deletions src/pages/ChooseArea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import { Map, type MapGeoJSONFeature } from "maplibre-gl";
import { onMount } from "svelte";
import "maplibre-gl/dist/maplibre-gl.css";
import { FileInput, InteractiveLayer } from "lib/common";
import { getAuthoritiesGeoJson } from "lib/common/data_getter";
import {
FileInput,
getAuthoritiesGeoJson,
InteractiveLayer,
} from "lib/common";
import { bbox, hoveredToggle } from "lib/maplibre";
import About from "lib/sidebar/About.svelte";
import { map as mapStore } from "stores";
Expand Down
10 changes: 9 additions & 1 deletion src/pages/CriticalIssueEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import "../style/main.css";
import type { LngLat } from "maplibre-gl";
import { onMount } from "svelte";
import { Layout, MapLibreMap, StreetViewController } from "../lib/common";
import {
appVersion,
Layout,
LoggedIn,
MapLibreMap,
StreetViewController,
} from "../lib/common";
import BaselayerSwitcher from "../lib/critical_entry/BaselayerSwitcher.svelte";
import Form from "../lib/critical_entry/Form.svelte";
import Pin from "../lib/critical_entry/Pin.svelte";
Expand All @@ -30,6 +36,8 @@
<Layout sidebarWidth="35rem">
<div slot="sidebar" class="govuk-prose">
<h1>Critical issue entry</h1>
<p>App version: {appVersion()}</p>
<LoggedIn />
{#if markerPosition}
<Form pt={markerPosition} />
{:else}
Expand Down

0 comments on commit 021b953

Please sign in to comment.