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,15 +47,18 @@ function NotificationListItem(props) {
key={notification.id} key={notification.id}
> >
<DataListItemRow> <DataListItemRow>
<DataListItemCells dataListCells={[ <DataListItemCells
dataListCells={[
<DataListCell key="name"> <DataListCell key="name">
<Link <Link
to={{ to={{
pathname: detailUrl pathname: detailUrl,
}} }}
css="margin-right: 1.5em;" css="margin-right: 1.5em;"
> >
<b id={`items-list-item-${notification.id}`}>{notification.name}</b> <b id={`items-list-item-${notification.id}`}>
{notification.name}
</b>
</Link> </Link>
</DataListCell>, </DataListCell>,
<DataListCell key="type"> <DataListCell key="type">
@@ -67,11 +70,13 @@ function NotificationListItem(props) {
label={i18n._(t`Successful`)} label={i18n._(t`Successful`)}
isChecked={successTurnedOn} isChecked={successTurnedOn}
isDisabled={!canToggleNotifications} isDisabled={!canToggleNotifications}
onChange={() => toggleNotification( onChange={() =>
toggleNotification(
notification.id, notification.id,
successTurnedOn, successTurnedOn,
'success' 'success'
)} )
}
aria-label={i18n._(t`Toggle notification success`)} aria-label={i18n._(t`Toggle notification success`)}
/> />
<Switch <Switch
@@ -79,14 +84,12 @@ function NotificationListItem(props) {
label={i18n._(t`Failure`)} label={i18n._(t`Failure`)}
isChecked={errorTurnedOn} isChecked={errorTurnedOn}
isDisabled={!canToggleNotifications} isDisabled={!canToggleNotifications}
onChange={() => toggleNotification( onChange={() =>
notification.id, toggleNotification(notification.id, errorTurnedOn, 'error')
errorTurnedOn, }
'error'
)}
aria-label={i18n._(t`Toggle notification failure`)} aria-label={i18n._(t`Toggle notification failure`)}
/> />
</DataListCell> </DataListCell>,
]} ]}
/> />
</DataListItemRow> </DataListItemRow>
@@ -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, id: 1,
name: 'Notification one', name: 'Notification one',
url: '/api/v2/notification_templates/1/', url: '/api/v2/notification_templates/1/',
notification_type: 'email', notification_type: 'email',
}, { },
{
id: 2, id: 2,
name: 'Notification two', name: 'Notification two',
url: '/api/v2/notification_templates/2/', url: '/api/v2/notification_templates/2/',
notification_type: 'email', 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(() => {