mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 19:50:05 -03:30
update activity stream file structure to be consistent with other routes and aid in testing
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
|
import { withI18n } from '@lingui/react';
|
||||||
|
|
||||||
const buildAnchor = (obj, resource, activity) => {
|
const buildAnchor = (obj, resource, activity) => {
|
||||||
let url;
|
let url;
|
||||||
@@ -150,7 +151,7 @@ const buildLabeledLink = (label, link) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (activity, i18n) => {
|
function ActivityStreamDescription({ i18n, activity }) {
|
||||||
const labeledLinks = [];
|
const labeledLinks = [];
|
||||||
// Activity stream objects will outlive the resources they reference
|
// Activity stream objects will outlive the resources they reference
|
||||||
// in that case, summary_fields will not be available - show generic error text instead
|
// in that case, summary_fields will not be available - show generic error text instead
|
||||||
@@ -578,4 +579,6 @@ export default (activity, i18n) => {
|
|||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export default withI18n()(ActivityStreamDescription);
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||||
|
import ActivityStreamDescription from './ActivityStreamDescription';
|
||||||
|
|
||||||
|
describe('ActivityStreamDescription', () => {
|
||||||
|
test('initially renders succesfully', () => {
|
||||||
|
const description = mountWithContexts(
|
||||||
|
<ActivityStreamDescription activity={{}} />
|
||||||
|
);
|
||||||
|
expect(description.find('span').length).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -9,7 +9,7 @@ import { formatDateString } from '../../util/dates';
|
|||||||
import { DetailList, Detail } from '../../components/DetailList';
|
import { DetailList, Detail } from '../../components/DetailList';
|
||||||
import { VariablesDetail } from '../../components/CodeMirrorInput';
|
import { VariablesDetail } from '../../components/CodeMirrorInput';
|
||||||
|
|
||||||
function StreamDetailButton({ i18n, streamItem, user, description }) {
|
function ActivityStreamDetailButton({ i18n, streamItem, user, description }) {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
const setting = streamItem?.summary_fields?.setting;
|
const setting = streamItem?.summary_fields?.setting;
|
||||||
@@ -50,15 +50,17 @@ function StreamDetailButton({ i18n, streamItem, user, description }) {
|
|||||||
value={setting && setting[0]?.name}
|
value={setting && setting[0]?.name}
|
||||||
/>
|
/>
|
||||||
<Detail fullWidth label={i18n._(t`Action`)} value={description} />
|
<Detail fullWidth label={i18n._(t`Action`)} value={description} />
|
||||||
<VariablesDetail
|
{streamItem?.changes && (
|
||||||
label={i18n._(t`Changes`)}
|
<VariablesDetail
|
||||||
rows={changeRows}
|
label={i18n._(t`Changes`)}
|
||||||
value={streamItem?.changes}
|
rows={changeRows}
|
||||||
/>
|
value={streamItem?.changes}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</DetailList>
|
</DetailList>
|
||||||
</Modal>
|
</Modal>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withI18n()(StreamDetailButton);
|
export default withI18n()(ActivityStreamDetailButton);
|
||||||
@@ -2,14 +2,14 @@ import React from 'react';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
|
||||||
import StreamDetailButton from './StreamDetailButton';
|
import ActivityStreamDetailButton from './ActivityStreamDetailButton';
|
||||||
|
|
||||||
jest.mock('../../api/models/ActivityStream');
|
jest.mock('../../api/models/ActivityStream');
|
||||||
|
|
||||||
describe('<StreamDetailButton />', () => {
|
describe('<ActivityStreamDetailButton />', () => {
|
||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
mountWithContexts(
|
mountWithContexts(
|
||||||
<StreamDetailButton
|
<ActivityStreamDetailButton
|
||||||
streamItem={{
|
streamItem={{
|
||||||
timestamp: '12:00:00',
|
timestamp: '12:00:00',
|
||||||
}}
|
}}
|
||||||
@@ -8,8 +8,8 @@ import { Link } from 'react-router-dom';
|
|||||||
import { formatDateString } from '../../util/dates';
|
import { formatDateString } from '../../util/dates';
|
||||||
import { ActionsTd, ActionItem } from '../../components/PaginatedTable';
|
import { ActionsTd, ActionItem } from '../../components/PaginatedTable';
|
||||||
|
|
||||||
import StreamDetailButton from './StreamDetailButton';
|
import ActivityStreamDetailButton from './ActivityStreamDetailButton';
|
||||||
import buildDescription from './buildActivityDescription';
|
import ActivityStreamDescription from './ActivityStreamDescription';
|
||||||
|
|
||||||
function ActivityStreamListItem({ streamItem, i18n }) {
|
function ActivityStreamListItem({ streamItem, i18n }) {
|
||||||
ActivityStreamListItem.propTypes = {
|
ActivityStreamListItem.propTypes = {
|
||||||
@@ -34,7 +34,7 @@ function ActivityStreamListItem({ streamItem, i18n }) {
|
|||||||
|
|
||||||
const labelId = `check-action-${streamItem.id}`;
|
const labelId = `check-action-${streamItem.id}`;
|
||||||
const user = buildUser(streamItem);
|
const user = buildUser(streamItem);
|
||||||
const description = buildDescription(streamItem, i18n);
|
const description = <ActivityStreamDescription activity={streamItem} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tr id={streamItem.id} aria-labelledby={labelId}>
|
<Tr id={streamItem.id} aria-labelledby={labelId}>
|
||||||
@@ -48,7 +48,7 @@ function ActivityStreamListItem({ streamItem, i18n }) {
|
|||||||
</Td>
|
</Td>
|
||||||
<ActionsTd dataLabel={i18n._(t`Actions`)}>
|
<ActionsTd dataLabel={i18n._(t`Actions`)}>
|
||||||
<ActionItem visible tooltip={i18n._(t`View event details`)}>
|
<ActionItem visible tooltip={i18n._(t`View event details`)}>
|
||||||
<StreamDetailButton
|
<ActivityStreamDetailButton
|
||||||
streamItem={streamItem}
|
streamItem={streamItem}
|
||||||
user={user}
|
user={user}
|
||||||
description={description}
|
description={description}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import { mount } from 'enzyme';
|
|
||||||
|
|
||||||
import buildDescription from './buildActivityDescription';
|
|
||||||
|
|
||||||
describe('buildActivityStream', () => {
|
|
||||||
test('initially renders succesfully', () => {
|
|
||||||
const description = mount(buildDescription({}, {}));
|
|
||||||
expect(description.find('span').length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -31,7 +31,10 @@ function Inventories({ i18n }) {
|
|||||||
if (passedInventory && passedInventory.name !== inventory?.name) {
|
if (passedInventory && passedInventory.name !== inventory?.name) {
|
||||||
setInventory(passedInventory);
|
setInventory(passedInventory);
|
||||||
}
|
}
|
||||||
if (passedNestedObject && passedNestedObject.name !== nestedObject?.name) {
|
if (
|
||||||
|
passedNestedObject &&
|
||||||
|
passedNestedObject.name !== nestedObject?.name
|
||||||
|
) {
|
||||||
setNestedGroup(passedNestedObject);
|
setNestedGroup(passedNestedObject);
|
||||||
}
|
}
|
||||||
if (passedSchedule && passedSchedule.name !== schedule?.name) {
|
if (passedSchedule && passedSchedule.name !== schedule?.name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user