[Cases] Lens as persistable state attachment type#159004
[Cases] Lens as persistable state attachment type#159004cnasikas merged 20 commits intoelastic:mainfrom
Conversation
59525ef to
3b4bad4
Compare
|
Pinging @elastic/response-ops (Team:ResponseOps) |
|
Pinging @elastic/response-ops-cases (Feature:Cases) |
| import { LensParser } from './parser'; | ||
| import { LensMarkDownRenderer } from './processor'; | ||
| import { VISUALIZATION } from './translations'; | ||
| import LensRenderer from '../../../visualizations/lens_renderer'; |
There was a problem hiding this comment.
Same code as before. Moved to the visualization folder.
| export const LensRenderer = React.memo(LensRendererComponent); | ||
|
|
||
| // eslint-disable-next-line import/no-default-export | ||
| export { LensRenderer as default }; |
There was a problem hiding this comment.
Same code as before. Different naming.
| import type { LensProps } from './types'; | ||
| import { OpenLensButton } from './open_lens_button'; | ||
|
|
||
| function getOpenLensButton(attachmentId: string, props: LensProps) { |
There was a problem hiding this comment.
Lazy loading here would decrease the page bundle size iirc
There was a problem hiding this comment.
I think it is ok as we do not import any new component from other plugins and the OpenLensButton component is already in the bundle as it is used by the markdown editor.
| persistableStateAttachmentState as unknown as LensProps; | ||
|
|
||
| return { | ||
| event: 'added visualization', |
There was a problem hiding this comment.
Translation missing for the event
| const { LensRenderer } = await import('./lens_renderer'); | ||
|
|
||
| return { | ||
| // eslint-disable-next-line react/display-name |
There was a problem hiding this comment.
nit: could you avoid this comment with the below?
| // eslint-disable-next-line react/display-name | |
| const my_function = (props: PersistableStateAttachmentViewProps) => { | |
| const { attributes, timeRange } = props.persistableStateAttachmentState as unknown as LensProps; | |
| return <LensRenderer attributes={attributes} timeRange={timeRange} />; | |
| } | |
| return { | |
| default: React.memo(my_function, | |
| ... |
| }); | ||
| }); | ||
|
|
||
| describe('createCommentUserActionBuilder', () => { |
There was a problem hiding this comment.
nit: should this be createRegisteredAttachmentUserActionBuilder?
createCommentUserActionBuilder is in x-pack/plugins/cases/public/components/user_actions/comment/comment.test.tsx
| }); | ||
| }); | ||
|
|
||
| it('builds the action correctly', async () => { |
There was a problem hiding this comment.
Could you please also add a test for when hideDefaultActions is true?
| type: CommentType.persistableState as const, | ||
| }, | ||
| ]; | ||
| ] as CaseAttachmentsWithoutOwner; |
There was a problem hiding this comment.
Could you please add the test below to its test file:
const mockOpenCaseFlyout = jest.fn();
const mockGetUseCasesAddToNewCaseFlyout = jest.fn().mockReturnValue({ open: mockOpenCaseFlyout });
it('should open create case flyout', () => {
const mockClick = jest.fn();
const { result } = renderHook(() =>
useAddToNewCase({
lensAttributes: kpiHostMetricLensAttributes,
timeRange,
onClick: mockClick,
})
);
result.current.onAddToNewCaseClicked();
expect(mockOpenCaseFlyout).toHaveBeenCalledWith({
attachments: [
{
persistableStateAttachmentState: { attributes: kpiHostMetricLensAttributes, timeRange },
persistableStateAttachmentTypeId: LENS_ATTACHMENT_TYPE,
type: CommentType.persistableState as const,
},
],
});
expect(mockClick).toHaveBeenCalled();
});
| type: CommentType.persistableState as const, | ||
| }, | ||
| ]; | ||
| ] as CaseAttachmentsWithoutOwner; |
There was a problem hiding this comment.
Please add the test to its test file:
const mockOpenCaseModal = jest.fn();
const mockGetUseCasesAddToExistingCaseModal = jest
.fn()
.mockReturnValue({ open: mockOpenCaseModal });
it('should open add to existing case modal', () => {
const mockClick = jest.fn();
const { result } = renderHook(() =>
useAddToExistingCase({
lensAttributes: kpiHostMetricLensAttributes,
timeRange,
onAddToCaseClicked: mockClick,
})
);
result.current.onAddToExistingCaseClicked();
const attachments = mockOpenCaseModal.mock.calls[0][0].getAttachments();
expect(attachments).toEqual([
{
persistableStateAttachmentState: {
attributes: kpiHostMetricLensAttributes,
timeRange,
},
persistableStateAttachmentTypeId: LENS_ATTACHMENT_TYPE,
type: CommentType.persistableState as const,
},
]);
expect(mockClick).toHaveBeenCalled();
});
jonathan-buttner
left a comment
There was a problem hiding this comment.
Looking good, left a few comments. Is there a way we can test the deferred migrations for user actions and comments? Or do our tests already cover it?
| "children": <React.Suspense | ||
| fallback={<EuiLoadingSpinner />} | ||
| > | ||
| <UNDEFINED |
There was a problem hiding this comment.
Is this supposed to be undefined 🤔
There was a problem hiding this comment.
Probably because the registered component does not have a displayName. I find it weird tbh.
|
|
||
| const props = { | ||
| ...getAttachmentViewProps(), | ||
| attachmentId: userAction.id, |
There was a problem hiding this comment.
Should this be attachmentId: comment.id?
There was a problem hiding this comment.
hmm, good point. I will change it.
| { | ||
| comment: `!{lens${JSON.stringify({ | ||
| timeRange: mockTimeRange, | ||
| persistableStateAttachmentState: { |
There was a problem hiding this comment.
nit: I know this isn't your change but I wonder if we should do a more exact check instead of expect.objectContaining. Or are there other fields that aren't represented here?
There was a problem hiding this comment.
I removed it and it seems that only these fields are the expected ones. Not sure why it was there in the first place.
| context, | ||
| error, | ||
| docType: 'user action persistable lens attachment', | ||
| docKey: 'comment', |
There was a problem hiding this comment.
Should this be user-action or something similar?
| return mergeSavedObjectMigrationMaps(userActionsMigrations, embeddableMigrationsToMerge); | ||
| }; | ||
|
|
||
| export const lensMigratorFactory = ( |
There was a problem hiding this comment.
I think it's fine if we want to migrate the user actions. But just to make sure I'm understanding correctly, we still aren't migrating the user actions where a lens embeddable is within the comment via a json blob (aka not a persistable attachment)?
There was a problem hiding this comment.
As we discussed offline, I removed the lens migrations in user actions.
Verified all 4 scenarios, works as expected 👍 |
shahzad31
left a comment
There was a problem hiding this comment.
Uptime changes LGTM !!
I don't think so as there are no 8.9+ migrations registered by the lens team yet. The unit tests should cover all scenarios. Wdyt? |
Sounds good. |
|
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @cnasikas |
Summary
This PR registers the lens attachment type using the cases attachment framework.
Testing scenarios
Checklist
Delete any items that are not applicable to this PR.
For maintainers