-
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
[Cases] Refactor UI user actions #121962
[Cases] Refactor UI user actions #121962
Conversation
b427d59
to
a3bd04f
Compare
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
9e94b82
to
657c847
Compare
x-pack/plugins/cases/public/components/user_actions/comment/alert_event.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx
Outdated
Show resolved
Hide resolved
@elasticmachine merge upstream |
|
||
it('renders correctly when editing a description', async () => { | ||
const userAction = getUserAction('description', Actions.update); | ||
// @ts-ignore no need to pass all the arguments |
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 keep seeing this same @ts-ignore
comment in many other tests and I am not a big fan of using them when we can avoid them. Could you perhaps create a common test helper builder that handles this and call it in these cases? that way we don't put so many @ts-ignore
across the code.
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.
My main concern on the current pattern is the typescript types for the builders. Could you create specific types for the builders?
x-pack/plugins/cases/public/components/user_actions/index.test.tsx
Outdated
Show resolved
Hide resolved
return ( | ||
<> | ||
<MyEuiCommentList comments={comments} data-test-subj="user-actions" /> | ||
{(isLoadingUserActions || loadingCommentIds.includes(NEW_COMMENT_ID)) && ( |
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.
could you turn this into a ternary? It makes it easier to read.
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 like better this pattern, to be honest. With a ternary, I have to return null
and I found it more difficult to read.
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.
@cnasikas I understand that but keep in mind it is more common for react to have ternaries returning null than having expressions like this. I won't push for the change but I find it better to follow code conventions like that one.
I'll go ahead and approve the PR though keep in mind my actual knowledge of the code is limited and I just ran a basic sanity check. My main concern is the lack of types for the action builders, if you could add those would make the PR better. |
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.
Nice work, left a few questions
x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx
Outdated
Show resolved
Hide resolved
}; | ||
|
||
export const createCommentUserActionBuilder: UserActionBuilder = ({ | ||
caseData, |
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'm not sure of the best practice here but that seems like a lot of parameters haha. If we used classes on the frontend we could group these fields into classes but I'm not sure what the equivalent is. Do you think grouping these by sub objects would be helpful? That way common fields are grouped together.
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 think in the front-end, or better in the React ecosystem (hooks, etc), the functional paradigm is more appropriate. Any proposal on the grouping of sub-objects?
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.
Gotcha, makes sense, hmm maybe grouping the comment stuff together, something like this
export interface UserActionBuilderArgs {
comments: {
data: Comment[];
refs: React.MutableRefObject<
Record<string, AddCommentRefObject | UserActionMarkdownRefObject | null | undefined>
>;
loadingIds: string[];
selectedOutlineId: string;
handleOutline: (id: string) => void;
handleSave: ({ id, version }: { id: string; version: string }, content: string) => void;
};
navigation: {
onShowAlertDetails: (alertId: string, index: string) => void;
actionsNavigation?: ActionsNavigation;
getRuleDetailsHref?: RuleDetailsNavigation['href'];
onRuleDetailsClick?: RuleDetailsNavigation['onClick'];
};
alerts: {
loading: boolean;
data: Record<string, Ecs>;
};
markdown: {
manageEditIds: string[];
handleManageEditId: (id: string) => void;
};
caseData: Case;
userAction: CaseUserActions;
caseServices: CaseServices;
index: number;
userCanCrud: boolean;
handleManageQuote: (quote: string) => void;
}
We could probably pull the definition of each object out into their own interface. This puts the burden of grouping the objects on the caller, so maybe that's not helpful 🤷♂️
x-pack/plugins/cases/public/components/user_actions/helpers.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/public/components/user_actions/use_user_actions_handler.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/public/components/user_actions/use_user_actions_handler.tsx
Outdated
Show resolved
Hide resolved
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 for the changes! I tested it locally and the user actions look good!
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @cnasikas |
Summary
When a user views a single case all user actions are being shown. A user action can be the edit of a title, a new comment, the addition or deletion of a tag, and etc. To visualize the user actions we use the EuiCommentList. The
UserActions
component is responsible for showing all user actions to the user. This component iterates the user actions and a big if/else is responsible for checking which user action to render. This PR refactors the component to use the factory pattern to render user actions. Each user action has a builder which is responsible for returning aEuiComment
. TheUserActions
component, uses a map and calls the builder of each user action to accumulate all needed user actions.Related issue: #115730
Checklist
Delete any items that are not applicable to this PR.
For maintainers