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
[Dashboard] Add Readonly State For Managed Dashboards #166204
[Dashboard] Add Readonly State For Managed Dashboards #166204
Conversation
@amyjtechwriter do you have any suggestions for the copy on this badge? It is currently:
In the future we'll likely rename this to @andreadelrio do you think a badge is an alright solution for this? I figured that users in this managed dashboard will never see the unsaved changes badge so it was an okay place to put it. When the user has no write permissions, the glasses icon appears roughly in that spot as well. |
@ThomThomson Thank you for taking LMK if you've got questions with SOs' |
Yeah! Sorry for such a long turnaround on this one, it fell through the cracks. I've been testing with a managed Dashboard that came with the OBLT data - it indeed does have the |
Pinging @elastic/kibana-presentation (Team:Presentation) |
@elasticmachine merge upstream |
All good feedback @nreese!
|
I think that works 👍 |
…temIsEditable methods for tableListView, update jest tests
@elasticmachine merge upstream |
@@ -457,6 +458,8 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({ | |||
return item.references.find(({ id: refId }) => refId === _id) as SavedObjectsReference; | |||
}); | |||
|
|||
const isReadonly = contentEditor.isReadonly || !itemIsEditable?.(item); |
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 don't think !itemIsEditable?.(item)
check is right. This will return true when itemIsEditable
is not provided. Items should not be readonly when itemIsEditable is not provided.
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.
Good catch, fixed this in 7029844
*/ | ||
showEditActionForItem?(item: T): boolean; | ||
itemIsEditable?(item: T): boolean; |
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.
Why is itemIsEditable dashboard implemenation checking for item.managed
? Shouldn't that information already be in item
? So instead of this change, just check that item.managed here instead of making itemIsEditable implemenation do it. This will reduce code duplication.
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.
It made sense to me to unify the callback into one function that determined if the itemIsEditable
for both the edit action + the inspect item action.
- If the table list view gets any more edit functionality in the future, the same function can be reused.
- The generic type
UserContentCommonSchema
isn't necessarily a saved object. We could requireUserContentCommonSchema
to have amanaged?: boolean
field - It allows the implementor to determine for themselves what makes an item readonly or managed etc. For instance, Visualizations have a
readonly
attribute.
We could leave the function as itemIsEditable
, and also have a default implementation that checks managed
state.
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.
The problem with leaving managed
behavior up to each implementation is that will result in inconsistent behavior across Kibana and potential bugs as teams forget to add checks for managed
.
I would be in favor of adding managed
to UserContentCommonSchema
. Then the table component can provide consistent behavior for managed
flag in a single location.
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 can add managed
to UserContentCommonSchema
and check it within the table list view, but it's important to note that it won't automatically make any managed saved objects non-editable. This is because the implementor is also in charge of actually fetching the objects, and mapping them to UserContentCommonSchema
.
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.
Would it make sense to make managed
required? That why tslint would fail when findItems
does not provide a value?
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 prefer option 2.
Wasn't there mention of 'by reference' saved objects in some of the managed dashboards? That would require support for managed saved objects for other types as well. Having a consistent behavior across listing pages would be ideal.
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.
there will be a pattern for this managed state
Are you saying that this is a new top level SO property handled by core available on all saved object? That's great to hear 👍
Sorry about mentioning Drew in my comment above. I went too quick when looking at the line change in the IDE
Regarding the showEditActionForItem
, looking at it again it seems to be a tech debt that we have. It will have to be removed in favor of using the existing rowItemActions
(which need to support the edit
action).
Thanks for clarifying, I agree then to go with option 2. Could you update the comments on top of the showEditActionForItem
and editItem
props to indicate that those will not have any effect if the content item has the managed
prop set to true
?
Slightly off topic:
Do all SO that have the managed
prop set to true
automatically get the managed
tag (in their references
array)?
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.
Okay, I've made the managed
state override the itemIsEditable
callback, and have added a comment to explain that in 4679bb1.
Yes, the managed
state is a new top level SO property handled by core, thanks to @TinaHeiligers for that! And I'm not quite sure how the managed tag appears, but I assume it's more of a holdover from before the new property. Tina would know more.
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.
Thanks. What I meant for the comments is to add that information to the TableListViewTableProps
interface. We want to warn consumers that those props won't have any effect if the SO has managed
set to true
.
// packages/content-management/table_list_view_table/src/table_list_view_table.tsx
...
/**
* Edit action onClick handler. Edit action not provided when property is not provided
*/
editItem?(item: T): void;
/**
* Handler to set edit action visiblity per item.
*/
showEditActionForItem?(item: T): boolean;
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.
Done in 5cbd79c
@@ -69,11 +69,13 @@ function savedObjectToItem<Attributes extends object>( | |||
error, | |||
namespaces, | |||
version, | |||
managed, |
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.
By default, managed
is false. The only way to change to true is to use SO import, with an option with conditions
I also shouldn't be able to add a read-only visualization to a dashboard (see #70461 (comment)). If it's out of scope here, maybe we should create another issue? |
@drewdaemon the way I understand that comment is that if a by reference visualization has a An alternative way we could go about this is by disallowing an edit action on managed visualizations. Either way, I'd say that could be done in a follow-up. Do you know of many |
@ThomThomson thinking about this more I'm not sure it matters whether users add managed assets to unmanaged dashboards as long as each editor enforces save-as functionality. Either way, I'm wondering if an issue to discuss this particular request makes sense?
This approach sounds reasonable, though it might be a bit magical? I think you meant this, but just for clarity, it should be based on the SO prop, not the tag.
I don't think this constraint from the dashboard side is necessary. It's fine for the user to open a managed vis in the editor as long as they save their changes as a new visualization. We will make sure this happens in #166720.
Agreed. Just looking for an issue to track. 👍
472 in the integrations today. We incentivize by-value in the metrics we track but there will always be legitimate cases for by-ref visualizations. In fact, one of the reasons I was given for the reason integrations try to avoid by-ref is the worry that people will edit them. That becomes moot with this effort to prevent editing. |
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.
LGTM
code review and tested in chrome
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.
Code-only review, kbn-content-management-utils
changes LGTM 👍
@@ -451,6 +454,15 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({ | |||
items, | |||
}); | |||
|
|||
const isEditable = useCallback( |
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.
👍
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.
LGTM! Thanks for making all the adjustments in the table list view 👍
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Public APIs missing comments
Async chunks
Unknown metric groupsAPI count
History
To update your PR or re-run it, just comment with: |
Summary
Closes #140364
This PR adds a new
managed
mode to Dashboards. When a user with write permissions opens a managed Dashboard they will be unable to hit theedit
button - and will instead be prompted to clone the Dashboard first.Managed State
The managed state is determined via the new root level
managed
property on the saved object which was added in this PR.Non-Editable
As part of this PR, managed Dashboard should not be editable in any capacity. For managed Dashboards, this PR disallows:
&_a=(viewMode:edit)
Badge
A new badge appears when viewing a managed Dashboard:
Checklist
Delete any items that are not applicable to this PR.