Skip to content

Commit 5ffa9e0

Browse files
authored
Merge pull request #391 from contentstack/feature/test-migration
SNYK fixes
2 parents e8a8f35 + 17a79b3 commit 5ffa9e0

File tree

5 files changed

+54
-182
lines changed

5 files changed

+54
-182
lines changed

ui/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@contentstack/json-rte-serializer": "^2.0.5",
7-
"@contentstack/venus-components": "^2.2.4",
8-
"@reduxjs/toolkit": "^2.2.5",
6+
"@contentstack/json-rte-serializer": "^2.0.12",
7+
"@contentstack/venus-components": "^2.2.5",
8+
"@reduxjs/toolkit": "^2.4.0",
99
"@testing-library/jest-dom": "^5.17.0",
1010
"@testing-library/react": "^13.4.0",
1111
"@testing-library/user-event": "^13.5.0",
@@ -24,7 +24,7 @@
2424
"react-redux": "^9.1.2",
2525
"react-router": "^6.17.0",
2626
"react-router-dom": "^6.16.0",
27-
"react-scripts": "5.0.1",
27+
"react-scripts": "^5.0.1",
2828
"redux-persist": "^6.0.0",
2929
"sass": "^1.68.0",
3030
"socket.io": "^4.7.5",
@@ -50,7 +50,7 @@
5050
"eslint": "^8.51.0",
5151
"eslint-plugin-react": "^7.33.2",
5252
"eslint-plugin-react-hooks": "^4.6.0",
53-
"prettier": "^2.7.1"
53+
"prettier": "^3.3.3"
5454
},
5555
"eslintConfig": {
5656
"extends": [
@@ -69,5 +69,8 @@
6969
"last 1 firefox version",
7070
"last 1 safari version"
7171
]
72+
},
73+
"overrides": {
74+
"http-proxy-middleware": "latest"
7275
}
7376
}

ui/src/components/AdvancePropertise/index.tsx

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const AdvancePropertise = (props: SchemaProps) => {
6565
// State for content types
6666
const [contentTypes, setContentTypes] = useState<ContentType[]>([]);
6767
const [ctValue, setCTValue] = useState<ContentTypeOption[] | null>(embedObjects);
68-
const [embedObjectslabels, setEmbedObjectsLabels] = useState<string[]>(props?.value?.embedObjects);
68+
const [embedObjectsLabels, setEmbedObjectsLabels] = useState<string[]>(props?.value?.embedObjects);
6969
const [showOptions, setShowOptions] = useState<Record<number, boolean>>({});
7070
const [showIcon, setShowIcon] = useState<number>();
7171
const filterRef = useRef<HTMLDivElement | null>(null);
@@ -132,7 +132,7 @@ const AdvancePropertise = (props: SchemaProps) => {
132132
unique: false,
133133
nonLocalizable: currentToggleStates?.nonLocalizable,
134134
embedObject: currentToggleStates?.embedObject,
135-
embedObjects: embedObjectslabels,
135+
embedObjects: embedObjectsLabels,
136136
minRange: currentToggleStates?.minRange,
137137
maxRange: currentToggleStates?.maxRange,
138138
minSize: currentToggleStates?.minSize,
@@ -165,13 +165,13 @@ const AdvancePropertise = (props: SchemaProps) => {
165165
{
166166
...props?.value,
167167
[field]: value,
168-
validationRegex: currentToggleStates?.validationRegex || '',
168+
validationRegex: currentToggleStates?.validationRegex ?? '',
169169
mandatory: currentToggleStates?.mandatory,
170170
multiple: currentToggleStates?.multiple,
171171
unique: false,
172172
nonLocalizable: currentToggleStates?.nonLocalizable,
173173
embedObject: currentToggleStates?.embedObject,
174-
embedObjects : embedObjectslabels,
174+
embedObjects : embedObjectsLabels,
175175
default_value: currentToggleStates?.default_value,
176176
minChars: currentToggleStates?.minChars,
177177
maxChars:currentToggleStates?.maxChars,
@@ -201,13 +201,13 @@ const AdvancePropertise = (props: SchemaProps) => {
201201
props?.rowId,
202202
{
203203
[field]: value,
204-
validationRegex: currentToggleStates?.validationRegex || '',
204+
validationRegex: currentToggleStates?.validationRegex ?? '',
205205
mandatory: currentToggleStates?.mandatory,
206206
multiple: currentToggleStates?.multiple,
207207
unique: false,
208208
nonLocalizable: currentToggleStates?.nonLocalizable,
209209
embedObject: currentToggleStates?.embedObject,
210-
embedObjects : embedObjectslabels
210+
embedObjects : embedObjectsLabels
211211
},
212212
true
213213
);
@@ -240,13 +240,13 @@ const AdvancePropertise = (props: SchemaProps) => {
240240
props?.rowId,
241241
{
242242
['default_value']: option?.key,
243-
validationRegex: currentToggleStates?.validationRegex || '',
243+
validationRegex: currentToggleStates?.validationRegex ?? '',
244244
mandatory: currentToggleStates?.mandatory,
245245
multiple: currentToggleStates?.multiple,
246246
unique: false,
247247
nonLocalizable: currentToggleStates?.nonLocalizable,
248248
embedObject: currentToggleStates?.embedObject,
249-
embedObjects : embedObjectslabels,
249+
embedObjects : embedObjectsLabels,
250250
options:options
251251
},
252252
true
@@ -271,13 +271,13 @@ const AdvancePropertise = (props: SchemaProps) => {
271271
props?.rowId,
272272
{
273273
['default_value']: '',
274-
validationRegex: currentToggleStates?.validationRegex || '',
274+
validationRegex: currentToggleStates?.validationRegex ?? '',
275275
mandatory: currentToggleStates?.mandatory,
276276
multiple: currentToggleStates?.multiple,
277277
unique: false,
278278
nonLocalizable: currentToggleStates?.nonLocalizable,
279279
embedObject: currentToggleStates?.embedObject,
280-
embedObjects : embedObjectslabels,
280+
embedObjects : embedObjectsLabels,
281281
options: options
282282
},
283283
true
@@ -294,12 +294,12 @@ const AdvancePropertise = (props: SchemaProps) => {
294294
};
295295

296296
const handleDragOver = (e:React.DragEvent<HTMLDivElement>, index:number) => {
297+
console.log("inside function");
298+
297299
e.preventDefault();
298300
document.querySelectorAll('.element-wrapper').forEach((el, i) => {
299301
if (i === index) {
300302
el.classList.remove('dragging');
301-
} else {
302-
el.classList.remove('dragging');
303303
}
304304
});
305305
};
@@ -350,25 +350,28 @@ const AdvancePropertise = (props: SchemaProps) => {
350350
<span className='read-only-text'>(read only)</span>
351351
<div className='dropdown-choices-wrapper'>
352352
{options?.map((option: optionsType,index)=>(
353-
<>
354-
<div className='element-wrapper' key={index} draggable
355-
onDragStart={() => handleDragStart(index)}
356-
onDragOver={(e)=> handleDragOver(e,index)}
357-
onDrop={() => handleDrop(index)}>
358-
<div
359-
360-
className='term-drag-icon'>
361-
<Icon icon="ActionBar" size='medium' version='v2' />
362-
</div>
363-
<TextInput version={"v2"} placeholder='Enter value here'
364-
suffixVisible={true}
365-
disabled={true}
366-
value={option?.key}
367-
suffix={
368-
<>
369-
{index === showIcon && <Icon icon={'CheckSquareOffset'} version='v2' size='medium'/>}
370-
371-
</>}></TextInput>
353+
354+
<div
355+
className='element-wrapper'
356+
key={`${index?.toString()}`}
357+
draggable
358+
onDragStart={() => handleDragStart(index)}
359+
onDragOver={(e)=> handleDragOver(e,index)}
360+
onDrop={() => handleDrop(index)}
361+
>
362+
<div className='term-drag-icon'>
363+
<Icon icon="ActionBar" size='medium' version='v2' />
364+
</div>
365+
<TextInput
366+
version={"v2"}
367+
placeholder='Enter value here'
368+
suffixVisible={true}
369+
disabled={true}
370+
value={option?.key}
371+
suffix={index === showIcon && <Icon icon={'CheckSquareOffset'} version='v2' size='medium'/>}
372+
>
373+
374+
</TextInput>
372375

373376
<Button buttonType="light" version={"v2"} onlyIcon={true} canCloseOnClickOutside={true}
374377
size={'small'} icon={'v2-DotsThreeLargeVertical'}
@@ -395,7 +398,7 @@ const AdvancePropertise = (props: SchemaProps) => {
395398

396399
</div>
397400

398-
</>))}
401+
))}
399402

400403

401404
</div>
@@ -544,7 +547,7 @@ const AdvancePropertise = (props: SchemaProps) => {
544547
props?.updateFieldSettings(
545548
props?.rowId,
546549
{
547-
validationRegex : toggleStates?.validationRegex || '',
550+
validationRegex : toggleStates?.validationRegex ?? '',
548551
embedObjects: embedObject
549552
},
550553
true,

ui/src/components/DestinationStack/index.tsx

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -6,156 +6,45 @@ import { CircularLoader } from '@contentstack/venus-components';
66
import { CS_ENTRIES } from '../../utilities/constants';
77
import {
88
DEFAULT_DESTINATION_STACK_DATA,
9-
IDestinationStack,
109
IDestinationStackComponent,
11-
IDropDown
1210
} from '../../context/app/app.interface';
1311
import './DestinationStack.scss';
14-
import { isEmptyString, validateArray } from '../../utilities/functions';
15-
import { getAllStacksInOrg } from '../../services/api/stacks.service';
16-
import { MigrationResponse, StackResponse } from '../../services/api/service.interface';
12+
import { MigrationResponse } from '../../services/api/service.interface';
1713
import { getCMSDataFromFile } from '../../cmsData/cmsSelector';
1814
import { RootState } from '../../store';
1915
import { updateMigrationData } from '../../store/slice/migrationDataSlice';
2016
import { AutoVerticalStepperRef } from '../LegacyCms';
2117

2218
type DestinationStackComponentProps = {
23-
destination_stack: string;
24-
org_id: string;
2519
isCompleted: boolean;
2620
projectData: MigrationResponse;
27-
handleStepChange: (currentStep: number) => void;
2821
handleOnAllStepsComplete:(flag : boolean)=>void;
2922
};
3023

3124
const DestinationStackComponent = ({
32-
destination_stack,
33-
org_id,
3425
projectData,
3526
isCompleted,
3627
// handleStepChange,
3728
handleOnAllStepsComplete,
3829
}: DestinationStackComponentProps) => {
3930
/** ALL HOOKS HERE */
4031

41-
// const [isCompleted, setIsCompleted] = useState<boolean>(false);
4232
const [isMigrationLocked, setIsMigrationLocked] = useState<boolean>(false);
4333
const [stepperKey] = useState<string>('destination-Vertical-stepper');
44-
const [internalActiveStepIndex, setInternalActiveStepIndex] = useState<number>(-1);
34+
const [internalActiveStepIndex] = useState<number>(-1);
4535

4636
const autoVerticalStepperComponent = useRef<AutoVerticalStepperRef>(null);
4737

4838
/** ALL CONTEXT HERE */
4939
const migrationData = useSelector((state:RootState)=>state?.migration?.migrationData);
5040
const newMigrationData = useSelector((state:RootState)=>state?.migration?.newMigrationData);
51-
const selectedOrganisation = useSelector((state:RootState)=>state?.authentication?.selectedOrganisation);
52-
const organisationsList = useSelector((state:RootState)=>state?.authentication?.organisationsList);
5341
const dispatch = useDispatch();
5442
const [isLoading, setIsLoading] = useState<boolean>(newMigrationData?.isprojectMapped);
5543

56-
// const { projectId = '' } = useParams();
57-
58-
// const navigate = useNavigate();
59-
6044
const handleAllStepsComplete = (flag = false) => {
6145
handleOnAllStepsComplete(flag);
6246
};
6347

64-
// const handleOnClick = async (event: MouseEvent) => {
65-
// event?.preventDefault();
66-
// //Update Data in backend
67-
// await updateDestinationStack(selectedOrganisation?.value, projectId, {
68-
// stack_api_key: newMigrationData?.destination_stack?.selectedStack?.value
69-
// });
70-
// handleStepChange(2);
71-
// const res = await updateCurrentStepData(selectedOrganisation?.value, projectId);
72-
// if (res) {
73-
// const url = `/projects/${projectId}/migration/steps/3`;
74-
// navigate(url, { replace: true });
75-
// }
76-
// };
77-
78-
const updateDestinationStackData = async () => {
79-
const selectedOrganisationData = validateArray(organisationsList)
80-
? organisationsList?.find((org: IDropDown) => org?.value === org_id)
81-
: selectedOrganisation;
82-
83-
let selectedStackData: IDropDown = {
84-
value: destination_stack,
85-
label: '',
86-
master_locale: '',
87-
locales: [],
88-
created_at: ''
89-
};
90-
91-
//If stack is already selected and exist in backend, then fetch all stack list and filter selected stack.
92-
if (!isEmptyString(destination_stack)) {
93-
try {
94-
const stackData: any = await getAllStacksInOrg(
95-
selectedOrganisationData?.value || selectedOrganisation?.value,''
96-
);
97-
const stackArray = validateArray(stackData?.data?.stacks)
98-
? stackData?.data?.stacks?.map((stack: StackResponse) => ({
99-
label: stack?.name,
100-
value: stack?.api_key,
101-
uid: stack?.api_key,
102-
master_locale: stack?.master_locale,
103-
locales: stack?.locales,
104-
created_at: stack?.created_at
105-
}))
106-
: [];
107-
108-
stackArray.sort(
109-
(a: IDropDown, b: IDropDown) =>
110-
new Date(b?.created_at)?.getTime() - new Date(a?.created_at)?.getTime()
111-
);
112-
const stack =
113-
validateArray(stackData?.data?.stacks) &&
114-
stackData?.data?.stacks?.find(
115-
(stack: StackResponse) => stack?.api_key === destination_stack
116-
);
117-
118-
if (stack) {
119-
selectedStackData = {
120-
label: stack?.name,
121-
value: stack?.api_key,
122-
master_locale: stack?.master_locale,
123-
locales: stack?.locales,
124-
created_at: stack?.created_at
125-
};
126-
}
127-
const newMigData: IDestinationStack = {
128-
...newMigrationData?.destination_stack,
129-
selectedOrg: selectedOrganisationData || selectedOrganisation,
130-
selectedStack: selectedStackData,
131-
stackArray: stackArray
132-
};
133-
134-
} catch (error) {
135-
return error;
136-
137-
}
138-
139-
140-
}
141-
142-
143-
144-
//Make First Step Complete
145-
if (!isEmptyString(selectedOrganisationData?.value)) {
146-
setInternalActiveStepIndex(0);
147-
}
148-
149-
//Complete step if all step are selected.
150-
if (
151-
!isEmptyString(selectedOrganisationData?.value) &&
152-
!isEmptyString(selectedStackData?.value)
153-
) {
154-
setInternalActiveStepIndex(1);
155-
// setIsCompleted(true);
156-
}
157-
};
158-
15948
/********** ALL USEEFFECT HERE *************/
16049
useEffect(() => {
16150
const fetchCMSData = async () => {
@@ -177,8 +66,6 @@ const DestinationStackComponent = ({
17766
all_steps: getDestinationStackSteps(isCompleted, isMigrationLocked, data?.all_steps)
17867
};
17968

180-
//updateDestinationStackData();
181-
18269
dispatch(updateMigrationData({ destinationStackData: destinationStackDataMapped }));
18370

18471
setIsLoading(false);
@@ -190,11 +77,6 @@ const DestinationStackComponent = ({
19077
fetchCMSData();
19178
}, []);
19279

193-
194-
// useEffect(() => {
195-
// updateDestinationStackData();
196-
// }, [selectedOrganisation]);
197-
19880
useEffect(() => {
19981
if (autoVerticalStepperComponent?.current) {
20082
if (internalActiveStepIndex > -1) {

0 commit comments

Comments
 (0)