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 Api from "./Api";
import { ApiResponse } from "./ApiResponses"; import { ApiResponse } from "./ApiResponses";
import { AxiosPromise } from "axios"; import { AxiosPromise } from "axios";
import { getUserCurrentOrgId } from "selectors/organizationSelectors";
export interface PublishApplicationRequest { export interface PublishApplicationRequest {
applicationId: string; applicationId: string;
@ -24,9 +23,9 @@ export interface ApplicationResponsePayload {
pages?: ApplicationPagePayload[]; pages?: ApplicationPagePayload[];
} }
export interface FetchApplicationResponse extends ApiResponse { // export interface FetchApplicationResponse extends ApiResponse {
data: ApplicationResponsePayload & { pages: ApplicationPagePayload[] }; // data: ApplicationResponsePayload & { pages: ApplicationPagePayload[] };
} // }
export interface FetchApplicationsResponse extends ApiResponse { export interface FetchApplicationsResponse extends ApiResponse {
data: Array<ApplicationResponsePayload & { pages: ApplicationPagePayload[] }>; 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}; props.code.match(/2\d\d/) ? props.theme.colors.primary : Colors.RED};
`; `;
const TableWrapper = styled.div` // const TableWrapper = styled.div`
&&& { // &&& {
table { // table {
table-layout: fixed; // table-layout: fixed;
width: 100%; // width: 100%;
td { // td {
font-size: 12px; // font-size: 12px;
width: 50%; // width: 50%;
white-space: nowrap; // white-space: nowrap;
overflow: hidden; // overflow: hidden;
text-overflow: ellipsis; // text-overflow: ellipsis;
} // }
} // }
} // }
`; // `;
interface ReduxStateProps { interface ReduxStateProps {
responses: Record<string, ActionResponse | undefined>; responses: Record<string, ActionResponse | undefined>;
isRunning: Record<string, boolean>; isRunning: Record<string, boolean>;
} }
const ResponseHeadersView = (props: { data: Record<string, string[]> }) => { // const ResponseHeadersView = (props: { data: Record<string, string[]> }) => {
if (!props.data) return <div />; // if (!props.data) return <div />;
return ( // return (
<TableWrapper> // <TableWrapper>
<table className="bp3-html-table bp3-html-table-striped bp3-html-table-condensed"> // <table className="bp3-html-table bp3-html-table-striped bp3-html-table-condensed">
<thead> // <thead>
<tr> // <tr>
<th>Key</th> // <th>Key</th>
<th>Value</th> // <th>Value</th>
</tr> // </tr>
</thead> // </thead>
<tbody> // <tbody>
{Object.keys(props.data).map(k => ( // {Object.keys(props.data).map(k => (
<tr key={k}> // <tr key={k}>
<td>{k}</td> // <td>{k}</td>
<td>{props.data[k].join(", ")}</td> // <td>{props.data[k].join(", ")}</td>
</tr> // </tr>
))} // ))}
</tbody> // </tbody>
</table> // </table>
</TableWrapper> // </TableWrapper>
); // );
}; // };
type Props = ReduxStateProps & RouteComponentProps<APIEditorRouteParams>; type Props = ReduxStateProps & RouteComponentProps<APIEditorRouteParams>;

View File

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

View File

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

View File

@ -44,7 +44,6 @@ import {
moveActionError, moveActionError,
moveActionSuccess, moveActionSuccess,
updateActionSuccess, updateActionSuccess,
updateApiNameDraft,
fetchActionsForPage, fetchActionsForPage,
} from "actions/actionActions"; } from "actions/actionActions";
import { import {
@ -77,8 +76,7 @@ import { ToastType } from "react-toastify";
import AnalyticsUtil from "utils/AnalyticsUtil"; import AnalyticsUtil from "utils/AnalyticsUtil";
import * as log from "loglevel"; import * as log from "loglevel";
import { QUERY_CONSTANT } from "constants/QueryEditorConstants"; import { QUERY_CONSTANT } from "constants/QueryEditorConstants";
import { RestAction } from "entities/Action"; import { Action, RestAction } from "entities/Action";
import { validateEntityName } from "components/editorComponents/EntityNameComponent";
import { ActionData } from "reducers/entityReducers/actionsReducer"; import { ActionData } from "reducers/entityReducers/actionsReducer";
import { getActions } from "selectors/entitiesSelector"; 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( export function* runApiActionSaga(
reduxAction: ReduxAction<{ reduxAction: ReduxAction<{
id: string; id: string;
@ -574,15 +584,7 @@ export function* runApiActionSaga(
} }
if (dirty) { if (dirty) {
action = _.omit(transformRestAction(values), "id") as RestAction; action = _.omit(transformRestAction(values), "id") as RestAction;
jsonPathKeys = extractBindingsFromAction(action 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 = [];
}
} }
const { paginationField } = reduxAction.payload; const { paginationField } = reduxAction.payload;

View File

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

View File

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

View File

@ -7,7 +7,6 @@ import { getWidgets, getWidgetsMeta } from "sagas/selectors";
import * as log from "loglevel"; import * as log from "loglevel";
import "url-search-params-polyfill"; import "url-search-params-polyfill";
import { getPageList } from "./appViewSelectors"; import { getPageList } from "./appViewSelectors";
import _ from "lodash";
// TODO Commenting out for now as it is causing performance issues // TODO Commenting out for now as it is causing performance issues
// function getQueryParams() { // 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) .second(0)
.millisecond(0); .millisecond(0);
const dateFormat = props.dateFormat ? props.dateFormat : moment.ISO_8601; const dateFormat = props.dateFormat ? props.dateFormat : moment.ISO_8601;
const dateStr = moment().toISOString(); // const dateStr = moment().toISOString();
const todayDateString = today.format(dateFormat); const todayDateString = today.format(dateFormat);
if (dateString === undefined) { if (dateString === undefined) {
return { return {

View File

@ -135,7 +135,6 @@ class DropdownWidget extends BaseWidget<DropdownWidgetProps, WidgetState> {
selectedOption.value, selectedOption.value,
); );
} else if (this.props.selectionType === "MULTI_SELECT") { } else if (this.props.selectionType === "MULTI_SELECT") {
console.log(this.props, selectedOption);
const isAlreadySelected = this.props.selectedOptionValueArr.includes( const isAlreadySelected = this.props.selectedOptionValueArr.includes(
selectedOption.value, 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 "^6.10.2"
ajv-keywords "^3.4.1" 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: scriptjs@^2.5.8:
version "2.5.9" version "2.5.9"
resolved "https://registry.yarnpkg.com/scriptjs/-/scriptjs-2.5.9.tgz#343915cd2ec2ed9bfdde2b9875cd28f59394b35f" resolved "https://registry.yarnpkg.com/scriptjs/-/scriptjs-2.5.9.tgz#343915cd2ec2ed9bfdde2b9875cd28f59394b35f"