Skip to content

Commit

Permalink
update activity stream file structure to be consistent with other rou…
Browse files Browse the repository at this point in the history
…tes and aid in testing
  • Loading branch information
John Mitchell authored and John Mitchell committed Jan 20, 2021
1 parent 8592003 commit 86fbf43
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Link } from 'react-router-dom';
import { t } from '@lingui/macro';
import { withI18n } from '@lingui/react';

const buildAnchor = (obj, resource, activity) => {
let url;
Expand Down Expand Up @@ -150,7 +151,7 @@ const buildLabeledLink = (label, link) => {
);
};

export default (activity, i18n) => {
function ActivityStreamDescription({ i18n, activity }) {
const labeledLinks = [];
// Activity stream objects will outlive the resources they reference
// in that case, summary_fields will not be available - show generic error text instead
Expand Down Expand Up @@ -578,4 +579,6 @@ export default (activity, i18n) => {
)}
</span>
);
};
}

export default withI18n()(ActivityStreamDescription);
Original file line number Diff line number Diff line change
@@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { formatDateString } from '../../util/dates';
import { DetailList, Detail } from '../../components/DetailList';
import { VariablesDetail } from '../../components/CodeMirrorInput';

function StreamDetailButton({ i18n, streamItem, user, description }) {
function ActivityStreamDetailButton({ i18n, streamItem, user, description }) {
const [isOpen, setIsOpen] = useState(false);

const setting = streamItem?.summary_fields?.setting;
Expand Down Expand Up @@ -50,15 +50,17 @@ function StreamDetailButton({ i18n, streamItem, user, description }) {
value={setting && setting[0]?.name}
/>
<Detail fullWidth label={i18n._(t`Action`)} value={description} />
<VariablesDetail
label={i18n._(t`Changes`)}
rows={changeRows}
value={streamItem?.changes}
/>
{streamItem?.changes && (
<VariablesDetail
label={i18n._(t`Changes`)}
rows={changeRows}
value={streamItem?.changes}
/>
)}
</DetailList>
</Modal>
</>
);
}

export default withI18n()(StreamDetailButton);
export default withI18n()(ActivityStreamDetailButton);
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react';
import { Link } from 'react-router-dom';

import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
import StreamDetailButton from './StreamDetailButton';
import ActivityStreamDetailButton from './ActivityStreamDetailButton';

jest.mock('../../api/models/ActivityStream');

describe('<StreamDetailButton />', () => {
describe('<ActivityStreamDetailButton />', () => {
test('initially renders succesfully', () => {
mountWithContexts(
<StreamDetailButton
<ActivityStreamDetailButton
streamItem={{
timestamp: '12:00:00',
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Link } from 'react-router-dom';
import { formatDateString } from '../../util/dates';
import { ActionsTd, ActionItem } from '../../components/PaginatedTable';

import StreamDetailButton from './StreamDetailButton';
import buildDescription from './buildActivityDescription';
import ActivityStreamDetailButton from './ActivityStreamDetailButton';
import ActivityStreamDescription from './ActivityStreamDescription';

function ActivityStreamListItem({ streamItem, i18n }) {
ActivityStreamListItem.propTypes = {
Expand All @@ -34,7 +34,7 @@ function ActivityStreamListItem({ streamItem, i18n }) {

const labelId = `check-action-${streamItem.id}`;
const user = buildUser(streamItem);
const description = buildDescription(streamItem, i18n);
const description = <ActivityStreamDescription activity={streamItem} />;

return (
<Tr id={streamItem.id} aria-labelledby={labelId}>
Expand All @@ -48,7 +48,7 @@ function ActivityStreamListItem({ streamItem, i18n }) {
</Td>
<ActionsTd dataLabel={i18n._(t`Actions`)}>
<ActionItem visible tooltip={i18n._(t`View event details`)}>
<StreamDetailButton
<ActivityStreamDetailButton
streamItem={streamItem}
user={user}
description={description}
Expand Down

This file was deleted.

5 changes: 4 additions & 1 deletion awx/ui_next/src/screens/Inventory/Inventories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ function Inventories({ i18n }) {
if (passedInventory && passedInventory.name !== inventory?.name) {
setInventory(passedInventory);
}
if (passedNestedObject && passedNestedObject.name !== nestedObject?.name) {
if (
passedNestedObject &&
passedNestedObject.name !== nestedObject?.name
) {
setNestedGroup(passedNestedObject);
}
if (passedSchedule && passedSchedule.name !== schedule?.name) {
Expand Down

0 comments on commit 86fbf43

Please sign in to comment.