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

View File

@@ -9,11 +9,11 @@ describe('<NotificationListItem canToggleNotifications />', () => {
const mockNotif = { const mockNotif = {
id: 9000, id: 9000,
name: 'Foo', name: 'Foo',
notification_type: 'slack' notification_type: 'slack',
}; };
const typeLabels = { const typeLabels = {
slack: 'Slack' slack: 'Slack',
}; };
beforeEach(() => { beforeEach(() => {
@@ -51,7 +51,10 @@ describe('<NotificationListItem canToggleNotifications />', () => {
typeLabels={typeLabels} 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'); expect(typeCell.text()).toBe('Slack');
}); });

View File

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

View File

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