-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(edit-dashboard-json): [MTM-61842] As a dashboard user, I want to have a better copy possibility #57
Open
jdre-c8y
wants to merge
17
commits into
main
Choose a base branch
from
feat/MTM-61842-study-ui-as-a-dashboard-user-i-want-to-have-a-better-copy-possibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
Types of changes
Paste Link to the issue
Checklist
Further comments
Validating dashboard and widget
It is possible to create json schema based on interface form ngx-components and then use it to validate objects. For study I only validate dashboard object and KPI widget config.
typescript-json-schema node_ modules/@c8y/ngx-components/widgets/implementations/kpi/kpi-widget.model.d.ts KpiWidgetConfig > src/app/dashboard-json-editor/kpi_config.json --esModuleInterop --required --noExtraProps
typescript-json-schema node_modules/@c8y/ngx-components/context-dashboard/context-dashboard.model.d.ts ContextDashboard > src/app/dashboard-json-editor/dashboard_config.json --esModuleInterop --required --noExtraProps
Making sure context devices are aligned
The challenge is to ensure that devices/groups assigned to dashboard are matching context that dashboard is pasted to. It should be possible to copy dashboard from anywhere, even different tenant, so there might be a case:
you copy from source a dashboard object which links to a device with id 123. It can happen that on the target tenant the same ID exist but it might not even be a device. so the resolver will resolve it successfully but it might not be anyhow near the data needed.
Also, there might be multiple devices assigned to widgets in one dashboard, so we have to handle them all.
Approach 1: using existing paste mechanism
Challenges:
Approach 2:
transform the data on copy, so that you basically not returning pure JSON but instead a JS-function
(context) => { "1233123'" { "name": "Html" "device": { "id": ${context.id} "name": ${context.name} } [...] } };
Approach 3:
Adding some metadata related to sourceTenant (the one we copied from). This way we could check if current tenant is the same as sourceTenant:
Approach 4:
main disadvantage of this is approach is that it it possible that we paste dashboard in context of different tenant and device id assigned to dashboard will exist, but will be different device (or even not device at all)
Approach 5:
change the source linking completely and instead of saving the id/name object we store a query
device: { query: 'inventory/1234' }
This could then be changed for copying to something more
device: { query: 'inventory?type=abcd' supportList: true }
Summary
The most generic and flexible approach is approach 3- idea above can be enhanced:
interface Clipboard = { c8y_Dashboard: ContextDashboard, metadata: { sourceTenant: 't1234' // tenant that we copied from // any other metadata needed } }
if it stays this way, we can just validate it in component/service; if it became more complicated, we can validate it with json schema (See "Validating dashboard and widget" section)
Wizard should be able to be ran later too.
Another case that we would like to handle is when source and target tenant are the same, but user that pastes dashboard might not have inventory role to see some of the devices- we might want to warn user about it and suggest to change __target/device of widget.