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

Finalise shareKeys #5055

Merged
merged 32 commits into from
Dec 16, 2020
Merged

Finalise shareKeys #5055

merged 32 commits into from
Dec 16, 2020

Conversation

nf-s
Copy link
Contributor

@nf-s nf-s commented Dec 3, 2020

Finalise shareKeys

Fixes ##4774

See https://github.com/TerriaJS/terriajs/blob/next/architecture/0005-root-group-ids-and-shareKeys.md for background

V7 catalog support

Partially fixes #4897

This replaces https://github.com/TerriaJS/terrace/pull/158

Adds v7initializationUrls to terria config. It will convert catalogs to v8 and print messages to console.

For example:

    {
      "v7initializationUrls": [
        "https://raw.githubusercontent.com/GeoscienceAustralia/dea-config/master/dev/terria/dea-maps.json",
        "https://maps.dea.ga.gov.au/init/terria-cube.json"
      ]
    },

ShareKeys support for root group of Magda map config

To map map-config-de-australia to the root group (now "/") you can add a shareKey like so:

{
  "aspects": {
    "terria": {
      "id": "map-config-de-australia",
      "shareKeys": [
        "map-config-de-australia"
      ],
      "type": "group"
    },
    ...
  },
  "id": "map-config-de-australia",
  ...
}

ShareKeys support for dynamic groups

See ADR for more info - https://github.com/TerriaJS/terriajs/blob/77a25b6967281e1f6189ccf54d77b2974730d4e1/architecture/0006-dynamic-groups-and-shareKeys.md

Change how WMS group sets id for items

To mimic v7. See https://github.com/TerriaJS/terriajs/blob/77a25b6967281e1f6189ccf54d77b2974730d4e1/architecture/0006-dynamic-groups-and-shareKeys.md#wms-group

Other small changes

  • Added InitDataPromise to InitSources
  • Add reverse modelIdShareKeysMap map - model.id -> shareKeys
  • Reverted Legend use of object instead of img - sometimes it was showing html error responses
  • Legend will now hide if an error is thrown

Checklist

  • Add test for magda map config shareKeys
  • Add test for GroupMixin shareKeys
  • Add test for v7 catalog
  • I've updated CHANGES.md with what I changed.

@nf-s nf-s changed the title add v7 catalog support through v7initializationUrls (FIXED) Finalise shareKeys Dec 9, 2020
Comment on lines +30 to +38
export function isInitDataPromise(
initSource: InitSource
): initSource is InitDataPromise {
return (
initSource &&
Object.prototype.toString.call(initSource) === "[object 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.

Used for v7-v8 catalog converting

Comment on lines -29 to +33
addedByUser(
<BaseModel>catalogMember.terria.getModelById(BaseModel, containerId),
{ depth: depth + 1 }
)
addedByUser(catalogMember.terria.getModelById(BaseModel, containerId), {
depth: depth + 1
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed bad <BaseModel> typing here

@@ -1026,7 +1051,8 @@ export default class Terria {
let existingReference = this.getModelById(MagdaReference, id);
if (existingReference === undefined) {
existingReference = new MagdaReference(id, this);
this.addModel(existingReference);
// Add model with terria aspects shareKeys
this.addModel(existingReference, aspects?.terria?.shareKeys);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For magda root group sharekeys

Comment on lines 1234 to 1260
const loadInitSource = createTransformer(
(initSource: InitSource): Promise<JsonObject | undefined> => {
let promise: Promise<JsonValue | undefined>;

async (initSource: InitSource): Promise<JsonObject | undefined> => {
let jsonValue: JsonValue | undefined;
if (isInitUrl(initSource)) {
promise = loadJson5(initSource.initUrl);
jsonValue = await loadJson5(initSource.initUrl);
} else if (isInitOptions(initSource)) {
promise = initSource.options.reduce((previousOptionPromise, option) => {
return previousOptionPromise
.then(json => {
if (json === undefined) {
return loadInitSource(option);
}
return json;
})
.catch(_ => {
await initSource.options.reduce(async (previousOptionPromise, option) => {
try {
const json = await previousOptionPromise;
if (json === undefined) {
return loadInitSource(option);
});
}
return json;
} catch (_) {
return loadInitSource(option);
}
}, Promise.resolve<JsonObject | undefined>(undefined));
} else {
promise = Promise.resolve(initSource.data);
} else if (isInitData(initSource)) {
jsonValue = initSource.data;
} else if (isInitDataPromise(initSource)) {
jsonValue = (await initSource).data;
}

return promise.then(jsonValue => {
if (isJsonObject(jsonValue)) {
return jsonValue;
}
return undefined;
});
if (jsonValue && isJsonObject(jsonValue)) {
return jsonValue;
}
return undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Asyncified + added support for InitDataPromise - which is just a Promise which resolves to InitData

Copy link
Member

Choose a reason for hiding this comment

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

Still reviewing this

@nf-s nf-s marked this pull request as draft December 10, 2020 00:58
@@ -288,7 +288,7 @@ class GetCapabilitiesStratum extends LoadableStratum(
if (!isDefined(this.catalogGroup.uniqueId)) {
return;
}
return `${this.catalogGroup.uniqueId}/${layer.Name || layer.Title}`;
return `${this.catalogGroup.uniqueId}/${layer.Title}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revert WMS id to match v7

@nf-s nf-s marked this pull request as ready for review December 11, 2020 01:21
Comment on lines -52 to 73
// If we legends need scaling, this is the only way to do it :/
// See https://stackoverflow.com/questions/7699621/display-image-at-50-of-its-native-size
// or https://stackoverflow.com/questions/35711807/display-high-dpi-image-at-50-scaling-using-just-css
resizeLegendImage(
evt: SyntheticEvent<HTMLObjectElement>,
onImageLoad(
evt: SyntheticEvent<HTMLImageElement>,
legend: Model<LegendTraits>
) {
if (!isDefined(legend.imageScaling) || legend.imageScaling === 1) return;
const image = evt.target as HTMLObjectElement;
image.style.display = "none";
image.style.maxWidth = "none";

image.style.width = `${legend.imageScaling * image.offsetWidth}px`;
if (evt.type === "error") {
return;
}

image.style.display = "initial";

// If legend need scaling, this is the only way to do it :/
// See https://stackoverflow.com/questions/7699621/display-image-at-50-of-its-native-size
// or https://stackoverflow.com/questions/35711807/display-high-dpi-image-at-50-scaling-using-just-css

image.style.width = `${(legend.imageScaling ?? 1) * image.offsetWidth}px`;
// Must set maxWidth *after* setting width, as it may change offsetWidth
image.style.maxWidth = "100%";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored this to hide if an image request gives error response.

@@ -58,7 +58,7 @@
"@vx/tooltip": "^0.0.193-alpha.2",
"babel-loader": "^8.0.5",
"babel-plugin-jsx-control-statements": "^4.0.0",
"catalog-converter": "^0.0.2-alpha.3",
"catalog-converter": "^0.0.2-alpha.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nf-s
Copy link
Contributor Author

nf-s commented Dec 15, 2020

nf-s and others added 2 commits December 16, 2020 16:02
Co-authored-by: Stephen Davies <steve9164@gmail.com>
Co-authored-by: Stephen Davies <steve9164@gmail.com>
Comment on lines -210 to +217
// Geoserver fontColor must be a hex value
// enable if we can ensure a dark background
const fontColor = terriaTheme.textLight.split("#")?.[1];
// Geoserver fontColor must be a hex value - use `textLight` theme colour
let fontColor = terriaTheme.textLight.split("#")?.[1];
if (isDefined(fontColor)) {
legendOptions += `;fontColor:0x${
terriaTheme.textLight.split("#")[1]
}`;
// If fontColor is a 3-character hex -> turn into 6
if (fontColor.length === 3) {
fontColor = `${fontColor[0]}${fontColor[0]}${fontColor[1]}${fontColor[1]}${fontColor[2]}${fontColor[2]}`;
}
legendOptions += `;fontColor:0x${fontColor}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If textLight is #fff - Geoserver gives us a blue legend ?!

Copy link
Member

@tephenavies tephenavies left a comment

Choose a reason for hiding this comment

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

Tests pass locally

@tephenavies tephenavies merged commit c71f7de into next Dec 16, 2020
@tephenavies tephenavies deleted the v7-catalog-support-clean branch December 16, 2020 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants