change events success code from 200 to 2xx (close #2335) (#2342)

This commit is contained in:
IMRAN KHAN 2019-06-07 18:12:32 +05:30 committed by Rikin Kachhia
parent ba96697abc
commit de09c29003
7 changed files with 155 additions and 233 deletions

View File

@ -18,6 +18,7 @@ import {
} from './FilterActions';
import { ordinalColSort, convertDateTimeToLocale } from '../utils';
import '../TableCommon/EventReactTableOverrides.css';
import { verifySuccessStatus } from '../utils';
const ViewRows = ({
curTriggerName,
@ -256,12 +257,11 @@ const ViewRows = ({
const invocationRowsData = [];
currentRow.logs.map((r, rowIndex) => {
const newRow = {};
const status =
r.status === 200 ? (
<i className={styles.invocationSuccess + ' fa fa-check'} />
) : (
<i className={styles.invocationFailure + ' fa fa-times'} />
);
const status = verifySuccessStatus(r.status) ? (
<i className={styles.invocationSuccess + ' fa fa-check'} />
) : (
<i className={styles.invocationFailure + ' fa fa-times'} />
);
// Insert cells corresponding to all rows
invocationColumns.forEach(col => {

View File

@ -5,9 +5,7 @@ import Tabs from 'react-bootstrap/lib/Tabs';
import Tab from 'react-bootstrap/lib/Tab';
import 'brace/mode/json';
import 'react-table/react-table.css';
import { deleteItem, vExpandRow, vCollapseRow } from './ViewActions'; // eslint-disable-line no-unused-vars
import FilterQuery from './FilterQuery';
import parseRowData from '../StreamingLogs/util';
import {
setOrderCol,
setOrderType,
@ -17,7 +15,12 @@ import {
setLimit,
addOrder,
} from './FilterActions';
import { ordinalColSort, convertDateTimeToLocale } from '../utils';
import {
ordinalColSort,
convertDateTimeToLocale,
verifySuccessStatus,
parseRowData,
} from '../utils';
import '../TableCommon/EventReactTableOverrides.css';
import * as tooltip from '../Common/Tooltips';
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
@ -221,6 +224,14 @@ const ViewRows = ({
}
};
const successIcon = (
<i className={styles.invocationSuccess + 'fa fa-check'} />
);
const failureIcon = (
<i className={styles.invocationFailure + ' fa fa-times'} />
);
const renderTableBody = () => {
if (newCurRows.length === 0) {
return <div> No rows found. </div>;
@ -275,12 +286,9 @@ const ViewRows = ({
const responseData = [];
currentRow.logs.map((r, rowIndex) => {
const newRow = {};
const status =
r.status === 200 ? (
<i className={styles.invocationSuccess + ' fa fa-check'} />
) : (
<i className={styles.invocationFailure + ' fa fa-times'} />
);
const status = verifySuccessStatus(r.status)
? successIcon
: failureIcon;
requestData.push(parseRowData(r, 'request'));
responseData.push(parseRowData(r, 'response'));
@ -429,36 +437,26 @@ const ViewRows = ({
>
{finalResponse.status_code
? [
'Status Code: ',
finalResponse.status_code === 200 ? (
<i
className={
styles.invocationSuccess +
' fa fa-check'
'Status Code: ',
verifySuccessStatus(
finalResponse.status_code
)
? successIcon
: failureIcon,
finalResponse.status_code,
' ',
<OverlayTrigger
placement="top"
overlay={
tooltip.statusCodeDescription
}
/>
) : (
<i
className={
styles.invocationFailure +
' fa fa-times'
}
/>
),
finalResponse.status_code,
' ',
<OverlayTrigger
placement="top"
overlay={
tooltip.statusCodeDescription
}
>
<i
className="fa fa-question-circle"
aria-hidden="true"
/>
</OverlayTrigger>,
]
>
<i
className="fa fa-question-circle"
aria-hidden="true"
/>
</OverlayTrigger>,
]
: null}
</div>
<AceEditor

View File

@ -19,6 +19,7 @@ import {
import { ordinalColSort, convertDateTimeToLocale } from '../utils';
import Spinner from '../../../Common/Spinner/Spinner';
import '../TableCommon/EventReactTableOverrides.css';
import { verifySuccessStatus } from '../utils';
const ViewRows = ({
curTriggerName,
@ -262,12 +263,11 @@ const ViewRows = ({
const invocationRowsData = [];
currentRow.logs.map((r, rowIndex) => {
const newRow = {};
const status =
r.status === 200 ? (
<i className={styles.invocationSuccess + ' fa fa-check'} />
) : (
<i className={styles.invocationFailure + ' fa fa-times'} />
);
const status = verifySuccessStatus(r.status) ? (
<i className={styles.invocationSuccess + ' fa fa-check'} />
) : (
<i className={styles.invocationFailure + ' fa fa-times'} />
);
// Insert cells corresponding to all rows
invocationColumns.forEach(col => {

View File

@ -7,7 +7,7 @@ import Tabs from 'react-bootstrap/lib/Tabs';
import Tab from 'react-bootstrap/lib/Tab';
import RedeliverEvent from '../TableCommon/RedeliverEvent';
import TableHeader from '../TableCommon/TableHeader';
import parseRowData from './util';
import { parseRowData, verifySuccessStatus } from '../utils';
import {
loadEventLogs,
setTrigger,
@ -144,7 +144,8 @@ class StreamingLogs extends Component {
const newRow = {};
const status =
r.status === 200 ? (
// 2xx is success
verifySuccessStatus(r.status) ? (
<i className={styles.invocationSuccess + ' fa fa-check'} />
) : (
<i className={styles.invocationFailure + ' fa fa-times'} />
@ -292,32 +293,32 @@ class StreamingLogs extends Component {
>
{finalResponse.status_code
? [
'Status Code: ',
finalResponse.status_code === 200 ? (
<i
className={
styles.invocationSuccess + ' fa fa-check'
}
/>
) : (
<i
className={
styles.invocationFailure + ' fa fa-times'
}
/>
),
finalResponse.status_code,
' ',
<OverlayTrigger
placement="top"
overlay={tooltip.statusCodeDescription}
>
<i
className="fa fa-question-circle"
aria-hidden="true"
/>
</OverlayTrigger>,
]
'Status Code: ',
verifySuccessStatus(finalResponse.status_code) ? (
<i
className={
styles.invocationSuccess + ' fa fa-check'
}
/>
) : (
<i
className={
styles.invocationFailure + ' fa fa-times'
}
/>
),
finalResponse.status_code,
' ',
<OverlayTrigger
placement="top"
overlay={tooltip.statusCodeDescription}
>
<i
className="fa fa-question-circle"
aria-hidden="true"
/>
</OverlayTrigger>,
]
: null}
</div>
<AceEditor

View File

@ -1,53 +0,0 @@
const parseRowData = (row, dataType) => {
switch (dataType) {
case 'request':
switch (row.request.version) {
case '2':
const data = row.request.payload;
return {
data: data,
headers: row.request.headers,
};
default:
return {
data: row.request,
};
}
case 'response':
let data;
switch (row.response.version) {
case '2':
try {
// Handle graphql-engine server error message
if (row.response.data.message) {
data = row.response.data;
} else {
data = JSON.parse(row.response.data.body);
}
} catch (e) {
console.error(e);
data = row.response.data.body;
}
return {
data: data,
headers: row.response.data.headers,
status_code: row.response.data.status,
};
default:
try {
data = JSON.parse(row.response);
} catch (e) {
console.error(e);
data = row.response;
}
return {
data: data,
status_code: row.status,
};
}
default:
return false;
}
};
export default parseRowData;

View File

@ -14,6 +14,8 @@ import AceEditor from 'react-ace';
import 'brace/mode/json';
import Button from '../../../Common/Button/Button';
import { verifySuccessStatus } from '../utils';
class RedeliverEvent extends Component {
constructor(props) {
super(props);
@ -89,22 +91,21 @@ class RedeliverEvent extends Component {
const invocationRowsData = [];
log.eventInvocations.map(r => {
const newRow = {};
const status =
r.status === 200 ? (
<i
className={
styles.invocationSuccess +
' fa fa-check invocationsSuccess ' +
styles.tabletdCenter
}
/>
) : (
<i
className={
styles.invocationFailure + ' fa fa-times invocationsFailure'
}
/>
);
const status = verifySuccessStatus(r.status) ? (
<i
className={
styles.invocationSuccess +
' fa fa-check invocationsSuccess ' +
styles.tabletdCenter
}
/>
) : (
<i
className={
styles.invocationFailure + ' fa fa-times invocationsFailure'
}
/>
);
// Insert cells corresponding to all rows
invocationColumns.forEach(col => {

View File

@ -1,4 +1,9 @@
const ordinalColSort = (a, b) => {
// check 2xx success status codes
export const verifySuccessStatus = status => {
return /^2[0-9][0-9]$/.test(status.toString());
};
export const ordinalColSort = (a, b) => {
if (a.ordinal_position < b.ordinal_position) {
return -1;
}
@ -18,7 +23,7 @@ const findFKConstraint = (curTable, column) => {
);
};
const findTableFromRel = (schemas, curTable, rel) => {
export const findTableFromRel = (schemas, curTable, rel) => {
let rtable = null;
// for view
@ -52,77 +57,7 @@ const findTableFromRel = (schemas, curTable, rel) => {
return schemas.find(x => x.table_name === rtable);
};
const findAllFromRel = (schemas, curTable, rel) => {
let rtable = null;
let lcol;
let rcol;
const foreignKeyConstraintOn = rel.rel_def.foreign_key_constraint_on;
// for view
if (rel.rel_def.manual_configuration !== undefined) {
rtable = rel.rel_def.manual_configuration.remote_table;
if (rtable.schema) {
rtable = rtable.name;
}
const columnMapping = rel.rel_def.manual_configuration.column_mapping;
lcol = Object.keys(columnMapping)[0];
rcol = columnMapping[lcol];
}
// for table
if (foreignKeyConstraintOn !== undefined) {
// for object relationship
if (rel.rel_type === 'object') {
lcol = foreignKeyConstraintOn;
const fkc = findFKConstraint(curTable, lcol);
if (fkc) {
rtable = fkc.ref_table;
rcol = fkc.column_mapping[lcol];
}
}
// for array relationship
if (rel.rel_type === 'array') {
rtable = foreignKeyConstraintOn.table;
rcol = foreignKeyConstraintOn.column;
if (rtable.schema) {
// if schema exists, its not public schema
rtable = rtable.name;
}
const rtableSchema = schemas.find(x => x.table_name === rtable);
const rfkc = findFKConstraint(rtableSchema, rcol);
lcol = rfkc.column_mapping[rcol];
}
}
return { lcol, rtable, rcol };
};
const getIngForm = string => {
return (
(string[string.length - 1] === 'e'
? string.slice(0, string.length - 1)
: string) + 'ing'
);
};
const getEdForm = string => {
return (
(string[string.length - 1] === 'e'
? string.slice(0, string.length - 1)
: string) + 'ed'
);
};
const escapeRegExp = string => {
return string.replace(/([.*+?^${}()|[\]\\])/g, '\\$1');
};
const getTableColumns = tableSchema => {
export const getTableColumns = tableSchema => {
if (tableSchema) {
return tableSchema.columns.map(colObj => ({
name: colObj.column_name,
@ -132,7 +67,7 @@ const getTableColumns = tableSchema => {
return [];
};
const convertDateTimeToLocale = dateTime => {
export const convertDateTimeToLocale = dateTime => {
const options = {
hourCycle: 'h24',
day: 'numeric',
@ -148,7 +83,7 @@ const convertDateTimeToLocale = dateTime => {
return new Date(dateTime + 'Z').toLocaleString('en-US', options);
};
const getEventTriggersQuery = (triggerNames) => {
export const getEventTriggersQuery = triggerNames => {
let whereQuery = '';
const triggerLength = triggerNames.length;
if (triggerLength !== 0) {
@ -156,7 +91,7 @@ const getEventTriggersQuery = (triggerNames) => {
whereQuery = 'where';
triggerNames.forEach((triggerName, index) => {
whereQuery = whereQuery + ` hdb_et.name='${triggerName}'`;
if ((index + 1) !== triggerLength) {
if (index + 1 !== triggerLength) {
whereQuery = whereQuery + ' and';
}
});
@ -209,14 +144,54 @@ FROM
};
};
export {
ordinalColSort,
findTableFromRel,
findAllFromRel,
getEdForm,
getIngForm,
escapeRegExp,
getTableColumns,
convertDateTimeToLocale,
getEventTriggersQuery,
export const parseRowData = (row, dataType) => {
switch (dataType) {
case 'request':
switch (row.request.version) {
case '2':
const data = row.request.payload;
return {
data: data,
headers: row.request.headers,
};
default:
return {
data: row.request,
};
}
case 'response':
let data;
switch (row.response.version) {
case '2':
try {
// Handle graphql-engine server error message
if (row.response.data.message) {
data = row.response.data;
} else {
data = JSON.parse(row.response.data.body);
}
} catch (e) {
console.error(e);
data = row.response.data.body;
}
return {
data: data,
headers: row.response.data.headers,
status_code: row.response.data.status,
};
default:
try {
data = JSON.parse(row.response);
} catch (e) {
console.error(e);
data = row.response;
}
return {
data: data,
status_code: row.status,
};
}
default:
return false;
}
};