Skip to content

Commit

Permalink
[8.16] [Security Assistant] Knowledge base settings author column fix (
Browse files Browse the repository at this point in the history
…#197114) (#197137)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Security Assistant] Knowledge base settings author column fix
(#197114)](#197114)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-21T20:18:44Z","message":"[Security
Assistant] Knowledge base settings author column fix
(#197114)","sha":"1e12f31a7082ce8286f933f8a586fdb706c35a01","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:
SecuritySolution","backport:prev-minor","Team:Security Generative
AI","v8.16.0"],"title":"[Security Assistant] Knowledge base settings
author column fix
","number":197114,"url":"https://github.com/elastic/kibana/pull/197114","mergeCommit":{"message":"[Security
Assistant] Knowledge base settings author column fix
(#197114)","sha":"1e12f31a7082ce8286f933f8a586fdb706c35a01"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197114","number":197114,"mergeCommit":{"message":"[Security
Assistant] Knowledge base settings author column fix
(#197114)","sha":"1e12f31a7082ce8286f933f8a586fdb706c35a01"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Steph Milovic <[email protected]>
  • Loading branch information
kibanamachine and stephmilovic authored Oct 21, 2024
1 parent 494164e commit 6820eb9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,6 @@ export const ENTRY_NAME_INPUT_PLACEHOLDER = i18n.translate(
}
);

export const ENTRY_SPACE_INPUT_LABEL = i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettingsManagement.entrySpaceInputLabel',
{
defaultMessage: 'Space',
}
);

export const ENTRY_SPACE_INPUT_PLACEHOLDER = i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettingsManagement.entrySpaceInputPlaceholder',
{
defaultMessage: 'Select',
}
);

export const SHARING_PRIVATE_OPTION_LABEL = i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettingsManagement.sharingPrivateOptionLabel',
{
Expand Down Expand Up @@ -272,7 +258,8 @@ export const ENTRY_DESCRIPTION_HELP_LABEL = i18n.translate(
export const ENTRY_DESCRIPTION_PLACEHOLDER = i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettingsManagement.entryDescriptionPlaceholder',
{
defaultMessage: 'Use this index to answer any question related to asset information.',
defaultMessage:
'Example: "Use this index to answer any question related to asset information."',
}
);

Expand All @@ -295,7 +282,7 @@ export const ENTRY_QUERY_DESCRIPTION_PLACEHOLDER = i18n.translate(
'xpack.elasticAssistant.assistant.settings.knowledgeBaseSettingsManagement.entryQueryDescriptionPlaceholder',
{
defaultMessage:
'Key terms to retrieve asset related information, like host names, IP Addresses or cloud objects.',
'Example: "Key terms to retrieve asset related information, like host names, IP Addresses or cloud objects."',
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,29 @@ import {
} from '@kbn/elastic-assistant-common';

import useAsync from 'react-use/lib/useAsync';
import { UserProfileAvatarData } from '@kbn/user-profile-components';
import { useAssistantContext } from '../../..';
import * as i18n from './translations';
import { BadgesColumn } from '../../assistant/common/components/assistant_settings_management/badges';
import { useInlineActions } from '../../assistant/common/components/assistant_settings_management/inline_actions';
import { isSystemEntry } from './helpers';

const AuthorColumn = ({ entry }: { entry: KnowledgeBaseEntryResponse }) => {
const { currentUserAvatar, userProfileService } = useAssistantContext();
const { userProfileService } = useAssistantContext();

const userProfile = useAsync(async () => {
const profile = await userProfileService?.bulkGet({ uids: new Set([entry.createdBy]) });
return profile?.[0].user.username;
}, []);
const profile = await userProfileService?.bulkGet<{ avatar: UserProfileAvatarData }>({
uids: new Set([entry.createdBy]),
dataPath: 'avatar',
});
return { username: profile?.[0].user.username, avatar: profile?.[0].data.avatar };
}, [entry.createdBy]);

const userName = useMemo(() => userProfile?.value ?? 'Unknown', [userProfile?.value]);
const userName = useMemo(
() => userProfile?.value?.username ?? 'Unknown',
[userProfile?.value?.username]
);
const userAvatar = userProfile.value?.avatar;
const badgeItem = isSystemEntry(entry) ? 'Elastic' : userName;
const userImage = isSystemEntry(entry) ? (
<EuiIcon
Expand All @@ -40,22 +48,22 @@ const AuthorColumn = ({ entry }: { entry: KnowledgeBaseEntryResponse }) => {
margin-right: 14px;
`}
/>
) : currentUserAvatar?.imageUrl != null ? (
) : userAvatar?.imageUrl != null ? (
<EuiAvatar
name={userName}
imageUrl={currentUserAvatar.imageUrl}
imageUrl={userAvatar.imageUrl}
size={'s'}
color={currentUserAvatar?.color ?? 'subdued'}
color={userAvatar.color ?? 'subdued'}
css={css`
margin-right: 10px;
`}
/>
) : (
<EuiAvatar
name={userName}
initials={currentUserAvatar?.initials}
initials={userAvatar?.initials}
size={'s'}
color={currentUserAvatar?.color ?? 'subdued'}
color={userAvatar?.color ?? 'subdued'}
css={css`
margin-right: 10px;
`}
Expand Down Expand Up @@ -123,7 +131,6 @@ export const useKnowledgeBaseTable = () => {
},
{
name: i18n.COLUMN_AUTHOR,
sortable: ({ users }: KnowledgeBaseEntryResponse) => users[0]?.name,
render: (entry: KnowledgeBaseEntryResponse) => <AuthorColumn entry={entry} />,
},
{
Expand Down
1 change: 1 addition & 0 deletions x-pack/packages/kbn-elastic-assistant/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
"@kbn/core",
"@kbn/zod",
"@kbn/data-views-plugin",
"@kbn/user-profile-components",
]
}

0 comments on commit 6820eb9

Please sign in to comment.