Skip to content

Commit fd5c0e0

Browse files
committed
comment-2: constants added, search func added in search utility
1 parent 27078fb commit fd5c0e0

File tree

9 files changed

+366
-160
lines changed

9 files changed

+366
-160
lines changed

api/src/services/migration.service.ts

Lines changed: 273 additions & 121 deletions
Large diffs are not rendered by default.

api/src/utils/search.util.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LogEntry } from "winston/index.js";
2+
3+
export const matchesSearchText = (log: LogEntry, searchText: string): boolean => {
4+
if (!searchText || searchText === "null") return true;
5+
6+
const loweredSearch = searchText.toLowerCase();
7+
8+
const fieldsToSearch = ["level", "message", "methodName", "timestamp"];
9+
10+
return fieldsToSearch.some((field) =>
11+
log?.[field]?.toString()?.toLowerCase()?.includes(loweredSearch)
12+
);
13+
};

ui/src/cmsData/setting.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
"theme": "secondary",
1313
"title": "Delete Project",
1414
"url": "",
15-
"with_icon": true
15+
"with_icon": true,
16+
"icon": "Delete"
1617
},
1718
"save_project": {
1819
"open_in_new_tab": false,
1920
"theme": "primary",
2021
"title": "Save",
2122
"url": "",
22-
"with_icon": true
23-
}
23+
"with_icon": true,
24+
"icon": "v2-Save"
25+
},
26+
"back_button": "LeftArrow"
2427
},
2528
"execution_logs": {
2629
"title": "Execution Logs"

ui/src/components/Common/Settings/index.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111
Textarea,
1212
PageLayout,
1313
Notification,
14-
cbModal,
15-
ClipBoard
14+
cbModal
1615
} from '@contentstack/venus-components';
1716

1817
// Redux
@@ -24,7 +23,7 @@ import { ModalObj } from '../../../components/Modal/modal.interface';
2423

2524
// Service
2625
import { deleteProject, getProject, updateProject } from '../../../services/api/project.service';
27-
import { CS_ENTRIES } from '../../../utilities/constants';
26+
import { CS_ENTRIES, HTTP_CODES } from '../../../utilities/constants';
2827
import { getCMSDataFromFile } from '../../../cmsData/cmsSelector';
2928

3029
// Component
@@ -81,7 +80,7 @@ const Settings = () => {
8180
params?.projectId ?? ''
8281
);
8382

84-
if (status === 200) {
83+
if (status === HTTP_CODES.OK) {
8584
setProjectName(data?.name);
8685
setProjectDescription(data?.description);
8786
setProjectId(params?.projectId ?? '');
@@ -111,7 +110,7 @@ const Settings = () => {
111110
projectData
112111
);
113112

114-
if (status === 200) {
113+
if (status === HTTP_CODES.OK) {
115114
Notification({
116115
notificationContent: { text: 'Project Updated Successfully' },
117116
notificationProps: {
@@ -136,7 +135,7 @@ const Settings = () => {
136135
//setIsLoading(true);
137136
const response = await deleteProject(selectedOrganisation?.value, params?.projectId ?? '');
138137

139-
if (response?.status === 200) {
138+
if (response?.status === HTTP_CODES.OK) {
140139
//setIsLoading(false);
141140
closeModal();
142141
dispatch(updateNewMigrationData(DEFAULT_NEW_MIGRATION));
@@ -194,7 +193,7 @@ const Settings = () => {
194193
<div className="flex-center">
195194
<div className="flex-v-center Button__mt-regular Button__visible">
196195
<Icon
197-
icon="Delete"
196+
icon={cmsData?.project?.delete_project?.icon ?? ''}
198197
version="v2"
199198
data={cmsData?.project?.delete_project?.title}></Icon>
200199
</div>
@@ -250,7 +249,7 @@ const Settings = () => {
250249
buttonType="primary"
251250
aria-label="save for saving update"
252251
version="v2"
253-
icon={'v2-Save'}
252+
icon={cmsData?.project?.save_project?.icon}
254253
autoClose={5000}
255254
label={'Success'}
256255
onClick={handleUpdateProject}>
@@ -262,9 +261,7 @@ const Settings = () => {
262261
</div>
263262
)}
264263
{active === cmsData?.execution_logs?.title && (
265-
<div>
266264
<ExecutionLog projectId={projectId} />
267-
</div>
268265
)}
269266
</div>
270267
)
@@ -281,7 +278,7 @@ const Settings = () => {
281278
<div>
282279
<Icon
283280
version="v2"
284-
icon={'LeftArrow'}
281+
icon={cmsData?.project?.back_button ?? ''}
285282
size="medium"
286283
onClick={() => {
287284
handleBack();

ui/src/components/Common/Settings/setting.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface IProject {
1010
save_project: CTA;
1111
email: string;
1212
description_placeholder: string;
13+
back_button: string;
1314
}
1415
/**
1516
* Represents a Call to Action (CTA) object.
@@ -20,6 +21,7 @@ interface CTA {
2021
title: string;
2122
url: string;
2223
with_icon: boolean;
24+
icon: string
2325
}
2426
interface IExecutionLogs {
2527
title: string;

ui/src/components/ExecutionLogs/index.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import './index.scss';
1212

1313
import FilterModal from '../FilterModale';
1414
import { getMigrationLogs } from '../../services/api/migration.service';
15+
import { EXECUTION_LOGS_UI_TEXT } from '../../utilities/constants';
1516

1617
const ExecutionLogs = ({ projectId }: { projectId: string }) => {
1718
const [data, setData] = useState<LogEntry[]>([]);
@@ -40,7 +41,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
4041
state?.migration?.newMigrationData?.migration_execution?.migrationCompleted
4142
);
4243

43-
const stackIds = testStacks?.map((stack: StackIds) => ({
44+
const stackIds = testStacks?.map?.((stack: StackIds) => ({
4445
label: stack?.stackName,
4546
value: stack?.stackUid
4647
}));
@@ -54,8 +55,8 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
5455

5556
const [selectedStack, setSelectedStack] = useState<DropdownOption>(
5657
{
57-
label: stackIds[stackIds?.length - 1]?.label ?? '' ,
58-
value: stackIds[stackIds?.length - 1]?.value ?? ''
58+
label: stackIds?.[stackIds?.length - 1]?.label ?? '' ,
59+
value: stackIds?.[stackIds?.length - 1]?.value ?? ''
5960
}
6061
);
6162

@@ -114,10 +115,8 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
114115
return;
115116
}
116117

117-
const usersQueryArray = filterOption.map((item) => item.value);
118-
const newFilter =
119-
usersQueryArray?.length > 1 ? usersQueryArray?.join('-') : usersQueryArray[0];
120-
118+
const usersQueryArray = filterOption?.map((item) => item?.value);
119+
const newFilter = usersQueryArray?.length > 1 ? usersQueryArray?.join('-') : usersQueryArray?.[0];
121120
setFilterValue(newFilter);
122121
fetchData({ filter: newFilter });
123122
setIsFilterApplied(true);
@@ -136,8 +135,8 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
136135

137136
const iconProps = {
138137
className: isFilterApplied
139-
? 'filterWithAppliedIcon Icon--v2 Icon--medium'
140-
: 'defaultFilterIcon Icon--v2 Icon--medium',
138+
? EXECUTION_LOGS_UI_TEXT.FILTER_ICON.FILTER_ON
139+
: EXECUTION_LOGS_UI_TEXT.FILTER_ICON.FILTER_OFF,
141140
withTooltip: true,
142141
tooltipContent: 'Filter',
143142
tooltipPosition: 'left'
@@ -187,7 +186,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
187186
minute: '2-digit',
188187
hour12: true
189188
};
190-
const formatted = new Intl.DateTimeFormat('en-US', options).format(date);
189+
const formatted = new Intl.DateTimeFormat('en-US', options)?.format(date);
191190
return <div>{formatted}</div>;
192191
}
193192
return <div>No Data Available</div>;
@@ -264,8 +263,8 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
264263
setData([]);
265264
setTotalCounts(0);
266265
} else {
267-
setData(response?.data.logs);
268-
setTotalCounts(response?.data.total);
266+
setData(response?.data?.logs);
267+
setTotalCounts(response?.data?.total);
269268
}
270269
} catch (error) {
271270
console.error('Unexpected error while fetching logs:', error);
@@ -297,7 +296,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
297296
isRowSelect={false}
298297
columnSelector={false}
299298
canSearch={true}
300-
searchPlaceholder={'Search Execution Logs'}
299+
searchPlaceholder={EXECUTION_LOGS_UI_TEXT.SEARCH_PLACEHOLDER}
301300
searchValue={searchText ?? ''}
302301
onSearchChangeEvent={(value: string) => setSearchText(value)}
303302
withExportCta={{
@@ -308,7 +307,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
308307
version="v2"
309308
value={testStacks?.length ? selectedStack : ''}
310309
options={stackIds ?? []}
311-
placeholder='Select a stack'
310+
placeholder={EXECUTION_LOGS_UI_TEXT.SELECT_PLACEHOLDER}
312311
onChange={(s: DropdownOption) => {
313312
setSelectedStack({
314313
label: s?.label ?? '',
@@ -323,13 +322,13 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
323322
customEmptyState={
324323
<EmptyState
325324
forPage="list"
326-
heading={searchText === '' ? 'No Logs' : 'No matching results found!'}
325+
heading={searchText === '' ? EXECUTION_LOGS_UI_TEXT.EMPTY_STATE_HEADING.NO_LOGS : EXECUTION_LOGS_UI_TEXT.EMPTY_STATE_HEADING.NO_MATCH}
327326
description={
328327
searchText === ''
329-
? 'Try Executing the Migration.'
330-
: 'Try changing the search query to find what you are looking for.'
328+
? EXECUTION_LOGS_UI_TEXT.EMPTY_STATE_DESCRIPTION.NO_LOGS
329+
: EXECUTION_LOGS_UI_TEXT.EMPTY_STATE_DESCRIPTION.NO_RESULT
331330
}
332-
moduleIcon={searchText === '' ? 'NoDataEmptyState' : 'NoSearchResult'}
331+
moduleIcon={searchText === '' ? EXECUTION_LOGS_UI_TEXT.EMPTY_STATE_ICON.NO_LOGS : EXECUTION_LOGS_UI_TEXT.EMPTY_STATE_ICON.NO_MATCH}
333332
type="secondary"
334333
className="custom-empty-state"
335334
/>

ui/src/services/api/migration.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ObjectType } from '../../utilities/constants.interface';
2-
import { API_VERSION } from '../../utilities/constants';
2+
import { API_VERSION, EXECUTION_LOGS_ERROR_TEXT } from '../../utilities/constants';
33
import { getDataFromLocalStorage } from '../../utilities/functions';
44
import { getCall, postCall, putCall, patchCall } from './service';
55

@@ -349,9 +349,10 @@ export const getMigrationLogs = async (orgId: string, projectId: string, stackId
349349
);
350350
} catch (error) {
351351
if (error instanceof Error) {
352-
throw new Error(`Error in userSession: ${error.message}`);
352+
throw new Error(`${EXECUTION_LOGS_ERROR_TEXT.ERROR}: ${error.message}`);
353353
} else {
354-
throw new Error('Unknown error in userSession');
354+
throw new Error('Unknown ${EXECUTION_LOGS_ERROR_TEXT.ERROR}');
355355
}
356356
}
357-
}
357+
}
358+

ui/src/utilities/constants.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,42 @@ export const VALIDATION_DOCUMENTATION_URL: { [key: string]: string } = {
118118
wordpress: '',
119119
drupal: ''
120120
};
121+
122+
export const HTTP_CODES = {
123+
OK: 200,
124+
FORBIDDEN: 403,
125+
BAD_REQUEST: 400,
126+
NOT_FOUND: 404,
127+
UNAUTHORIZED: 401,
128+
TOO_MANY_REQS: 429,
129+
SOMETHING_WRONG: 501,
130+
MOVED_PERMANENTLY: 301,
131+
SUPPORT_DOC: 294,
132+
SERVER_ERROR: 500,
133+
UNPROCESSABLE_CONTENT: 422,
134+
};
135+
136+
export const EXECUTION_LOGS_UI_TEXT = {
137+
SEARCH_PLACEHOLDER: 'Search Execution Logs',
138+
SELECT_PLACEHOLDER: 'Select a stack',
139+
EMPTY_STATE_DESCRIPTION: {
140+
NO_RESULT: 'Try Changing the Search Query to find what you are looking for',
141+
NO_LOGS: 'Try executing Test Migration'
142+
},
143+
EMPTY_STATE_HEADING: {
144+
NO_LOGS: 'No Logs Found',
145+
NO_MATCH: 'No Matching Result Found'
146+
},
147+
EMPTY_STATE_ICON: {
148+
NO_LOGS:'NoDataEmptyState',
149+
NO_MATCH: 'NoSearchResult'
150+
},
151+
FILTER_ICON: {
152+
FILTER_ON: 'filterWithAppliedIcon Icon--v2 Icon--medium',
153+
FILTER_OFF: 'defaultFilterIcon Icon--v2 Icon--medium'
154+
}
155+
}
156+
157+
export const EXECUTION_LOGS_ERROR_TEXT = {
158+
ERROR: 'Error in Getting Migration Logs'
159+
}

upload-api/src/config/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default {
22
plan: {
33
dropdown: { optionLimit: 100 }
44
},
5-
cmsType: 'sitecore',
5+
cmsType: 'contentful',
66
isLocalPath: true,
77
awsData: {
88
awsRegion: 'us-east-2',
@@ -13,5 +13,5 @@ export default {
1313
bucketKey: ''
1414
},
1515
// localPath: '/Users/sayali.joshi/Downloads/contentfulDummyEmbedData.json' //package 45.zip'
16-
localPath: '/Users/yash.shinde/Documents/Migration/update-script/package 45.zip'
17-
};
16+
localPath: '/Users/shobhit.upadhyay/Downloads/asic.json'
17+
};

0 commit comments

Comments
 (0)