Merge branch 'fix/dry-run-stringify' into 'release'

JSON stringify fixes

See merge request theappsmith/internal-tools-client!777
This commit is contained in:
Hetu Nandu 2020-06-25 10:04:57 +00:00
commit 906521dcdd
13 changed files with 97 additions and 86 deletions

View File

@ -1,7 +1,6 @@
import Api from "./Api";
import { ApiResponse } from "./ApiResponses";
import { AxiosPromise } from "axios";
import { getUserCurrentOrgId } from "selectors/organizationSelectors";
export interface PublishApplicationRequest {
applicationId: string;
@ -24,9 +23,9 @@ export interface ApplicationResponsePayload {
pages?: ApplicationPagePayload[];
}
export interface FetchApplicationResponse extends ApiResponse {
data: ApplicationResponsePayload & { pages: ApplicationPagePayload[] };
}
// export interface FetchApplicationResponse extends ApiResponse {
// data: ApplicationResponsePayload & { pages: ApplicationPagePayload[] };
// }
export interface FetchApplicationsResponse extends ApiResponse {
data: Array<ApplicationResponsePayload & { pages: ApplicationPagePayload[] }>;

View File

@ -42,50 +42,50 @@ const StatusCodeText = styled(BaseText)<{ code: string }>`
props.code.match(/2\d\d/) ? props.theme.colors.primary : Colors.RED};
`;
const TableWrapper = styled.div`
&&& {
table {
table-layout: fixed;
width: 100%;
td {
font-size: 12px;
width: 50%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
`;
// const TableWrapper = styled.div`
// &&& {
// table {
// table-layout: fixed;
// width: 100%;
// td {
// font-size: 12px;
// width: 50%;
// white-space: nowrap;
// overflow: hidden;
// text-overflow: ellipsis;
// }
// }
// }
// `;
interface ReduxStateProps {
responses: Record<string, ActionResponse | undefined>;
isRunning: Record<string, boolean>;
}
const ResponseHeadersView = (props: { data: Record<string, string[]> }) => {
if (!props.data) return <div />;
return (
<TableWrapper>
<table className="bp3-html-table bp3-html-table-striped bp3-html-table-condensed">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{Object.keys(props.data).map(k => (
<tr key={k}>
<td>{k}</td>
<td>{props.data[k].join(", ")}</td>
</tr>
))}
</tbody>
</table>
</TableWrapper>
);
};
// const ResponseHeadersView = (props: { data: Record<string, string[]> }) => {
// if (!props.data) return <div />;
// return (
// <TableWrapper>
// <table className="bp3-html-table bp3-html-table-striped bp3-html-table-condensed">
// <thead>
// <tr>
// <th>Key</th>
// <th>Value</th>
// </tr>
// </thead>
// <tbody>
// {Object.keys(props.data).map(k => (
// <tr key={k}>
// <td>{k}</td>
// <td>{props.data[k].join(", ")}</td>
// </tr>
// ))}
// </tbody>
// </table>
// </TableWrapper>
// );
// };
type Props = ReduxStateProps & RouteComponentProps<APIEditorRouteParams>;

View File

@ -4,7 +4,7 @@ import { StyledDatePicker } from "./StyledControls";
import moment from "moment-timezone";
import styled from "styled-components";
import { TimePrecision } from "@blueprintjs/datetime";
import BaseWidget, { WidgetProps } from "widgets/BaseWidget";
import { WidgetProps } from "widgets/BaseWidget";
const DatePickerControlWrapper = styled.div`
display: flex;

View File

@ -47,11 +47,8 @@ export const CreateApplicationForm = (props: Props) => {
const mapStateToProps = (state: AppState, props: Props): any => {
const orgId = props.orgId;
console.log(orgId, " orgId in mapStateToProps");
return {
initialValues: {
orgId: props.orgId,
},
initialValues: { orgId },
};
};

View File

@ -44,7 +44,6 @@ import {
moveActionError,
moveActionSuccess,
updateActionSuccess,
updateApiNameDraft,
fetchActionsForPage,
} from "actions/actionActions";
import {
@ -77,8 +76,7 @@ import { ToastType } from "react-toastify";
import AnalyticsUtil from "utils/AnalyticsUtil";
import * as log from "loglevel";
import { QUERY_CONSTANT } from "constants/QueryEditorConstants";
import { RestAction } from "entities/Action";
import { validateEntityName } from "components/editorComponents/EntityNameComponent";
import { Action, RestAction } from "entities/Action";
import { ActionData } from "reducers/entityReducers/actionsReducer";
import { getActions } from "selectors/entitiesSelector";
@ -549,6 +547,18 @@ export function* deleteActionSaga(
}
}
export function extractBindingsFromAction(action: Action) {
const bindings: string[] = [];
action.dynamicBindingPathList.forEach(a => {
const value = _.get(action, a.key);
if (isDynamicValue(value)) {
const { jsSnippets } = getDynamicBindings(value);
bindings.push(...jsSnippets.filter(jsSnippet => !!jsSnippet));
}
});
return bindings;
}
export function* runApiActionSaga(
reduxAction: ReduxAction<{
id: string;
@ -574,15 +584,7 @@ export function* runApiActionSaga(
}
if (dirty) {
action = _.omit(transformRestAction(values), "id") as RestAction;
const actionString = JSON.stringify(action);
if (isDynamicValue(actionString)) {
const { jsSnippets } = getDynamicBindings(actionString);
// Replace cause the existing keys could have been updated
jsonPathKeys = jsSnippets.filter(jsSnippet => !!jsSnippet);
} else {
jsonPathKeys = [];
}
jsonPathKeys = extractBindingsFromAction(action as RestAction);
}
const { paginationField } = reduxAction.payload;

View File

@ -16,15 +16,13 @@ import { fetchActions } from "actions/actionActions";
import { CURL } from "constants/ApiConstants";
import { changeApi } from "actions/apiPaneActions";
import { getCurrentOrgId } from "selectors/organizationSelectors";
import transformCurlImport from "transformers/CurlImportTransformer";
export function* curlImportSaga(action: ReduxAction<CurlImportRequest>) {
const { type, pageId, name } = action.payload;
let { curl } = action.payload;
try {
// Transform to add quotes if not present
curl = `${curl.charAt(0) !== '"' ? '"' : ""}${curl}${
curl.charAt(curl.length - 1) !== '"' ? '"' : ""
}`;
curl = transformCurlImport(curl);
const organizationId = yield select(getCurrentOrgId);
const request: CurlImportRequest = {
type,

View File

@ -27,7 +27,12 @@ import {
getCurrentPageId,
} from "selectors/editorSelectors";
import { change, initialize } from "redux-form";
import { getAction, getActionParams, getActionTimeout } from "./ActionSagas";
import {
extractBindingsFromAction,
getAction,
getActionParams,
getActionTimeout,
} from "./ActionSagas";
import { AppState } from "reducers";
import ActionAPI, {
PaginationField,
@ -40,12 +45,12 @@ import { changeQuery, deleteQuerySuccess } from "actions/queryPaneActions";
import { AppToaster } from "components/editorComponents/ToastComponent";
import { ToastType } from "react-toastify";
import { PageAction } from "constants/ActionConstants";
import { isDynamicValue, getDynamicBindings } from "utils/DynamicBindingUtils";
import { isDynamicValue } from "utils/DynamicBindingUtils";
import AnalyticsUtil from "utils/AnalyticsUtil";
import { GenericApiResponse } from "api/ApiResponses";
import { validateResponse } from "./ErrorSagas";
import { getQueryName } from "selectors/entitiesSelector";
import { RestAction } from "entities/Action";
import { QueryAction, RestAction } from "entities/Action";
const getQueryDraft = (state: AppState, id: string) => {
const drafts = state.entities.actionDrafts;
@ -146,7 +151,6 @@ function* updateDynamicBindingsSaga(
const isDynamic = isDynamicValue(value);
let dynamicBindings: Property[] = values.dynamicBindingPathList || [];
console.log({ field, value, isDynamic, dynamicBindings });
const fieldExists = _.some(dynamicBindings, { key: field });
if (!isDynamic && fieldExists) {
@ -214,7 +218,7 @@ function* handleMoveOrCopySaga(actionPayload: ReduxAction<{ id: string }>) {
export function* executeQuerySaga(
actionPayload: ReduxAction<{
action: RestAction;
action: QueryAction;
actionId: string;
paginationField: PaginationField;
}>,
@ -224,7 +228,7 @@ export function* executeQuerySaga(
values,
dirty,
}: {
values: RestAction;
values: QueryAction;
dirty: boolean;
valid: boolean;
} = yield select(getFormData, QUERY_EDITOR_FORM_NAME);
@ -233,16 +237,8 @@ export function* executeQuerySaga(
let jsonPathKeys = actionObject.jsonPathKeys;
if (dirty) {
action = _.omit(values, "id") as RestAction;
const actionString = JSON.stringify(action);
if (isDynamicValue(actionString)) {
const { jsSnippets } = getDynamicBindings(actionString);
// Replace cause the existing keys could have been updated
jsonPathKeys = jsSnippets.filter(jsSnippet => !!jsSnippet);
} else {
jsonPathKeys = [];
}
action = _.omit(values, "id") as QueryAction;
jsonPathKeys = extractBindingsFromAction(action as QueryAction);
}
const { paginationField } = actionPayload.payload;

View File

@ -7,7 +7,6 @@ import { getWidgets, getWidgetsMeta } from "sagas/selectors";
import * as log from "loglevel";
import "url-search-params-polyfill";
import { getPageList } from "./appViewSelectors";
import _ from "lodash";
// TODO Commenting out for now as it is causing performance issues
// function getQueryParams() {

View File

@ -0,0 +1,22 @@
import transformCurlImport from "transformers/CurlImportTransformer";
describe("CurlImportTransformer", () => {
it("has quotes in start and end and escapes special characters", () => {
const inputs = [
`curl -X GET`,
`"curl -X GET`,
`curl -X GET"`,
`curl google.com\n`,
];
const outputs = [
`"curl -X GET"`,
`"\\"curl -X GET"`,
`"curl -X GET\\""`,
`"curl google.com\\n"`,
];
inputs.forEach((input, index) => {
const result = transformCurlImport(input);
expect(result).toBe(outputs[index]);
});
});
});

View File

@ -0,0 +1,3 @@
export default (curlString: string): string => {
return JSON.stringify(curlString);
};

View File

@ -400,7 +400,7 @@ export const VALIDATORS: Record<ValidationType, Validator> = {
.second(0)
.millisecond(0);
const dateFormat = props.dateFormat ? props.dateFormat : moment.ISO_8601;
const dateStr = moment().toISOString();
// const dateStr = moment().toISOString();
const todayDateString = today.format(dateFormat);
if (dateString === undefined) {
return {

View File

@ -135,7 +135,6 @@ class DropdownWidget extends BaseWidget<DropdownWidgetProps, WidgetState> {
selectedOption.value,
);
} else if (this.props.selectionType === "MULTI_SELECT") {
console.log(this.props, selectedOption);
const isAlreadySelected = this.props.selectedOptionValueArr.includes(
selectedOption.value,
);

View File

@ -13378,10 +13378,6 @@ schema-utils@^2.0.1, schema-utils@^2.5.0, schema-utils@^2.6.0, schema-utils@^2.6
ajv "^6.10.2"
ajv-keywords "^3.4.1"
screenfull@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/screenfull/-/screenfull-5.0.2.tgz#b9acdcf1ec676a948674df5cd0ff66b902b0bed7"
scriptjs@^2.5.8:
version "2.5.9"
resolved "https://registry.yarnpkg.com/scriptjs/-/scriptjs-2.5.9.tgz#343915cd2ec2ed9bfdde2b9875cd28f59394b35f"