Prettify files

This commit is contained in:
mabashian 2019-07-01 13:51:13 -04:00
parent 1d2c21249b
commit 12c0b80102
4 changed files with 91 additions and 76 deletions

View File

@ -47,47 +47,50 @@ function NotificationListItem(props) {
key={notification.id}
>
<DataListItemRow>
<DataListItemCells dataListCells={[
<DataListCell key="name">
<Link
to={{
pathname: detailUrl
}}
css="margin-right: 1.5em;"
>
<b id={`items-list-item-${notification.id}`}>{notification.name}</b>
</Link>
</DataListCell>,
<DataListCell key="type">
{typeLabels[notification.notification_type]}
</DataListCell>,
<DataListCell righthalf="true" key="toggles">
<Switch
id={`notification-${notification.id}-success-toggle`}
label={i18n._(t`Successful`)}
isChecked={successTurnedOn}
isDisabled={!canToggleNotifications}
onChange={() => toggleNotification(
notification.id,
successTurnedOn,
'success'
)}
aria-label={i18n._(t`Toggle notification success`)}
/>
<Switch
id={`notification-${notification.id}-error-toggle`}
label={i18n._(t`Failure`)}
isChecked={errorTurnedOn}
isDisabled={!canToggleNotifications}
onChange={() => toggleNotification(
notification.id,
errorTurnedOn,
'error'
)}
aria-label={i18n._(t`Toggle notification failure`)}
/>
</DataListCell>
]}
<DataListItemCells
dataListCells={[
<DataListCell key="name">
<Link
to={{
pathname: detailUrl,
}}
css="margin-right: 1.5em;"
>
<b id={`items-list-item-${notification.id}`}>
{notification.name}
</b>
</Link>
</DataListCell>,
<DataListCell key="type">
{typeLabels[notification.notification_type]}
</DataListCell>,
<DataListCell righthalf="true" key="toggles">
<Switch
id={`notification-${notification.id}-success-toggle`}
label={i18n._(t`Successful`)}
isChecked={successTurnedOn}
isDisabled={!canToggleNotifications}
onChange={() =>
toggleNotification(
notification.id,
successTurnedOn,
'success'
)
}
aria-label={i18n._(t`Toggle notification success`)}
/>
<Switch
id={`notification-${notification.id}-error-toggle`}
label={i18n._(t`Failure`)}
isChecked={errorTurnedOn}
isDisabled={!canToggleNotifications}
onChange={() =>
toggleNotification(notification.id, errorTurnedOn, 'error')
}
aria-label={i18n._(t`Toggle notification failure`)}
/>
</DataListCell>,
]}
/>
</DataListItemRow>
</DataListItem>
@ -105,7 +108,7 @@ NotificationListItem.propTypes = {
errorTurnedOn: bool,
successTurnedOn: bool,
toggleNotification: func.isRequired,
typeLabels: shape().isRequired
typeLabels: shape().isRequired,
};
NotificationListItem.defaultProps = {

View File

@ -9,11 +9,11 @@ describe('<NotificationListItem canToggleNotifications />', () => {
const mockNotif = {
id: 9000,
name: 'Foo',
notification_type: 'slack'
notification_type: 'slack',
};
const typeLabels = {
slack: 'Slack'
slack: 'Slack',
};
beforeEach(() => {
@ -51,7 +51,10 @@ describe('<NotificationListItem canToggleNotifications />', () => {
typeLabels={typeLabels}
/>
);
const typeCell = wrapper.find('DataListCell').at(1).find('div');
const typeCell = wrapper
.find('DataListCell')
.at(1)
.find('div');
expect(typeCell.text()).toBe('Slack');
});

View File

@ -35,7 +35,7 @@ class OrganizationNotifications extends Component {
notifications: [],
successTemplateIds: [],
errorTemplateIds: [],
typeLabels: null
typeLabels: null,
};
this.handleNotificationToggle = this.handleNotificationToggle.bind(this);
this.handleNotificationErrorClose = this.handleNotificationErrorClose.bind(
@ -60,9 +60,7 @@ class OrganizationNotifications extends Component {
const { typeLabels } = this.state;
const params = parseNamespacedQueryString(QS_CONFIG, location.search);
const promises = [
OrganizationsAPI.readNotificationTemplates(id, params)
];
const promises = [OrganizationsAPI.readNotificationTemplates(id, params)];
if (!typeLabels) {
promises.push(OrganizationsAPI.readOptionsNotificationTemplates(id));
@ -70,12 +68,12 @@ class OrganizationNotifications extends Component {
this.setState({ contentError: null, hasContentLoading: true });
try {
const [{
data: {
count: itemCount = 0,
results: notifications = [],
}
}, optionsResponse] = await Promise.all(promises);
const [
{
data: { count: itemCount = 0, results: notifications = [] },
},
optionsResponse,
] = await Promise.all(promises);
let idMatchParams;
if (notifications.length > 0) {
@ -100,10 +98,20 @@ class OrganizationNotifications extends Component {
};
if (!typeLabels) {
const { data: { actions: { GET: { notification_type: {choices} } } } } = optionsResponse;
const {
data: {
actions: {
GET: {
notification_type: { choices },
},
},
},
} = optionsResponse;
// The structure of choices looks like [['slack', 'Slack'], ['email', 'Email'], ...]
stateToUpdate.typeLabels =
choices.reduce((map, notifType) => ({ ...map, [notifType[0]]: notifType[1]}), {});
stateToUpdate.typeLabels = choices.reduce(
(map, notifType) => ({ ...map, [notifType[0]]: notifType[1] }),
{}
);
}
this.setState(stateToUpdate);

View File

@ -10,17 +10,20 @@ jest.mock('@api');
describe('<OrganizationNotifications />', () => {
const data = {
count: 2,
results: [{
id: 1,
name: 'Notification one',
url: '/api/v2/notification_templates/1/',
notification_type: 'email',
}, {
id: 2,
name: 'Notification two',
url: '/api/v2/notification_templates/2/',
notification_type: 'email',
}]
results: [
{
id: 1,
name: 'Notification one',
url: '/api/v2/notification_templates/1/',
notification_type: 'email',
},
{
id: 2,
name: 'Notification two',
url: '/api/v2/notification_templates/2/',
notification_type: 'email',
},
],
};
OrganizationsAPI.readOptionsNotificationTemplates.mockReturnValue({
@ -28,13 +31,11 @@ describe('<OrganizationNotifications />', () => {
actions: {
GET: {
notification_type: {
choices: [
['email', 'Email']
]
}
}
}
}
choices: [['email', 'Email']],
},
},
},
},
});
beforeEach(() => {