-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rk/text-editor-ui-design
- Loading branch information
Showing
52 changed files
with
787 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
packages/content-management/content_editor/src/components/activity_view.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { UserProfilesProvider } from '@kbn/content-management-user-profiles'; | ||
import { I18nProvider } from '@kbn/i18n-react'; | ||
|
||
import { ActivityView as ActivityViewComponent, ActivityViewProps } from './activity_view'; | ||
|
||
const mockGetUserProfile = jest.fn(async (uid: string) => ({ | ||
uid, | ||
enabled: true, | ||
data: {}, | ||
user: { username: uid, full_name: uid.toLocaleUpperCase() }, | ||
})); | ||
|
||
const ActivityView = (props: ActivityViewProps) => { | ||
return ( | ||
<I18nProvider> | ||
<UserProfilesProvider bulkGetUserProfiles={jest.fn()} getUserProfile={mockGetUserProfile}> | ||
<ActivityViewComponent {...props} /> | ||
</UserProfilesProvider> | ||
</I18nProvider> | ||
); | ||
}; | ||
|
||
test('should render activity view', () => { | ||
render(<ActivityView item={{}} />); | ||
|
||
expect(screen.getByTestId('activityView')).toBeVisible(); | ||
|
||
expect(screen.getByTestId('createdByCard')).toHaveTextContent(/Unknown/); | ||
expect(() => screen.getByTestId('updateByCard')).toThrow(); | ||
}); | ||
|
||
test('should render creator card', async () => { | ||
render(<ActivityView item={{ createdBy: 'john', createdAt: '2024-06-13T12:55:46.825Z' }} />); | ||
|
||
await waitFor(() => { | ||
const createdByCard = screen.getByTestId('createdByCard'); | ||
expect(createdByCard).toHaveTextContent(/JOHN/); | ||
expect(createdByCard).toHaveTextContent(/June 13/); | ||
}); | ||
}); | ||
|
||
test('should not render updater card when updatedAt matches createdAt', async () => { | ||
render( | ||
<ActivityView | ||
item={{ | ||
createdBy: 'john', | ||
updatedBy: 'john', | ||
createdAt: '2024-06-13T12:55:46.825Z', | ||
updatedAt: '2024-06-13T12:55:46.825Z', | ||
}} | ||
/> | ||
); | ||
|
||
expect(screen.getByTestId('createdByCard')).toBeVisible(); | ||
expect(() => screen.getByTestId('updateByCard')).toThrow(); | ||
}); | ||
|
||
test('should render updater card', async () => { | ||
render( | ||
<ActivityView | ||
item={{ | ||
createdBy: 'john', | ||
updatedBy: 'pete', | ||
createdAt: '2024-06-13T12:55:46.825Z', | ||
updatedAt: '2024-06-14T12:55:46.825Z', | ||
}} | ||
/> | ||
); | ||
|
||
await waitFor(() => { | ||
const createdByCard = screen.getByTestId('createdByCard'); | ||
expect(createdByCard).toHaveTextContent(/JOHN/); | ||
expect(createdByCard).toHaveTextContent(/June 13/); | ||
}); | ||
|
||
await waitFor(() => { | ||
const updatedByCard = screen.getByTestId('updatedByCard'); | ||
expect(updatedByCard).toHaveTextContent(/PETE/); | ||
expect(updatedByCard).toHaveTextContent(/June 14/); | ||
}); | ||
}); | ||
|
||
test('should handle managed objects', async () => { | ||
render( | ||
<ActivityView | ||
item={{ | ||
managed: true, | ||
createdAt: '2024-06-13T12:55:46.825Z', | ||
updatedAt: '2024-06-14T12:55:46.825Z', | ||
}} | ||
/> | ||
); | ||
|
||
await waitFor(() => { | ||
const createdByCard = screen.getByTestId('createdByCard'); | ||
expect(createdByCard).toHaveTextContent(/System/); | ||
expect(createdByCard).toHaveTextContent(/June 13/); | ||
}); | ||
|
||
const updatedByCard = screen.getByTestId('updatedByCard'); | ||
expect(updatedByCard).toHaveTextContent(/System/); | ||
expect(updatedByCard).toHaveTextContent(/June 14/); | ||
}); |
185 changes: 185 additions & 0 deletions
185
packages/content-management/content_editor/src/components/activity_view.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiFormRow, | ||
EuiIconTip, | ||
EuiPanel, | ||
EuiSpacer, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import React from 'react'; | ||
import { | ||
UserAvatarTip, | ||
useUserProfile, | ||
NoUpdaterTip, | ||
NoCreatorTip, | ||
ManagedAvatarTip, | ||
} from '@kbn/content-management-user-profiles'; | ||
import { getUserDisplayName } from '@kbn/user-profile-components'; | ||
|
||
import { Item } from '../types'; | ||
|
||
export interface ActivityViewProps { | ||
item: Pick<Item, 'createdBy' | 'createdAt' | 'updatedBy' | 'updatedAt' | 'managed'>; | ||
} | ||
|
||
export const ActivityView = ({ item }: ActivityViewProps) => { | ||
const showLastUpdated = Boolean(item.updatedAt && item.updatedAt !== item.createdAt); | ||
|
||
const UnknownUserLabel = ( | ||
<FormattedMessage | ||
id="contentManagement.contentEditor.activity.unkownUserLabel" | ||
defaultMessage="Unknown" | ||
/> | ||
); | ||
|
||
const ManagedUserLabel = ( | ||
<> | ||
<ManagedAvatarTip />{' '} | ||
<FormattedMessage | ||
id="contentManagement.contentEditor.activity.managedUserLabel" | ||
defaultMessage="System" | ||
/> | ||
</> | ||
); | ||
|
||
return ( | ||
<EuiFormRow | ||
label={ | ||
<> | ||
<FormattedMessage | ||
id="contentManagement.contentEditor.metadataForm.activityLabel" | ||
defaultMessage="Activity" | ||
/>{' '} | ||
<EuiIconTip | ||
type={'iInCircle'} | ||
iconProps={{ style: { verticalAlign: 'bottom' } }} | ||
content={ | ||
<FormattedMessage | ||
id="contentManagement.contentEditor.activity.activityLabelHelpText" | ||
defaultMessage="Activity data is auto-generated and cannot be updated." | ||
/> | ||
} | ||
/> | ||
</> | ||
} | ||
fullWidth | ||
data-test-subj={'activityView'} | ||
> | ||
<> | ||
<EuiFlexGroup gutterSize={'s'}> | ||
<EuiFlexItem grow={1} css={{ flexBasis: '50%', minWidth: 0 }}> | ||
<ActivityCard | ||
what={i18n.translate('contentManagement.contentEditor.activity.createdByLabelText', { | ||
defaultMessage: 'Created by', | ||
})} | ||
who={ | ||
item.createdBy ? ( | ||
<UserLabel uid={item.createdBy} /> | ||
) : item.managed ? ( | ||
<>{ManagedUserLabel}</> | ||
) : ( | ||
<> | ||
{UnknownUserLabel} | ||
<NoCreatorTip /> | ||
</> | ||
) | ||
} | ||
when={item.createdAt} | ||
data-test-subj={'createdByCard'} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={1} css={{ flexBasis: '50%', minWidth: 0 }}> | ||
{showLastUpdated && ( | ||
<ActivityCard | ||
what={i18n.translate( | ||
'contentManagement.contentEditor.activity.lastUpdatedByLabelText', | ||
{ defaultMessage: 'Last updated by' } | ||
)} | ||
who={ | ||
item.updatedBy ? ( | ||
<UserLabel uid={item.updatedBy} /> | ||
) : item.managed ? ( | ||
<>{ManagedUserLabel}</> | ||
) : ( | ||
<> | ||
{UnknownUserLabel} | ||
<NoUpdaterTip /> | ||
</> | ||
) | ||
} | ||
when={item.updatedAt} | ||
data-test-subj={'updatedByCard'} | ||
/> | ||
)} | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</> | ||
</EuiFormRow> | ||
); | ||
}; | ||
|
||
const dateFormatter = new Intl.DateTimeFormat(i18n.getLocale(), { | ||
dateStyle: 'long', | ||
timeStyle: 'short', | ||
}); | ||
|
||
const ActivityCard = ({ | ||
what, | ||
when, | ||
who, | ||
'data-test-subj': dataTestSubj, | ||
}: { | ||
what: string; | ||
who: React.ReactNode; | ||
when?: string; | ||
'data-test-subj'?: string; | ||
}) => { | ||
return ( | ||
<EuiPanel hasBorder paddingSize={'s'} data-test-subj={dataTestSubj}> | ||
<EuiText size={'s'}> | ||
<b>{what}</b> | ||
</EuiText> | ||
<EuiSpacer size={'xs'} /> | ||
<EuiText size={'s'} className={'eui-textTruncate'}> | ||
{who} | ||
</EuiText> | ||
{when && ( | ||
<> | ||
<EuiSpacer size={'xs'} /> | ||
<EuiText title={when} color={'subdued'} size={'s'}> | ||
<FormattedMessage | ||
id="contentManagement.contentEditor.activity.lastUpdatedByDateTime" | ||
defaultMessage="on {dateTime}" | ||
values={{ | ||
dateTime: dateFormatter.format(new Date(when)), | ||
}} | ||
/> | ||
</EuiText> | ||
</> | ||
)} | ||
</EuiPanel> | ||
); | ||
}; | ||
|
||
const UserLabel = ({ uid }: { uid: string }) => { | ||
const userQuery = useUserProfile(uid); | ||
|
||
if (!userQuery.data) return null; | ||
|
||
return ( | ||
<> | ||
<UserAvatarTip uid={uid} /> {getUserDisplayName(userQuery.data.user)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.