Skip to content

Commit b513422

Browse files
authored
Merge pull request #45 from contentstack/fix/ECO-3312
fix:ECO-3320
2 parents b91535d + 2f63001 commit b513422

File tree

21 files changed

+24339
-186
lines changed

21 files changed

+24339
-186
lines changed

ui/package-lock.json

Lines changed: 24231 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"name": "marketplace-json-editor-app-ui",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": true,
55
"dependencies": {
6-
"@contentstack/app-sdk": "^1.2.0",
7-
"@types/node": "^12.20.37",
6+
"@contentstack/app-sdk": "^1.5.0",
7+
"@datadog/browser-rum": "^4.25.0",
8+
"@playwright/test": "^1.35.1",
89
"@types/react": "^17.0.35",
910
"@types/react-dom": "^17.0.11",
10-
"@datadog/browser-rum": "^4.25.0",
1111
"ajv": "^8.8.2",
12+
"axios": "^1.4.0",
1213
"brace": "^0.11.1",
14+
"jotai": "^2.2.1",
1315
"jsoneditor": "^9.5.8",
1416
"jsoneditor-react": "^3.1.2",
1517
"prop-types": "^15.8.1",
@@ -19,18 +21,23 @@
1921
"react-scripts": "4.0.3",
2022
"sass": "^1.43.4",
2123
"tippy.js": "^6.3.7",
22-
"trackjs": "^3.10.1",
2324
"typescript": "^4.5.2",
2425
"web-vitals": "^1.1.2"
2526
},
2627
"scripts": {
27-
"start": "export PORT=4000 && react-scripts start",
28+
"start": "export PORT=3000 && react-scripts start",
2829
"build": "GENERATE_SOURCEMAP=false react-scripts build",
2930
"test": "jest",
3031
"eject": "react-scripts eject",
3132
"prettify": "prettier --write .",
3233
"lint:fix": "eslint --fix --ext .js,.jsx,.ts,.tsx . --ignore-pattern './node_modules/' --ignore-pattern './buid/'",
33-
"precommit": "npm run prettify && npm run lint:fix"
34+
"precommit": "npm run prettify && npm run lint:fix",
35+
"test:chrome": "npx playwright test --config=playwright.config.ts --project=Chromium",
36+
"test:firefox": "npx playwright test --config=playwright.config.ts --project=firefox",
37+
"test:safari": "npx playwright test --config=playwright.config.ts --project=safari",
38+
"test:chrome-headed": "npx playwright test --headed --config=playwright.config.ts --project=Chromium",
39+
"test:firefox-headed": "npx playwright test --headed --config=playwright.config.ts --project=firefox",
40+
"test:safari-headed": "npx playwright test --headed --config=playwright.config.ts --project=safari"
3441
},
3542
"eslintConfig": {
3643
"extends": [
@@ -59,6 +66,7 @@
5966
"@testing-library/jest-dom": "^5.16.0",
6067
"@testing-library/react": "^12.1.2",
6168
"@types/jest": "^26.0.14",
69+
"@types/node": "^20.3.2",
6270
"@typescript-eslint/eslint-plugin": "^5.4.0",
6371
"@typescript-eslint/parser": "^5.4.0",
6472
"babel-jest": "^26.6.0",
@@ -75,4 +83,4 @@
7583
"jest-fetch-mock": "^3.0.3",
7684
"ts-jest": "^26.5.6"
7785
}
78-
}
86+
}

ui/playwright-report/index.html

Lines changed: 62 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const config: PlaywrightTestConfig = {
1414
* globalSetup & teardown of test data
1515
* globalTeardown: require.resolve("./tests/global-teardown"),
1616
*/
17-
globalSetup: require.resolve("./tests/global-setup"),
17+
globalSetup: require.resolve("../ui/tests/global-setup"),
1818

1919

20-
testDir: "./tests/e2e",
20+
testDir: "../ui/tests/e2e",
2121
/* Maximum time one test can run for. */
2222
timeout: 10 * 10000,
2323
expect: {
@@ -42,7 +42,7 @@ const config: PlaywrightTestConfig = {
4242
actionTimeout: 0,
4343
screenshot: "off",
4444
video: "off",
45-
viewport: { width: 1200, height: 720 },
45+
viewport: { width: 1000, height: 720 },
4646
trace: "on-first-retry",
4747
baseURL: process.env.APP_HOST_URL,
4848
launchOptions: {

ui/src/components/ErrorBoundary/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable react/prop-types */
22
/* eslint-disable react/destructuring-assignment */
33
import React from "react";
4-
import TrackJS from "../../trackjs";
54
import { datadogRum } from '@datadog/browser-rum';
65

76
interface MyProps {
@@ -12,7 +11,7 @@ interface MyState {
1211
hasError: boolean;
1312
}
1413

15-
//datadog-rum Installation
14+
// datadog-rum Installation
1615
datadogRum.init({
1716
applicationId: `${process.env.REACT_APP_DATADOG_RUM_APPLICATION_ID}`,
1817
clientToken: `${process.env.REACT_APP_DATADOG_RUM_CLIENT_TOKEN}`,
@@ -27,7 +26,7 @@ datadogRum.init({
2726
useCrossSiteSessionCookie: true,
2827
});
2928

30-
//sending MetaData to Datadog RUM
29+
// sending MetaData to Datadog RUM
3130
datadogRum.setGlobalContextProperty('Application Type', 'Marketplace');
3231
datadogRum.setGlobalContextProperty('Application Name', 'JSON Editor App');
3332

@@ -38,16 +37,12 @@ class ErrorBoundary extends React.Component<MyProps, MyState> {
3837
}
3938

4039
static getDerivedStateFromError(error: any) {
41-
// error tracker for error reporting service
42-
TrackJS.trackError(error);
4340
// Update state so the next render will show the fallback UI.
4441
console.warn(error); // Remove this line if not required.
4542
return { hasError: true };
4643
}
4744

4845
componentDidCatch(error: any, errorInfo: any) {
49-
// error tracker for error reporting service
50-
TrackJS.trackError(error);
5146
// You can also log the error to an error reporting service
5247
// logErrorToMyService(error, errorInfo);
5348
console.error("errorInfo ", errorInfo);
@@ -56,8 +51,6 @@ class ErrorBoundary extends React.Component<MyProps, MyState> {
5651

5752
render() {
5853
if (this?.state?.hasError) {
59-
// error tracker for error reporting service
60-
TrackJS.trackError(this?.state?.hasError);
6154
// You can render any custom fallback UI
6255
return <h1>Something went wrong.</h1>;
6356
}

ui/src/containers/App/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from "react";
22
import { HashRouter, Route, Routes, Navigate } from "react-router-dom";
3-
import TrackJS from "../../trackjs";
43
import ErrorBoundary from "../../components/ErrorBoundary";
54
import ConfigScreen from "../ConfigScreen";
65
import CustomField from "../CustomField";
@@ -17,8 +16,6 @@ const HomeRedirectHandler = function () {
1716
return null;
1817
};
1918

20-
// Track.js installation
21-
TrackJS.installation();
2219

2320
/* App - The main app component that should be rendered */
2421
const App: React.FC = function () {

ui/src/containers/ConfigScreen/index.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import tippy from "tippy.js";
1111
import localeTexts from "../../common/locale/en-us";
1212
import constants from "../../common/constants";
1313
import { mergeObjects } from "../../common/utils";
14-
import TrackJS from "../../trackjs";
1514
import { TypeAppSdkConfigState } from "../../common/types";
1615

1716
/* Import node module CSS */
@@ -50,9 +49,7 @@ const ConfigScreen: React.FC = function () {
5049

5150
useEffect(() => {
5251
ContentstackAppSdk.init()
53-
.then(async (appSdk:AppSdkProps) => {
54-
//Adding Track.js metadata
55-
TrackJS.addMetadata(appSdk);
52+
.then(async (appSdk) => {
5653
const sdkConfigData = appSdk?.location?.AppConfigWidget?.installation;
5754
if (sdkConfigData) {
5855
const installationDataFromSDK =
@@ -70,11 +67,6 @@ const ConfigScreen: React.FC = function () {
7067
setIsStringified(
7168
state?.installationData?.configuration?.isStringified
7269
);
73-
// setting metadata for js error tracker
74-
addMetadata("stack", `${appSdk?.stack._data.name}`);
75-
addMetadata("organization", `${appSdk?.currentUser.defaultOrganization}`);
76-
addMetadata("api_key", `${stackKey}`);
77-
addMetadata("user_uid", `${appSdk?.stack._data.collaborators[0].uid}`);
7870
}
7971
})
8072
.catch((error) => {

ui/src/containers/CustomField/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useEffect, useState } from "react";
22
import ContentstackAppSdk from "@contentstack/app-sdk";
33
import constants from "../../common/constants";
44
import { isEmpty } from "../../common/utils";
5-
import TrackJS from "../../trackjs";
65
import { TypeSDKData } from "../../common/types";
76
import "./styles.scss";
87
import JSONEditor from "../../components/jsoneditor";
@@ -14,7 +13,7 @@ const CustomField: React.FC = function () {
1413
appSdkInitialized: false,
1514
});
1615
const [jsonData, setJsonData] = useState<Array<any>>([{}]);
17-
const [saceJsonData, setSaveJsonData] = useState<Array<any>>([{}]);
16+
const [saveJsonData, setSaveJsonData] = useState<Array<any>>([{}]);
1817
let isStringified: any;
1918

2019
const toStringify = (localConfig: any, globalConfig: any) => {
@@ -30,9 +29,6 @@ const CustomField: React.FC = function () {
3029
useEffect(() => {
3130
ContentstackAppSdk.init()
3231
.then(async (appSdk) => {
33-
// Adding Track.js metadata
34-
TrackJS.addMetadata(appSdk);
35-
3632
const config = await appSdk?.getConfig();
3733
setState({
3834
config,
@@ -81,8 +77,8 @@ const CustomField: React.FC = function () {
8177
};
8278

8379
useEffect(() => {
84-
state?.location?.CustomField?.field?.setData(saceJsonData);
85-
}, [saceJsonData]);
80+
state?.location?.CustomField?.field?.setData(saveJsonData);
81+
}, [saveJsonData]);
8682

8783
return (
8884
<div className="layout-container">

ui/src/hooks/useAnalytics.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import { useAppSdk } from './useAppSdk';
1+
import { useCallback } from "react";
2+
import { useAppSdk } from "./useAppSdk";
23

3-
const useAnalytics = () => {
4-
const [appSdk] = useAppSdk();
4+
const ENV: string = process.env.NODE_ENV || "";
55

6-
const trackEvent = (event: string, eventData: any = {}) => {
7-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8-
// @ts-ignore
9-
return appSdk?.pulse(event, eventData);
10-
};
6+
/**
7+
* useAnalytics hook to track user actions and events in application
8+
*/
9+
const useAnalytics = () => {
10+
const [appSDK] = useAppSdk();
11+
const trackEvent = useCallback(
12+
(event: string, eventData: any = {}) => {
13+
if (ENV === "production") {
14+
appSDK?.pulse(event, eventData);
15+
}
16+
},
17+
[appSDK]
18+
);
1119

1220
return { trackEvent };
1321
};

ui/src/hooks/useAppSdk.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const appSdkRefAtom = atom<Extension | null>(null);
1313
* To be used during Sdk initialization
1414
*/
1515
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
16+
// eslint-disable-next-line arrow-body-style
1617
export const useAppSdk = (): [Extension | null, any] => {
1718
return useAtom(appSdkRefAtom);
1819
};

0 commit comments

Comments
 (0)