-
Notifications
You must be signed in to change notification settings - Fork 363
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
[#5008] More granular control over tools/panels #5131
[#5008] More granular control over tools/panels #5131
Conversation
Hi @smotornyuk I didn't have much time to look into this in detail, but I like the idea behind this. I am wondering how will this play with the option to specify another version of catalog init file (extend it or completely replace it) in the URL which one will take effect (if the administrator doesn't want to have some button active, end-user shouldn't have an option to override that setting - unless there is also catalog option which can't be changed). Some other things that should be taken into account, mainly working on making the navigation more accessible and easier to integrate new buttons, especially #5020, #5062, and discussion in #4085. I expect it to be much easier to implement more general visibility control with that, at least for the navigation bar. Also, there is an initiative of making terriajs work as a multitenant solution, but I don't know how it is going to work. Let's see what TerriaJS team says about this. |
Hey @smotornyuk. I really like the idea of this PR. I'll do a full code review of this hopefully tomorrow. In response to your questions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @smotornyuk. Thanks for the PR. I think Terria.elements
is only not reactive due to limits of MobX v4 (see the dot point about MobX 4 in MobX object
docs if you're interested). It should be reactive if you switch to using an ObservableMap
.
Other than that I've added some suggestions for small improvements to change/discuss.
lib/Models/Terria.ts
Outdated
@@ -175,6 +176,9 @@ export default class Terria { | |||
readonly timelineClock = new Clock({ shouldAnimate: false }); | |||
// readonly overrides: any = overrides; // TODO: add options.functionOverrides like in master | |||
|
|||
@observable | |||
readonly elements = new ElementsConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of an object this should be an ObservableMap
:
readonly elements = new ElementsConfig(); | |
readonly elements = new observable.map<String, IElementConfig>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this way it works as expected
lib/Models/Terria.ts
Outdated
@@ -822,6 +826,10 @@ export default class Terria { | |||
this.catalog.group.addMembersFromJson(stratumId, initData.catalog); | |||
} | |||
|
|||
if (isJsonObject(initData.elements)) { | |||
Object.assign(this.elements, initData.elements); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you agree with suggestion to use an ObservableMap
, you can use the MobX function ObservableMap.merge
:
Object.assign(this.elements, initData.elements); | |
this.elements.merge(initData.elements); |
lib/ReactViews/Map/MapNavigation.jsx
Outdated
<ZoomControl terria={this.props.terria} /> | ||
<ZoomControl | ||
terria={this.props.terria} | ||
elementConfig={this.props.terria.elements["zoom"]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will become this.props.terria.elements.get("zoom")
if you use a Map.
function VisibilitySwitch(props) { | ||
const isVisible = props.elementConfig ? props.elementConfig.visible : true; | ||
return isVisible ? <Component {...props} /> : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be written as:
function VisibilitySwitch(props) { | |
const isVisible = props.elementConfig ? props.elementConfig.visible : true; | |
return isVisible ? <Component {...props} /> : null; | |
function VisibilitySwitch({ elementConfig, ...props }) { | |
const isVisible = elementConfig ? elementConfig.visible : true; | |
return isVisible ? <Component {...props} /> : null; |
to avoid passing elementConfig
as a prop to inner component
@@ -0,0 +1,22 @@ | |||
import React from "react"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should be moved to HOCs
Hey, @steve9164 we also like the idea of introducing more controls of navigation items but I am still more into introducing the navigation model component that would control all navigation items. It would probably reduce the complexity of the component rendering, and also force us to have all of the controls for the new navigation item. The one written in #5062 is just a quickly written prototype for a client on how it could look and work (the basic idea is taken from vs code models), and I am aware that some parts of it should go through a rewrite and extended on menu bar. The nav model also might be connected to Stratum and Traits system so we benefit from multiple layers of configurability. We should probably separate it into two parts one just to introduce the model, and then grouping of items on smaller screens. If you agree with proposed and @smotornyuk is interested and have time I will be happy to let him take it over. |
Hey @zoran995. I think you're right. It would be beneficial to have the navigation controls framework reviewed before merging this. I'll give it a review this week. |
@steve9164, thank you for review. I'm not sure about this place - i had to extend type with
|
@steve9164 this will need to be checked and merged by 12-13 April max; the dashboard depending on it will be launched mid April and it needs a couple of days to test the data etc etc |
Add ability to hide different buttons\panels using init files
Fixes #5008
This PR adds a new wrapper
visibilitySwitch
that conditionally renders elements depending on their configuration from init-file. Inside init-file, user can add newelements
sections that looks like the following:Later these config objects are passed by-name into corresponding elements(buttons, panels), and depending on the
visible
flag they either rendered or not. This is a rather hot-fix and I want to provide a more elegant solution, but it requires more essential changes. Here a few points that are not completely clear to me:Terria
instance. How to make it reactive, so that it updates every time user changes init file(for example, retypes#<INIT>
part of the URL). Right now only initial values, that were available at load time are appliedMapIconButton
, all others are using a unique way of rendering.terria/viewState
config object through context so that it will be possible to access it using hooks inside any component?visibilitySwitch
from the conceptual point of view? Maybe,HOCs
?Checklist