Pin Nav Items: Add tracking for pinned items clicks (#90803)

* Pin Nav Items: Add tracking for pinned items clicks

* Update id

* Simplify onClick logic
This commit is contained in:
Alex Khomenko 2024-07-23 14:58:50 +03:00 committed by GitHub
parent 888417c01b
commit 8966083132
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 4 deletions

View File

@ -49,6 +49,7 @@ const (
NavIDCfgGeneral = "cfg/general"
NavIDCfgPlugins = "cfg/plugins"
NavIDCfgAccess = "cfg/access"
NavIDBookmarks = "bookmarks"
)
type NavLink struct {
@ -70,6 +71,7 @@ type NavLink struct {
PluginID string `json:"pluginId,omitempty"` // (Optional) The ID of the plugin that registered nav link (e.g. as a standalone plugin page)
IsCreateAction bool `json:"isCreateAction,omitempty"`
Keywords []string `json:"keywords,omitempty"`
ParentItem *NavLink `json:"parentItem,omitempty"` // (Optional) The parent item of the nav link
}
func (node *NavLink) Sort() {

View File

@ -168,7 +168,7 @@ func (s *ServiceImpl) GetNavTree(c *contextmodel.ReqContext, prefs *pref.Prefere
treeRoot.AddSection(&navtree.NavLink{
Text: "Bookmarks",
Id: "bookmarks",
Id: navtree.NavIDBookmarks,
Icon: "bookmark",
SortWeight: navtree.WeightBookmarks,
Children: bookmarks,
@ -355,6 +355,7 @@ func (s *ServiceImpl) buildBookmarksNavLinks(prefs *pref.Preference, treeRoot *n
PluginID: item.PluginID,
IsCreateAction: item.IsCreateAction,
Keywords: item.Keywords,
ParentItem: &navtree.NavLink{Id: navtree.NavIDBookmarks},
})
}
}

View File

@ -38,6 +38,7 @@ export const enrichWithInteractionTracking = (item: NavModelItem, megaMenuDocked
reportInteraction('grafana_navigation_item_clicked', {
path: newItem.url ?? newItem.id,
menuIsDocked: megaMenuDockedState,
itemIsBookmarked: Boolean(config.featureToggles.pinNavItems && newItem?.parentItem?.id === 'bookmarks'),
});
onClick?.();
};

View File

@ -59,9 +59,7 @@ const navTreeSlice = createSlice({
const { item, isSaved } = action.payload;
if (bookmarks) {
if (isSaved) {
if (!bookmarks.children) {
bookmarks.children = [];
}
bookmarks.children ||= [];
const newBookmark: NavModelItem = {
...item,
// Clear the children, sortWeight and empty message of the item
@ -69,6 +67,7 @@ const navTreeSlice = createSlice({
sortWeight: 0,
emptyMessageId: '',
emptyMessage: '',
parentItem: { id: bookmarks.id, text: bookmarks.text },
};
bookmarks.children.push(newBookmark);
} else {