mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 14:05:59 -03:30
Merge pull request #139 from AlexSCorey/138-updateFunctionName
Fixes function naming
This commit is contained in:
@@ -12,29 +12,29 @@ describe('<Notifications />', () => {
|
|||||||
<Notifications
|
<Notifications
|
||||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
||||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||||
getError={jest.fn()}
|
onReadError={jest.fn()}
|
||||||
getNotifications={jest.fn()}
|
onReadNotifications={jest.fn()}
|
||||||
getSuccess={jest.fn()}
|
onReadSuccess={jest.fn()}
|
||||||
postError={jest.fn()}
|
onCreateError={jest.fn()}
|
||||||
postSuccess={jest.fn()}
|
onCreateSuccess={jest.fn()}
|
||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('fetches notifications on mount', () => {
|
test('fetches notifications on mount', () => {
|
||||||
const spy = jest.spyOn(Notifications.prototype, 'fetchNotifications');
|
const spy = jest.spyOn(Notifications.prototype, 'readNotifications');
|
||||||
mount(
|
mount(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
<Notifications
|
<Notifications
|
||||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
||||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||||
getError={jest.fn()}
|
onReadError={jest.fn()}
|
||||||
getNotifications={jest.fn()}
|
onReadNotifications={jest.fn()}
|
||||||
getSuccess={jest.fn()}
|
onReadSuccess={jest.fn()}
|
||||||
postError={jest.fn()}
|
onCreateError={jest.fn()}
|
||||||
postSuccess={jest.fn()}
|
onCreateSuccess={jest.fn()}
|
||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
@@ -42,18 +42,18 @@ describe('<Notifications />', () => {
|
|||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
test('toggle success calls post', () => {
|
test('toggle success calls post', () => {
|
||||||
const spy = jest.spyOn(Notifications.prototype, 'postToSuccess');
|
const spy = jest.spyOn(Notifications.prototype, 'createSuccess');
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
<Notifications
|
<Notifications
|
||||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
||||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||||
getError={jest.fn()}
|
onReadError={jest.fn()}
|
||||||
getNotifications={jest.fn()}
|
onReadNotifications={jest.fn()}
|
||||||
getSuccess={jest.fn()}
|
onReadSuccess={jest.fn()}
|
||||||
postError={jest.fn()}
|
onCreateError={jest.fn()}
|
||||||
postSuccess={jest.fn()}
|
onCreateSuccess={jest.fn()}
|
||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
@@ -62,43 +62,43 @@ describe('<Notifications />', () => {
|
|||||||
expect(spy).toHaveBeenCalledWith(1, true);
|
expect(spy).toHaveBeenCalledWith(1, true);
|
||||||
});
|
});
|
||||||
test('post success makes request and updates state properly', async () => {
|
test('post success makes request and updates state properly', async () => {
|
||||||
const postSuccessFn = jest.fn();
|
const createSuccess = jest.fn();
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
<Notifications
|
<Notifications
|
||||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
||||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||||
getError={jest.fn()}
|
onReadError={jest.fn()}
|
||||||
getNotifications={jest.fn()}
|
onReadNotifications={jest.fn()}
|
||||||
getSuccess={jest.fn()}
|
onReadSuccess={jest.fn()}
|
||||||
postError={jest.fn()}
|
onCreateError={jest.fn()}
|
||||||
postSuccess={postSuccessFn}
|
onCreateSuccess={createSuccess}
|
||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
).find('Notifications');
|
).find('Notifications');
|
||||||
wrapper.setState({ successTemplateIds: [44] });
|
wrapper.setState({ successTemplateIds: [44] });
|
||||||
await wrapper.instance().postToSuccess(44, true);
|
await wrapper.instance().createSuccess(44, true);
|
||||||
expect(postSuccessFn).toHaveBeenCalledWith(1, { id: 44, disassociate: true });
|
expect(createSuccess).toHaveBeenCalledWith(1, { id: 44, disassociate: true });
|
||||||
expect(wrapper.state('successTemplateIds')).not.toContain(44);
|
expect(wrapper.state('successTemplateIds')).not.toContain(44);
|
||||||
await wrapper.instance().postToSuccess(44, false);
|
await wrapper.instance().createSuccess(44, false);
|
||||||
expect(postSuccessFn).toHaveBeenCalledWith(1, { id: 44 });
|
expect(createSuccess).toHaveBeenCalledWith(1, { id: 44 });
|
||||||
expect(wrapper.state('successTemplateIds')).toContain(44);
|
expect(wrapper.state('successTemplateIds')).toContain(44);
|
||||||
});
|
});
|
||||||
test('toggle error calls post', () => {
|
test('toggle error calls post', () => {
|
||||||
const spy = jest.spyOn(Notifications.prototype, 'postToError');
|
const spy = jest.spyOn(Notifications.prototype, 'createError');
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
<Notifications
|
<Notifications
|
||||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
||||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||||
getError={jest.fn()}
|
onReadError={jest.fn()}
|
||||||
getNotifications={jest.fn()}
|
onReadNotifications={jest.fn()}
|
||||||
getSuccess={jest.fn()}
|
onReadSuccess={jest.fn()}
|
||||||
postError={jest.fn()}
|
onCreateError={jest.fn()}
|
||||||
postSuccess={jest.fn()}
|
onCreateSuccess={jest.fn()}
|
||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
@@ -107,28 +107,28 @@ describe('<Notifications />', () => {
|
|||||||
expect(spy).toHaveBeenCalledWith(1, true);
|
expect(spy).toHaveBeenCalledWith(1, true);
|
||||||
});
|
});
|
||||||
test('post error makes request and updates state properly', async () => {
|
test('post error makes request and updates state properly', async () => {
|
||||||
const postErrorFn = jest.fn();
|
const createError = jest.fn();
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
<Notifications
|
<Notifications
|
||||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
||||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||||
getError={jest.fn()}
|
onReadError={jest.fn()}
|
||||||
getNotifications={jest.fn()}
|
onReadNotifications={jest.fn()}
|
||||||
getSuccess={jest.fn()}
|
onReadSuccess={jest.fn()}
|
||||||
postError={postErrorFn}
|
onCreateError={createError}
|
||||||
postSuccess={jest.fn()}
|
onCreateSuccess={jest.fn()}
|
||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
).find('Notifications');
|
).find('Notifications');
|
||||||
wrapper.setState({ errorTemplateIds: [44] });
|
wrapper.setState({ errorTemplateIds: [44] });
|
||||||
await wrapper.instance().postToError(44, true);
|
await wrapper.instance().createError(44, true);
|
||||||
expect(postErrorFn).toHaveBeenCalledWith(1, { id: 44, disassociate: true });
|
expect(createError).toHaveBeenCalledWith(1, { id: 44, disassociate: true });
|
||||||
expect(wrapper.state('errorTemplateIds')).not.toContain(44);
|
expect(wrapper.state('errorTemplateIds')).not.toContain(44);
|
||||||
await wrapper.instance().postToError(44, false);
|
await wrapper.instance().createError(44, false);
|
||||||
expect(postErrorFn).toHaveBeenCalledWith(1, { id: 44 });
|
expect(createError).toHaveBeenCalledWith(1, { id: 44 });
|
||||||
expect(wrapper.state('errorTemplateIds')).toContain(44);
|
expect(wrapper.state('errorTemplateIds')).toContain(44);
|
||||||
});
|
});
|
||||||
test('fetchNotifications', async () => {
|
test('fetchNotifications', async () => {
|
||||||
@@ -137,7 +137,7 @@ describe('<Notifications />', () => {
|
|||||||
page_size: 10,
|
page_size: 10,
|
||||||
order_by: 'name'
|
order_by: 'name'
|
||||||
};
|
};
|
||||||
const getNotificationsFn = jest.fn().mockResolvedValue({
|
const onReadNotifications = jest.fn().mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
results: [
|
results: [
|
||||||
{ id: 1, notification_type: 'slack' },
|
{ id: 1, notification_type: 'slack' },
|
||||||
@@ -146,14 +146,14 @@ describe('<Notifications />', () => {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const getSuccessFn = jest.fn().mockResolvedValue({
|
const onReadSuccess = jest.fn().mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
results: [
|
results: [
|
||||||
{ id: 1 }
|
{ id: 1 }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const getErrorFn = jest.fn().mockResolvedValue({
|
const readError = jest.fn().mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
results: [
|
results: [
|
||||||
{ id: 2 }
|
{ id: 2 }
|
||||||
@@ -166,22 +166,22 @@ describe('<Notifications />', () => {
|
|||||||
<Notifications
|
<Notifications
|
||||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
||||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||||
getNotifications={getNotificationsFn}
|
onReadNotifications={onReadNotifications}
|
||||||
getSuccess={getSuccessFn}
|
onReadSuccess={onReadSuccess}
|
||||||
getError={getErrorFn}
|
onReadError={readError}
|
||||||
postError={jest.fn()}
|
onCreateError={jest.fn()}
|
||||||
postSuccess={jest.fn()}
|
onCreateSuccess={jest.fn()}
|
||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
).find('Notifications');
|
).find('Notifications');
|
||||||
wrapper.instance().updateUrl = jest.fn();
|
wrapper.instance().updateUrl = jest.fn();
|
||||||
await wrapper.instance().fetchNotifications(mockQueryParams);
|
await wrapper.instance().readNotifications(mockQueryParams);
|
||||||
expect(getNotificationsFn).toHaveBeenCalledWith(1, mockQueryParams);
|
expect(onReadNotifications).toHaveBeenCalledWith(1, mockQueryParams);
|
||||||
expect(getSuccessFn).toHaveBeenCalledWith(1, {
|
expect(onReadSuccess).toHaveBeenCalledWith(1, {
|
||||||
id__in: '1,2,3'
|
id__in: '1,2,3'
|
||||||
});
|
});
|
||||||
expect(getErrorFn).toHaveBeenCalledWith(1, {
|
expect(readError).toHaveBeenCalledWith(1, {
|
||||||
id__in: '1,2,3'
|
id__in: '1,2,3'
|
||||||
});
|
});
|
||||||
expect(wrapper.state('successTemplateIds')).toContain(1);
|
expect(wrapper.state('successTemplateIds')).toContain(1);
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ describe('<OrganizationNotifications />', () => {
|
|||||||
/>
|
/>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
).find('OrganizationNotifications');
|
).find('OrganizationNotifications');
|
||||||
wrapper.instance().getOrgNotifications(1, { foo: 'bar' });
|
wrapper.instance().readOrgNotifications(1, { foo: 'bar' });
|
||||||
expect(getOrganizationNotifications).toHaveBeenCalledWith(1, { foo: 'bar' });
|
expect(getOrganizationNotifications).toHaveBeenCalledWith(1, { foo: 'bar' });
|
||||||
wrapper.instance().getOrgNotificationSuccess(1, { foo: 'bar' });
|
wrapper.instance().readOrgNotificationSuccess(1, { foo: 'bar' });
|
||||||
expect(getOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { foo: 'bar' });
|
expect(getOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { foo: 'bar' });
|
||||||
wrapper.instance().getOrgNotificationError(1, { foo: 'bar' });
|
wrapper.instance().readOrgNotificationError(1, { foo: 'bar' });
|
||||||
expect(getOrganizationNotificationError).toHaveBeenCalledWith(1, { foo: 'bar' });
|
expect(getOrganizationNotificationError).toHaveBeenCalledWith(1, { foo: 'bar' });
|
||||||
wrapper.instance().createOrgNotificationSuccess(1, { id: 2 });
|
wrapper.instance().createOrgNotificationSuccess(1, { id: 2 });
|
||||||
expect(createOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { id: 2 });
|
expect(createOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { id: 2 });
|
||||||
|
|||||||
@@ -49,27 +49,21 @@ class Notifications extends Component {
|
|||||||
errorTemplateIds: []
|
errorTemplateIds: []
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onSearch = this.onSearch.bind(this);
|
this.handleSearch = this.handleSearch.bind(this);
|
||||||
this.getQueryParams = this.getQueryParams.bind(this);
|
this.getQueryParams = this.getQueryParams.bind(this);
|
||||||
this.onSort = this.onSort.bind(this);
|
this.handleSort = this.handleSort.bind(this);
|
||||||
this.onSetPage = this.onSetPage.bind(this);
|
this.handleSetPage = this.handleSetPage.bind(this);
|
||||||
this.onSelectAll = this.onSelectAll.bind(this);
|
this.handleSelectAll = this.handleSelectAll.bind(this);
|
||||||
this.toggleNotification = this.toggleNotification.bind(this);
|
this.toggleNotification = this.toggleNotification.bind(this);
|
||||||
this.updateUrl = this.updateUrl.bind(this);
|
this.updateUrl = this.updateUrl.bind(this);
|
||||||
this.postToError = this.postToError.bind(this);
|
this.createError = this.createError.bind(this);
|
||||||
this.postToSuccess = this.postToSuccess.bind(this);
|
this.createSuccess = this.createSuccess.bind(this);
|
||||||
this.fetchNotifications = this.fetchNotifications.bind(this);
|
this.readNotifications = this.readNotifications.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const queryParams = this.getQueryParams();
|
const queryParams = this.getQueryParams();
|
||||||
this.fetchNotifications(queryParams);
|
this.readNotifications(queryParams);
|
||||||
}
|
|
||||||
|
|
||||||
onSearch () {
|
|
||||||
const { sortedColumnKey, sortOrder } = this.state;
|
|
||||||
|
|
||||||
this.onSort(sortedColumnKey, sortOrder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getQueryParams (overrides = {}) {
|
getQueryParams (overrides = {}) {
|
||||||
@@ -81,7 +75,7 @@ class Notifications extends Component {
|
|||||||
return Object.assign({}, this.defaultParams, searchParams, overrides);
|
return Object.assign({}, this.defaultParams, searchParams, overrides);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSort = (sortedColumnKey, sortOrder) => {
|
handleSort = (sortedColumnKey, sortOrder) => {
|
||||||
const { page_size } = this.state;
|
const { page_size } = this.state;
|
||||||
|
|
||||||
let order_by = sortedColumnKey;
|
let order_by = sortedColumnKey;
|
||||||
@@ -92,19 +86,19 @@ class Notifications extends Component {
|
|||||||
|
|
||||||
const queryParams = this.getQueryParams({ order_by, page_size });
|
const queryParams = this.getQueryParams({ order_by, page_size });
|
||||||
|
|
||||||
this.fetchNotifications(queryParams);
|
this.readNotifications(queryParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
onSetPage = (pageNumber, pageSize) => {
|
handleSetPage = (pageNumber, pageSize) => {
|
||||||
const page = parseInt(pageNumber, 10);
|
const page = parseInt(pageNumber, 10);
|
||||||
const page_size = parseInt(pageSize, 10);
|
const page_size = parseInt(pageSize, 10);
|
||||||
|
|
||||||
const queryParams = this.getQueryParams({ page, page_size });
|
const queryParams = this.getQueryParams({ page, page_size });
|
||||||
|
|
||||||
this.fetchNotifications(queryParams);
|
this.readNotifications(queryParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
onSelectAll = isSelected => {
|
handleSelectAll = isSelected => {
|
||||||
const { results } = this.state;
|
const { results } = this.state;
|
||||||
|
|
||||||
const selected = isSelected ? results.map(o => o.id) : [];
|
const selected = isSelected ? results.map(o => o.id) : [];
|
||||||
@@ -114,12 +108,18 @@ class Notifications extends Component {
|
|||||||
|
|
||||||
toggleNotification = (id, isCurrentlyOn, status) => {
|
toggleNotification = (id, isCurrentlyOn, status) => {
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
this.postToSuccess(id, isCurrentlyOn);
|
this.createSuccess(id, isCurrentlyOn);
|
||||||
} else if (status === 'error') {
|
} else if (status === 'error') {
|
||||||
this.postToError(id, isCurrentlyOn);
|
this.createError(id, isCurrentlyOn);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleSearch () {
|
||||||
|
const { sortedColumnKey, sortOrder } = this.state;
|
||||||
|
|
||||||
|
this.handleSort(sortedColumnKey, sortOrder);
|
||||||
|
}
|
||||||
|
|
||||||
updateUrl (queryParams) {
|
updateUrl (queryParams) {
|
||||||
const { history, location, match } = this.props;
|
const { history, location, match } = this.props;
|
||||||
const pathname = match.url;
|
const pathname = match.url;
|
||||||
@@ -130,14 +130,14 @@ class Notifications extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async postToError (id, isCurrentlyOn) {
|
async createError (id, isCurrentlyOn) {
|
||||||
const { postError, match } = this.props;
|
const { onCreateError, match } = this.props;
|
||||||
const postParams = { id };
|
const postParams = { id };
|
||||||
if (isCurrentlyOn) {
|
if (isCurrentlyOn) {
|
||||||
postParams.disassociate = true;
|
postParams.disassociate = true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await postError(match.params.id, postParams);
|
await onCreateError(match.params.id, postParams);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: true });
|
this.setState({ error: true });
|
||||||
} finally {
|
} finally {
|
||||||
@@ -155,14 +155,14 @@ class Notifications extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async postToSuccess (id, isCurrentlyOn) {
|
async createSuccess (id, isCurrentlyOn) {
|
||||||
const { postSuccess, match } = this.props;
|
const { onCreateSuccess, match } = this.props;
|
||||||
const postParams = { id };
|
const postParams = { id };
|
||||||
if (isCurrentlyOn) {
|
if (isCurrentlyOn) {
|
||||||
postParams.disassociate = true;
|
postParams.disassociate = true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await postSuccess(match.params.id, postParams);
|
await onCreateSuccess(match.params.id, postParams);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ error: true });
|
this.setState({ error: true });
|
||||||
} finally {
|
} finally {
|
||||||
@@ -180,9 +180,9 @@ class Notifications extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchNotifications (queryParams) {
|
async readNotifications (queryParams) {
|
||||||
const { noInitialResults } = this.state;
|
const { noInitialResults } = this.state;
|
||||||
const { getNotifications, getSuccess, getError, match } = this.props;
|
const { onReadNotifications, onReadSuccess, onReadError, match } = this.props;
|
||||||
const { page, page_size, order_by } = queryParams;
|
const { page, page_size, order_by } = queryParams;
|
||||||
|
|
||||||
let sortOrder = 'ascending';
|
let sortOrder = 'ascending';
|
||||||
@@ -196,7 +196,7 @@ class Notifications extends Component {
|
|||||||
this.setState({ error: false, loading: true });
|
this.setState({ error: false, loading: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await getNotifications(match.params.id, queryParams);
|
const { data } = await onReadNotifications(match.params.id, queryParams);
|
||||||
const { count, results } = data;
|
const { count, results } = data;
|
||||||
|
|
||||||
const pageCount = Math.ceil(count / page_size);
|
const pageCount = Math.ceil(count / page_size);
|
||||||
@@ -231,10 +231,10 @@ class Notifications extends Component {
|
|||||||
let errorTemplateIds = [];
|
let errorTemplateIds = [];
|
||||||
|
|
||||||
if (results.length > 0) {
|
if (results.length > 0) {
|
||||||
const successTemplatesPromise = getSuccess(match.params.id, {
|
const successTemplatesPromise = onReadSuccess(match.params.id, {
|
||||||
id__in: notificationTemplateIds
|
id__in: notificationTemplateIds
|
||||||
});
|
});
|
||||||
const errorTemplatesPromise = getError(match.params.id, {
|
const errorTemplatesPromise = onReadError(match.params.id, {
|
||||||
id__in: notificationTemplateIds
|
id__in: notificationTemplateIds
|
||||||
});
|
});
|
||||||
const successTemplatesResult = await successTemplatesPromise;
|
const successTemplatesResult = await successTemplatesPromise;
|
||||||
@@ -297,9 +297,9 @@ class Notifications extends Component {
|
|||||||
sortedColumnKey={sortedColumnKey}
|
sortedColumnKey={sortedColumnKey}
|
||||||
sortOrder={sortOrder}
|
sortOrder={sortOrder}
|
||||||
columns={this.columns}
|
columns={this.columns}
|
||||||
onSearch={this.onSearch}
|
onSearch={this.handleSearch}
|
||||||
onSort={this.onSort}
|
onSort={this.handleSort}
|
||||||
onSelectAll={this.onSelectAll}
|
onSelectAll={this.handleSelectAll}
|
||||||
/>
|
/>
|
||||||
<I18n>
|
<I18n>
|
||||||
{({ i18n }) => (
|
{({ i18n }) => (
|
||||||
@@ -324,7 +324,7 @@ class Notifications extends Component {
|
|||||||
page={page}
|
page={page}
|
||||||
pageCount={pageCount}
|
pageCount={pageCount}
|
||||||
page_size={page_size}
|
page_size={page_size}
|
||||||
onSetPage={this.onSetPage}
|
onSetPage={this.handleSetPage}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)}
|
)}
|
||||||
@@ -336,11 +336,11 @@ class Notifications extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Notifications.propTypes = {
|
Notifications.propTypes = {
|
||||||
getError: PropTypes.func.isRequired,
|
onReadError: PropTypes.func.isRequired,
|
||||||
getNotifications: PropTypes.func.isRequired,
|
onReadNotifications: PropTypes.func.isRequired,
|
||||||
getSuccess: PropTypes.func.isRequired,
|
onReadSuccess: PropTypes.func.isRequired,
|
||||||
postError: PropTypes.func.isRequired,
|
onCreateError: PropTypes.func.isRequired,
|
||||||
postSuccess: PropTypes.func.isRequired,
|
onCreateSuccess: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Notifications;
|
export default Notifications;
|
||||||
|
|||||||
@@ -6,24 +6,24 @@ class OrganizationNotifications extends Component {
|
|||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.getOrgNotifications = this.getOrgNotifications.bind(this);
|
this.readOrgNotifications = this.readOrgNotifications.bind(this);
|
||||||
this.getOrgNotificationSuccess = this.getOrgNotificationSuccess.bind(this);
|
this.readOrgNotificationSuccess = this.readOrgNotificationSuccess.bind(this);
|
||||||
this.getOrgNotificationError = this.getOrgNotificationError.bind(this);
|
this.readOrgNotificationError = this.readOrgNotificationError.bind(this);
|
||||||
this.createOrgNotificationSuccess = this.createOrgNotificationSuccess.bind(this);
|
this.createOrgNotificationSuccess = this.createOrgNotificationSuccess.bind(this);
|
||||||
this.createOrgNotificationError = this.createOrgNotificationError.bind(this);
|
this.createOrgNotificationError = this.createOrgNotificationError.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrgNotifications (id, reqParams) {
|
readOrgNotifications (id, reqParams) {
|
||||||
const { api } = this.props;
|
const { api } = this.props;
|
||||||
return api.getOrganizationNotifications(id, reqParams);
|
return api.getOrganizationNotifications(id, reqParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrgNotificationSuccess (id, reqParams) {
|
readOrgNotificationSuccess (id, reqParams) {
|
||||||
const { api } = this.props;
|
const { api } = this.props;
|
||||||
return api.getOrganizationNotificationSuccess(id, reqParams);
|
return api.getOrganizationNotificationSuccess(id, reqParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrgNotificationError (id, reqParams) {
|
readOrgNotificationError (id, reqParams) {
|
||||||
const { api } = this.props;
|
const { api } = this.props;
|
||||||
return api.getOrganizationNotificationError(id, reqParams);
|
return api.getOrganizationNotificationError(id, reqParams);
|
||||||
}
|
}
|
||||||
@@ -47,11 +47,11 @@ class OrganizationNotifications extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<NotificationsList
|
<NotificationsList
|
||||||
getNotifications={this.getOrgNotifications}
|
onReadNotifications={this.readOrgNotifications}
|
||||||
getSuccess={this.getOrgNotificationSuccess}
|
onReadSuccess={this.readOrgNotificationSuccess}
|
||||||
getError={this.getOrgNotificationError}
|
onReadError={this.readOrgNotificationError}
|
||||||
postSuccess={this.createOrgNotificationSuccess}
|
onCreateSuccess={this.createOrgNotificationSuccess}
|
||||||
postError={this.createOrgNotificationError}
|
onCreateError={this.createOrgNotificationError}
|
||||||
match={match}
|
match={match}
|
||||||
location={location}
|
location={location}
|
||||||
history={history}
|
history={history}
|
||||||
|
|||||||
Reference in New Issue
Block a user