-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #799 from factly/feat/797/add-webhooks-action-list
Feat/797/add-webhooks-logs-list
- Loading branch information
Showing
12 changed files
with
245 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import axios from 'axios'; | ||
import { | ||
ADD_WEBHOOKLOGS, | ||
ADD_WEBHOOKLOGS_REQUEST, | ||
SET_WEBHOOKLOGS_LOADING, | ||
RESET_WEBHOOKLOGS, | ||
} from '../constants/webhooklogs'; | ||
import { addErrorNotification, addSuccessNotification } from './notifications'; | ||
import { addEvents } from './events'; | ||
import getError from '../utils/getError'; | ||
import { WEBHOOKS_API } from '../constants/webhooks'; | ||
|
||
export const getWebhooklogs = (id, query) => { | ||
return (dispatch) => { | ||
dispatch(loadingWebhookLogs()); | ||
return axios | ||
.get(WEBHOOKS_API + '/' + id + '/logs', { | ||
params: query, | ||
}) | ||
.then((response) => { | ||
dispatch(addWebhooklogList(response.data.nodes)); | ||
dispatch( | ||
addWebhookRequest({ | ||
data: response.data.nodes.map((item) => item.id), | ||
query: query, | ||
total: response.data.total, | ||
}), | ||
); | ||
}) | ||
.catch((error) => { | ||
dispatch(addErrorNotification(getError(error))); | ||
}) | ||
.finally(() => dispatch(stopWebhookLogsLoading())); | ||
}; | ||
}; | ||
|
||
export const loadingWebhookLogs = () => ({ | ||
type: SET_WEBHOOKLOGS_LOADING, | ||
payload: true, | ||
}); | ||
export const stopWebhookLogsLoading = () => ({ | ||
type: SET_WEBHOOKLOGS_LOADING, | ||
payload: false, | ||
}); | ||
export const addWebhooklogList = (data) => ({ | ||
type: ADD_WEBHOOKLOGS, | ||
payload: data, | ||
}); | ||
export const addWebhookRequest = (data) => ({ | ||
type: ADD_WEBHOOKLOGS_REQUEST, | ||
payload: data, | ||
}); | ||
export const resetWebhooks = () => ({ | ||
type: RESET_WEBHOOKLOGS, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//Actions | ||
export const ADD_WEBHOOKLOG = 'ADD_WEBHOOKLOG'; | ||
export const ADD_WEBHOOKLOGS = 'ADD_WEBHOOKLOGS'; | ||
export const ADD_WEBHOOKLOGS_REQUEST = 'ADD_WEBHOOKLOGS_REQUEST'; | ||
export const RESET_WEBHOOKLOGS = 'RESET_WEBHOOKLOGS'; | ||
export const SET_WEBHOOKLOGS_LOADING = 'SET_WEBHOOKLOGS_LOADING'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
studio/src/pages/webhooks/webhooklogs/components/WebhookLogsList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { Table } from 'antd'; | ||
import { getEventName } from '../../../../utils/event'; | ||
import { getDateAndTimeFromString } from '../../../../utils/date'; | ||
function WebhookLogsList({data, filters, setFilters}) { | ||
const columns = [ | ||
{ | ||
title: 'Event', | ||
dataIndex: 'event', | ||
key: 'event', | ||
render: (_, record) => getEventName(record.event) | ||
}, | ||
{ | ||
title: 'Time', | ||
dataIndex: 'created_at', | ||
key: 'created_at', | ||
render: (_, record) => getDateAndTimeFromString(record.created_at) | ||
} | ||
]; | ||
|
||
return ( | ||
<Table | ||
bordered | ||
columns={columns} | ||
dataSource={data.webhooklogs} | ||
loading={data.loading} | ||
rowKey={'id'} | ||
pagination={{ | ||
total: data.total, | ||
current: filters.page, | ||
pageSize: filters.limit, | ||
onChange: (pageNumber, pageSize) => setFilters({ page: pageNumber, limit: pageSize }), | ||
pageSizeOptions: ['10', '15', '20'], | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default WebhookLogsList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { Space } from 'antd'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import deepEqual from 'deep-equal'; | ||
import { getWebhooklogs } from '../../../actions/webhooklogs'; | ||
import WebhookLogsList from './components/WebhookLogsList'; | ||
|
||
function Webhooklogs({WebhookId}) { | ||
const spaces = useSelector(({ spaces }) => spaces); | ||
const dispatch = useDispatch(); | ||
const [filters, setFilters] = React.useState({ | ||
page: 1, | ||
limit: 20, | ||
}); | ||
const { webhooklogs, total, loading } = useSelector((state) => { | ||
const node = state.webhooklogs.req.find((item) => { | ||
return deepEqual(item.query, filters); | ||
}); | ||
if (node) | ||
return { | ||
webhooklogs: node.data.map((element) => state.webhooklogs.details[element]), | ||
total: node.total, | ||
loading: state.webhooks.loading, | ||
}; | ||
return { webhooklogs: [], total: 0, loading: state.webhooklogs.loading }; | ||
}); | ||
React.useEffect(() => { | ||
fetchWebhooklogs(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [filters]); | ||
|
||
const fetchWebhooklogs = () => { | ||
dispatch(getWebhooklogs(WebhookId,filters)); | ||
}; | ||
|
||
return ( | ||
<Space direction="vertical"> | ||
<WebhookLogsList | ||
data={{ webhooklogs, total, loading }} | ||
filters={filters} | ||
setFilters={setFilters} | ||
fetchWebhooks={fetchWebhooklogs} | ||
/> | ||
</Space> | ||
); | ||
} | ||
|
||
export default Webhooklogs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
ADD_WEBHOOKLOG, | ||
ADD_WEBHOOKLOGS, | ||
ADD_WEBHOOKLOGS_REQUEST, | ||
SET_WEBHOOKLOGS_LOADING, | ||
RESET_WEBHOOKLOGS, | ||
} from '../constants/webhooklogs'; | ||
import deepEqual from 'deep-equal'; | ||
|
||
const initialState = { | ||
req: [], | ||
details: {}, | ||
loading: true, | ||
}; | ||
|
||
export default function webhooklogsReducer(state = initialState, action = {}) { | ||
switch (action.type) { | ||
case RESET_WEBHOOKLOGS: | ||
return { | ||
...state, | ||
req: [], | ||
details: {}, | ||
loading: true, | ||
}; | ||
case SET_WEBHOOKLOGS_LOADING: | ||
return { | ||
...state, | ||
loading: action.payload, | ||
}; | ||
case ADD_WEBHOOKLOGS_REQUEST: | ||
return { | ||
...state, | ||
req: state.req | ||
.filter((value) => !deepEqual(value.query, action.payload.query)) | ||
.concat(action.payload), | ||
}; | ||
case ADD_WEBHOOKLOGS: | ||
if (action.payload.length === 0) { | ||
return state; | ||
} | ||
return { | ||
...state, | ||
details: { | ||
...state.details, | ||
...action?.payload?.reduce((obj, item) => Object.assign(obj, { [item.id]: item }), {}), | ||
}, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const getEventName = (eventLabel) => { | ||
var labelArr = eventLabel.split('.'); | ||
for (var i = 0; i < labelArr.length; i++) { | ||
labelArr[i] = labelArr[i][0].toUpperCase() + labelArr[i].slice(1); | ||
} | ||
return labelArr.join(' '); | ||
}; |