-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Lens] Make breadcrumbs look and feel like Visualize #44258
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,24 @@ function isLocalStateDirty( | |
); | ||
} | ||
|
||
// Exported for testing purposes, sets the Kibana breadcrumbs. | ||
export function setBreadcrumbs( | ||
chrome: { | ||
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. chrome should be well typed by 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. Yeah, but that pulls in a lot of baggage that we aren't using here, and requires a comprehensive mock of Chrome. This is kind of doing the I in SOLID in a way-- preferring narrow, specific interfaces to large, general ones. Hm. But I could do a 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. Turns out it still requires a lot more mocking, at which point, so I think it's worth defining a narrower interface in the function. 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. Last comment... I was only exporting the function for testing purposes in order to avoid the complexity of testing React effects. But Wylie asked me to test the effect, so I just got rid of the function and the point about Chrome is now moot! |
||
addBasePath: (url: string) => string; | ||
breadcrumbs: { set: (crumbs: Array<{ text: string; href?: string }>) => void }; | ||
}, | ||
persistedDoc?: { title: string } | ||
) { | ||
const rootCrumb = { | ||
href: chrome.addBasePath(`/app/kibana#/visualize`), | ||
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. Not sure whether we want to open that can of worms, but you can navigate back to the visualize listing with unsaved changes and lose them because we don't persist to the url. Maps solves this by a browser prompt, either that or a modal would be nice The same thing would apply to navigating away from the page by clicking another app or hitting back, so probably out of scope for this PR. 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. Agreed. I think it's unrelated, though. I'll make sure we have an issue for warning when you're about to lose changes. |
||
text: i18n.translate('xpack.lens.breadcrumbsTitle', { | ||
defaultMessage: 'Visualize', | ||
}), | ||
}; | ||
|
||
chrome.breadcrumbs.set(persistedDoc ? [rootCrumb, { text: persistedDoc.title }] : [rootCrumb]); | ||
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. |
||
} | ||
|
||
export function App({ | ||
editorFrame, | ||
store, | ||
|
@@ -87,6 +105,11 @@ export function App({ | |
|
||
const lastKnownDocRef = useRef<Document | undefined>(undefined); | ||
|
||
// Sync Kibana breadcrumbs any time we save the document | ||
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. nit: comment should be 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. True. |
||
useEffect(() => setBreadcrumbs(chrome, state.persistedDoc), [ | ||
state.persistedDoc && state.persistedDoc.title, | ||
]); | ||
|
||
useEffect(() => { | ||
if (docId && (!state.persistedDoc || state.persistedDoc.id !== docId)) { | ||
setState({ ...state, isLoading: true }); | ||
|
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 see a test for the useEffect you added, which would be if the persisted title is changed, the breadcrumb should change.
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.
Yeah... It's true. It's clumsy to test, and I felt like I was just testing mocks, mostly, but it's probably worth something basic at least.