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
Merged
ThomThomson
merged 16 commits into
elastic:main
from
ThomThomson:dashboard/managedState
Sep 21, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0216597
Add managed state to Dashboard
ThomThomson a5556ca
fix types
ThomThomson c2e78eb
fix jest test
ThomThomson f555386
fix jest test again
ThomThomson 76acf9d
Merge branch 'main' into dashboard/managedState
kibanamachine 3d25eb1
read only for managed Dashboards in table list view.
ThomThomson ae8210f
omit managed Dashboards from dashboard picker
ThomThomson bcfc7af
block dashboard from entering edit mode when managed
ThomThomson f51b9a7
lock down edit mode when write controls are off. Rename and combine i…
ThomThomson 9d28907
undo module level showWriteControls
ThomThomson ab07806
Merge branch 'main' into dashboard/managedState
kibanamachine 7029844
default isEditable to true
ThomThomson c895a57
check for managed state inside table list view
ThomThomson 4679bb1
make managed state override itemIsEditable
ThomThomson 5cbd79c
Update comment to mention that managed items will always be non-edita…
ThomThomson ed2555d
Merge remote-tracking branch 'upstream/main' into dashboard/managedState
ThomThomson File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,10 +90,12 @@ export interface TableListViewTableProps< | |
* 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. | ||
* Handler to set edit action visiblity, and content editor readonly state per item. If not provided all non-managed items are considered editable. Note: Items with the managed property set to true will always be non-editable. | ||
*/ | ||
showEditActionForItem?(item: T): boolean; | ||
itemIsEditable?(item: T): boolean; | ||
|
||
/** | ||
* Name for the column containing the "title" value. | ||
*/ | ||
|
@@ -144,6 +146,7 @@ export interface State<T extends UserContentCommonSchema = UserContentCommonSche | |
export interface UserContentCommonSchema { | ||
id: string; | ||
updatedAt: string; | ||
managed?: boolean; | ||
references: SavedObjectsReference[]; | ||
type: string; | ||
attributes: { | ||
|
@@ -264,7 +267,7 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({ | |
findItems, | ||
createItem, | ||
editItem, | ||
showEditActionForItem, | ||
itemIsEditable, | ||
deleteItems, | ||
getDetailViewLink, | ||
onClickTitle, | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
(item: T) => { | ||
// If the So is `managed` it is never editable. | ||
if (item.managed) return false; | ||
return itemIsEditable?.(item) ?? true; | ||
}, | ||
[itemIsEditable] | ||
); | ||
|
||
const inspectItem = useCallback( | ||
(item: T) => { | ||
const tags = getTagIdsFromReferences(item.references).map((_id) => { | ||
|
@@ -466,6 +478,7 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({ | |
}, | ||
entityName, | ||
...contentEditor, | ||
isReadonly: contentEditor.isReadonly || !isEditable(item), | ||
onSave: | ||
contentEditor.onSave && | ||
(async (args) => { | ||
|
@@ -476,7 +489,7 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({ | |
}), | ||
}); | ||
}, | ||
[getTagIdsFromReferences, openContentEditor, entityName, contentEditor, fetchItems] | ||
[getTagIdsFromReferences, openContentEditor, entityName, contentEditor, isEditable, fetchItems] | ||
); | ||
|
||
const tableColumns = useMemo(() => { | ||
|
@@ -550,7 +563,7 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({ | |
), | ||
icon: 'pencil', | ||
type: 'icon', | ||
available: (v) => (showEditActionForItem ? showEditActionForItem(v) : true), | ||
available: (item) => isEditable(item), | ||
enabled: (v) => !(v as unknown as { error: string })?.error, | ||
onClick: editItem, | ||
'data-test-subj': `edit-action`, | ||
|
@@ -598,16 +611,16 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({ | |
customTableColumn, | ||
hasUpdatedAtMetadata, | ||
editItem, | ||
contentEditor.enabled, | ||
listingId, | ||
getDetailViewLink, | ||
onClickTitle, | ||
searchQuery.text, | ||
addOrRemoveIncludeTagFilter, | ||
addOrRemoveExcludeTagFilter, | ||
addOrRemoveIncludeTagFilter, | ||
DateFormatterComp, | ||
contentEditor, | ||
isEditable, | ||
inspectItem, | ||
showEditActionForItem, | ||
]); | ||
|
||
const itemsById = useMemo(() => { | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. By default, |
||
} = savedObject; | ||
|
||
return { | ||
id, | ||
type, | ||
managed, | ||
updatedAt, | ||
createdAt, | ||
attributes: pick(attributes, allowedSavedObjectAttributes), | ||
|
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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 initem
? 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.UserContentCommonSchema
isn't necessarily a saved object. We could requireUserContentCommonSchema
to have amanaged?: boolean
fieldreadonly
attribute.We could leave the function as
itemIsEditable
, and also have a default implementation that checksmanaged
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 formanaged
.I would be in favor of adding
managed
toUserContentCommonSchema
. Then the table component can provide consistent behavior formanaged
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
toUserContentCommonSchema
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 toUserContentCommonSchema
.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 whenfindItems
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.
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 existingrowItemActions
(which need to support theedit
action).Thanks for clarifying, I agree then to go with option 2. Could you update the comments on top of the
showEditActionForItem
andeditItem
props to indicate that those will not have any effect if the content item has themanaged
prop set totrue
?Slightly off topic:
Do all SO that have the
managed
prop set totrue
automatically get themanaged
tag (in theirreferences
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 theitemIsEditable
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 hasmanaged
set totrue
.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