Skip to content

Commit 87a2f7e

Browse files
authored
Merge pull request #19 from contentstack/feature/ESI-554-new-updates
UI texts changed as per doc team's review.
2 parents 0a83409 + e69a22e commit 87a2f7e

File tree

10 files changed

+116
-11
lines changed

10 files changed

+116
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ node_modules/
2525
.eslintcache
2626
.dccache
2727
ui/.dccache
28+
ui/.env
29+
api/.env
30+
.env

ui/package-lock.json

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

ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"react-scripts": "4.0.3",
1919
"sass": "^1.43.4",
2020
"tippy.js": "^6.3.7",
21+
"trackjs": "^3.10.1",
2122
"typescript": "^4.5.2",
2223
"web-vitals": "^1.1.2"
2324
},

ui/src/common/locale/en-us/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ export default {
22
configFields: {
33
entrySaveRadioButton: {
44
label: "Data format In Entry",
5-
help: "You can select the structure of data you want to save in the entry",
5+
help: "Select the structure of the data you want to save in the entry.",
66
instruction:
7-
"You can select the structure of data you want to save in the entry. You can either save data in a stringified format or as a JSON object.",
7+
"You can select the structure of the data you want to save in the entry. You can either save the data as a string or as a JSON object.",
88
jsonObject: "JSON Object",
99
jsonStringified: "JSON Stringified",
1010
},

ui/src/components/ErrorBoundary/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable react/prop-types */
22
/* eslint-disable react/destructuring-assignment */
33
import React from "react";
4+
import TrackJS from "../../trackjs";
45

56
interface MyProps {}
67

@@ -15,20 +16,26 @@ class ErrorBoundary extends React.Component<MyProps, MyState> {
1516
}
1617

1718
static getDerivedStateFromError(error: any) {
19+
// error tracker for error reporting service
20+
TrackJS.trackError(error);
1821
// Update state so the next render will show the fallback UI.
1922
console.warn(error); // Remove this line if not required.
2023
return { hasError: true };
2124
}
2225

2326
componentDidCatch(error: any, errorInfo: any) {
27+
// error tracker for error reporting service
28+
TrackJS.trackError(error);
2429
// You can also log the error to an error reporting service
2530
// logErrorToMyService(error, errorInfo);
2631
console.error("errorInfo ", errorInfo);
2732
throw new Error(errorInfo);
2833
}
2934

3035
render() {
31-
if (this.state.hasError) {
36+
if (this?.state?.hasError) {
37+
// error tracker for error reporting service
38+
TrackJS.trackError(this?.state?.hasError);
3239
// You can render any custom fallback UI
3340
return <h1>Something went wrong.</h1>;
3441
}

ui/src/containers/App/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from "react";
22
import { HashRouter, Route, Routes, Navigate } from "react-router-dom";
3+
import TrackJS from "../../trackjs";
34
import ErrorBoundary from "../../components/ErrorBoundary";
45
import ConfigScreen from "../ConfigScreen";
56
import CustomField from "../CustomField";
67
import "./venus.css";
78
import "./styles.scss";
89

910
/** HomeRedirectHandler - component to nandle redirect based on the window location pathname,
10-
as react Router does not identifies pathname if the app is rendered in an iframe.
11+
as react Router does not identifies pathname if the app is rendered in an iframe.
1112
*/
1213
const HomeRedirectHandler = function () {
1314
if (window?.location?.pathname !== "/") {
@@ -16,6 +17,9 @@ const HomeRedirectHandler = function () {
1617
return null;
1718
};
1819

20+
// Track.js installation
21+
TrackJS.installation();
22+
1923
/* App - The main app component that should be rendered */
2024
const App: React.FC = function () {
2125
return (
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import { render, screen, cleanup, fireEvent } from "@testing-library/react";
3+
import ConfigPage from "./index";
4+
5+
const inputLabel = "Data format In Entry";
6+
7+
const UIElementsIDs = [
8+
"cs-form",
9+
"cs-field",
10+
"cs-field-label",
11+
"cs-tooltip",
12+
"cs-radio-one",
13+
"cs-radio-two",
14+
"cs-instruction-text",
15+
];
16+
17+
beforeEach(async () => {
18+
render(<ConfigPage />);
19+
});
20+
jest.spyOn(React, "useEffect").mockImplementation();
21+
22+
afterEach(cleanup);
23+
24+
describe(`UI Elements of Custom Field Screen`, () => {
25+
UIElementsIDs.forEach((id: string) => {
26+
test(`Rendered ${id} element`, async () => {
27+
expect(screen.getByTestId(`${id}`)).toBeInTheDocument();
28+
});
29+
});
30+
31+
test(`Text Label`, async () => {
32+
expect(screen.getByText(inputLabel)).toBeInTheDocument();
33+
});
34+
35+
test(`FireEvent Functionality`, async () => {
36+
const input = screen
37+
.getByTestId(`cs-radio-one`)
38+
.querySelector("input") as HTMLInputElement;
39+
fireEvent.change(input, { target: { value: "false" } });
40+
expect(input.value).toBe("false");
41+
});
42+
});

ui/src/containers/ConfigScreen/index.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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";
1415
import { TypeAppSdkConfigState } from "../../common/types";
1516

1617
/* Import node module CSS */
@@ -39,6 +40,9 @@ const ConfigScreen: React.FC = function () {
3940
useEffect(() => {
4041
ContentstackAppSdk.init()
4142
.then(async (appSdk) => {
43+
//Adding Track.js metadata
44+
TrackJS.addMetadata(appSdk);
45+
4246
const sdkConfigData = appSdk?.location?.AppConfigWidget?.installation;
4347
if (sdkConfigData) {
4448
const installationDataFromSDK =
@@ -104,16 +108,16 @@ const ConfigScreen: React.FC = function () {
104108
return (
105109
<div className="layout-container">
106110
<div className="page-wrapper">
107-
<form data-test-id="cs-form" className="config-wrapper">
111+
<form data-testid="cs-form" className="config-wrapper">
108112
<div className="Form__item">
109113
<div
110114
className="Field Field--full json-field"
111-
data-test-id="cs-field"
115+
data-testid="cs-field"
112116
>
113117
<label
114118
className="FieldLabel"
115119
htmlFor="isStringified"
116-
data-test-id="cs-field-label"
120+
data-testid="cs-field-label"
117121
>
118122
{localeTexts.configFields.entrySaveRadioButton.label}
119123
<span className="FieldLabel__required-text">
@@ -123,12 +127,12 @@ const ConfigScreen: React.FC = function () {
123127
<div
124128
className="tippy-wrapper"
125129
id="help-text"
126-
data-test-id="cs-tooltip"
130+
data-testid="cs-tooltip"
127131
>
128132
<VenusHelp />
129133
</div>
130134
<div className="Radio-wrapper">
131-
<label data-test-id="cs-radio" className="Radio label-text">
135+
<label data-testid="cs-radio-one" className="Radio label-text">
132136
<input
133137
id="jsonObject"
134138
type="radio"
@@ -143,7 +147,7 @@ const ConfigScreen: React.FC = function () {
143147
{localeTexts.configFields.entrySaveRadioButton.jsonObject}
144148
</span>
145149
</label>
146-
<label data-test-id="cs-radio" className="Radio label-text">
150+
<label data-testid="cs-radio-two" className="Radio label-text">
147151
<input
148152
id="stringified"
149153
type="radio"
@@ -162,7 +166,7 @@ const ConfigScreen: React.FC = function () {
162166
</span>
163167
</label>
164168
</div>
165-
<p className="InstructionText" data-test-id="cs-instruction-text">
169+
<p className="InstructionText" data-testid="cs-instruction-text">
166170
{localeTexts.configFields.entrySaveRadioButton.instruction}
167171
</p>
168172
</div>

ui/src/containers/CustomField/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ 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";
56
import { TypeSDKData } from "../../common/types";
67
import "./styles.scss";
78
import JSONEditor from "../../components/jsoneditor";
@@ -29,6 +30,9 @@ const CustomField: React.FC = function () {
2930
useEffect(() => {
3031
ContentstackAppSdk.init()
3132
.then(async (appSdk) => {
33+
// Adding Track.js metadata
34+
TrackJS.addMetadata(appSdk);
35+
3236
const config = await appSdk?.getConfig();
3337
setState({
3438
config,

ui/src/trackjs/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* eslint-disable no-underscore-dangle */
2+
import { TrackJS } from "trackjs";
3+
4+
// To get started with Track.js - add .env variables and change the app's name here.
5+
const installation = () => {
6+
TrackJS.install({
7+
token: `${process.env.REACT_APP_TRACKER_TOKEN}`,
8+
application: process.env.REACT_APP_TRACKER_ENV,
9+
console: { display: true },
10+
});
11+
12+
TrackJS.addMetadata("application_type", "marketplace");
13+
TrackJS.addMetadata("application_name", "JSON-Editor App");
14+
};
15+
16+
// Adding bulk metadata to the Track.js here
17+
const addMetadata = (appSdk: any = {}) => {
18+
const { api_key: apiKey, org_uid: orgUid, name } = appSdk?.stack?._data || {};
19+
const { uid: userUid } = appSdk?.currentUser || {};
20+
const metaData = Object.entries({ apiKey, name, orgUid, userUid });
21+
metaData?.forEach(([key, value]) => {
22+
TrackJS.addMetadata(key, value);
23+
});
24+
};
25+
26+
// To log the error manuall.
27+
const trackError = (error: any) => {
28+
TrackJS.track(error);
29+
};
30+
31+
export default {
32+
installation,
33+
addMetadata,
34+
trackError,
35+
};

0 commit comments

Comments
 (0)