PromucFlow_constructor/app/client/src/components/editorComponents/utils.ts
Ayangade Adeoluwa 562e0bed00
chore: Fix Security vulnerabilities (#26241)
This PR fixes a security vulnerability.

For more context: https://github.com/appsmithorg/appsmith-ee/issues/2011


- Bug fix (non-breaking change which fixes an issue)
- Chore (housekeeping or task changes that don't impact user perception)

## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [x] Manual
- [x] Jest
- [x] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Shrikant Sharat Kandula <shrikantsharat.k@gmail.com>
2023-08-15 13:56:53 +05:30

54 lines
1.8 KiB
TypeScript

import type { JSAction } from "entities/JSCollection";
import { JSResponseState } from "./JSResponseView";
export const isHtml = (str: string) => {
const doc = new DOMParser().parseFromString(str, "text/html");
return Array.from(doc.body.childNodes).some(
(node: any) => node.nodeType === 1,
);
};
/**
* Returns state of the JSResponseview editor component
* @param currentFunction => Current function whose response is to be shown
* @param isDirty => Object containing JS Object functions with parse errors
* @param isExecuting => Object containing JS Object functions still executing
* @param isSaving => Whether any entity is still saving in the application
* @param responses => Object containing JS Object functions' responses
* @returns => state of the JSResponseview editor component
*/
export function getJSResponseViewState(
currentFunction: JSAction | null,
isDirty: Record<string, boolean>,
isExecuting: Record<string, boolean>,
isSaving: boolean,
responses: Record<string, any>,
): JSResponseState {
if (!currentFunction) return JSResponseState.NoResponse;
if (isExecuting[currentFunction.id] && isSaving)
return JSResponseState.IsUpdating;
if (isExecuting[currentFunction.id]) return JSResponseState.IsExecuting;
if (
!responses.hasOwnProperty(currentFunction.id) &&
!isExecuting.hasOwnProperty(currentFunction.id)
)
return JSResponseState.NoResponse;
if (
responses.hasOwnProperty(currentFunction.id) &&
isDirty[currentFunction.id]
)
return JSResponseState.IsDirty;
if (
responses.hasOwnProperty(currentFunction.id) &&
responses[currentFunction.id] === undefined
)
return JSResponseState.NoReturnValue;
if (responses.hasOwnProperty(currentFunction.id))
return JSResponseState.ShowResponse;
// Default state
return JSResponseState.NoResponse;
}