Skip to content

Commit 27078fb

Browse files
committed
comment-1: null checks added
1 parent 47bc0ad commit 27078fb

File tree

4 files changed

+114
-109
lines changed

4 files changed

+114
-109
lines changed

api/src/services/migration.service.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -634,22 +634,26 @@ const startMigration = async (req: Request): Promise<any> => {
634634
};
635635

636636
const getLogs = async (req: Request): Promise<any> => {
637-
const projectId = path.basename(req?.params?.projectId);
638-
const stackId = path.basename(req?.params?.stackId);
639-
const limit = parseInt(req?.params?.limit);
640-
const startIndex = parseInt(req?.params?.startIndex);
637+
const projectId = req?.params?.projectId ? path.basename(req.params.projectId) : '';
638+
const stackId = req?.params?.stackId ? path.basename(req.params.stackId) : '';
639+
const limit = req?.params?.limit ? parseInt(req.params.limit) : 10;
640+
const startIndex = req?.params?.startIndex ? parseInt(req.params.startIndex) : 0;
641641
const stopIndex = startIndex + limit;
642-
const searchText = req?.params?.searchText;
643-
const filter = req?.params?.filter;
642+
const searchText = req?.params?.searchText ?? null;
643+
const filter = req?.params?.filter ?? 'all';
644644

645645
const srcFunc = "getLogs";
646646

647-
if (projectId.includes("..") || stackId.includes("..")) {
647+
if (!projectId || !stackId || projectId.includes("..") || stackId.includes("..")) {
648648
throw new BadRequestError("Invalid projectId or stackId");
649649
}
650650

651651
try {
652-
const mainPath = process.cwd().split("migration-v2")[0];
652+
const mainPath = process.cwd()?.split("migration-v2")?.[0];
653+
if (!mainPath) {
654+
throw new BadRequestError("Invalid application path");
655+
}
656+
653657
const logsDir = path.join(mainPath, "migration-v2", "api", "logs");
654658
const loggerPath = path.join(logsDir, projectId, `${stackId}.log`);
655659
const absolutePath = path.resolve(loggerPath);
@@ -661,48 +665,46 @@ const getLogs = async (req: Request): Promise<any> => {
661665
if (fs.existsSync(absolutePath)) {
662666
const logs = await fs.promises.readFile(absolutePath, "utf8");
663667
let logEntries = logs
664-
.split("\n")
665-
.map((line) => {
668+
?.split("\n")
669+
?.map((line) => {
666670
try {
667-
return JSON.parse(line);
671+
return line ? JSON.parse(line) : null;
668672
} catch (error) {
669673
return null;
670674
}
671675
})
672-
.filter((entry) => entry !== null);
676+
?.filter((entry) => entry !== null);
673677

674-
logEntries = logEntries.slice(1, logEntries.length - 2);
678+
if (!logEntries?.length) {
679+
return { logs: [], total: 0 };
680+
}
675681

676-
if (filter != "all") {
677-
const filters = filter.split("-");
678-
logEntries = logEntries.filter((log) => {
679-
return filters.some((filter) => {
680-
return (
681-
log?.level?.toLowerCase()?.includes(filter?.toLowerCase())
682-
);
682+
logEntries = logEntries?.slice(1, logEntries.length - 2);
683+
684+
if (filter !== "all") {
685+
const filters = filter?.split("-") ?? [];
686+
logEntries = logEntries?.filter((log) => {
687+
return filters?.some((filter) => {
688+
return log?.level?.toLowerCase()?.includes(filter?.toLowerCase() ?? '');
683689
});
684690
});
685-
686691
}
687692

688-
if (searchText != "null") {
689-
logEntries = logEntries.filter((log) => {
693+
if (searchText !== "null") {
694+
logEntries = logEntries?.filter((log) => {
690695
return (
691-
log?.level?.toLowerCase()?.includes(searchText?.toLowerCase()) ||
692-
log?.message?.toLowerCase()?.includes(searchText?.toLowerCase()) ||
693-
log?.methodName
694-
?.toLowerCase()
695-
?.includes(searchText?.toLowerCase()) ||
696-
log?.timestamp?.toLowerCase()?.includes(searchText?.toLowerCase())
696+
log?.level?.toLowerCase()?.includes(searchText?.toLowerCase() ?? '') ||
697+
log?.message?.toLowerCase()?.includes(searchText?.toLowerCase() ?? '') ||
698+
log?.methodName?.toLowerCase()?.includes(searchText?.toLowerCase() ?? '') ||
699+
log?.timestamp?.toLowerCase()?.includes(searchText?.toLowerCase() ?? '')
697700
);
698701
});
699-
700702
}
701703

702-
const paginatedLogs = logEntries.slice(startIndex, stopIndex);
704+
const paginatedLogs = logEntries?.slice(startIndex, stopIndex) ?? [];
703705
return {
704706
logs: paginatedLogs,
705-
total: logEntries.length,
707+
total: logEntries?.length ?? 0,
706708
};
707709
} else {
708710
logger.error(getLogMessage(srcFunc, HTTP_TEXTS.LOGS_NOT_FOUND));

ui/src/components/ExecutionLogs/index.tsx

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
3131
const testStacks = useSelector(
3232
(state: RootState) => state?.migration?.newMigrationData?.testStacks
3333
);
34-
console.info(testStacks.length)
34+
3535
const mainStack = useSelector(
3636
(state: RootState) => state?.migration?.newMigrationData?.stackDetails
3737
);
@@ -54,8 +54,8 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
5454

5555
const [selectedStack, setSelectedStack] = useState<DropdownOption>(
5656
{
57-
label: stackIds[stackIds.length - 1]?.label ?? '' ,
58-
value: stackIds[stackIds.length - 1]?.value ?? ''
57+
label: stackIds[stackIds?.length - 1]?.label ?? '' ,
58+
value: stackIds[stackIds?.length - 1]?.value ?? ''
5959
}
6060
);
6161

@@ -87,14 +87,14 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
8787
try {
8888
let filterValueCopy: FilterOption[] = [...filterOption];
8989

90-
if (!filterValueCopy.length && isChecked) {
91-
filterValueCopy.push(value);
90+
if (!filterValueCopy?.length && isChecked) {
91+
filterValueCopy?.push(value);
9292
} else if (isChecked) {
9393
// Remove the old value and keep updated one in case old value exists
94-
const updatedFilter = filterValueCopy.filter((v) => v.value !== value.value);
94+
const updatedFilter = filterValueCopy?.filter((v) => v?.value !== value?.value);
9595
filterValueCopy = [...updatedFilter, value];
9696
} else if (!isChecked) {
97-
filterValueCopy = filterValueCopy.filter((v) => v.value !== value.value);
97+
filterValueCopy = filterValueCopy?.filter((v) => v?.value !== value?.value);
9898
}
9999

100100
setFilterOption(filterValueCopy);
@@ -106,7 +106,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
106106
// Method to handle Apply
107107
const onApply = () => {
108108
try {
109-
if (!filterOption.length) {
109+
if (!filterOption?.length) {
110110
const newFilter = 'all';
111111
setFilterValue(newFilter);
112112
fetchData({ filter: newFilter });
@@ -116,7 +116,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
116116

117117
const usersQueryArray = filterOption.map((item) => item.value);
118118
const newFilter =
119-
usersQueryArray.length > 1 ? usersQueryArray.join('-') : usersQueryArray[0];
119+
usersQueryArray?.length > 1 ? usersQueryArray?.join('-') : usersQueryArray[0];
120120

121121
setFilterValue(newFilter);
122122
fetchData({ filter: newFilter });
@@ -177,8 +177,8 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
177177
Header: 'Timestamp',
178178
disableSortBy: true,
179179
accessor: (data: LogEntry) => {
180-
if (data.timestamp) {
181-
const date = new Date(data.timestamp);
180+
if (data?.timestamp) {
181+
const date = new Date(data?.timestamp);
182182
const options: Intl.DateTimeFormatOptions = {
183183
month: 'short',
184184
day: '2-digit',
@@ -198,7 +198,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
198198
Header: 'Level',
199199
id: 'level',
200200
disableSortBy: true,
201-
accessor: (data: LogEntry) => <div>{data.level}</div>,
201+
accessor: (data: LogEntry) => <div>{data?.level}</div>,
202202
width: 150,
203203
filter: ColumnFilter
204204
},
@@ -208,7 +208,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
208208
accessor: (data: LogEntry) => {
209209
return (
210210
<div>
211-
<div>{data.message}</div>
211+
<div>{data?.message}</div>
212212
</div>
213213
);
214214
},
@@ -220,7 +220,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
220220
accessor: (data: LogEntry) => {
221221
return (
222222
<div>
223-
<div>{data.methodName}</div>
223+
<div>{data?.methodName}</div>
224224
</div>
225225
);
226226
},
@@ -250,7 +250,7 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
250250
const response = await getMigrationLogs(
251251
selectedOrganisation?.value || '',
252252
projectId,
253-
selectedStack.value,
253+
selectedStack?.value,
254254
skip,
255255
limit,
256256
startIndex,
@@ -264,8 +264,8 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
264264
setData([]);
265265
setTotalCounts(0);
266266
} else {
267-
setData(response.data.logs);
268-
setTotalCounts(response.data.total);
267+
setData(response?.data.logs);
268+
setTotalCounts(response?.data.total);
269269
}
270270
} catch (error) {
271271
console.error('Unexpected error while fetching logs:', error);
@@ -279,58 +279,61 @@ const ExecutionLogs = ({ projectId }: { projectId: string }) => {
279279
return (
280280
<div>
281281
<InfiniteScrollTable
282-
tableHeight={590}
283-
itemSize={60}
284-
columns={columns}
285-
data={data}
286-
uniqueKey={'timestamp'}
287-
fetchTableData={fetchData}
288-
totalCounts={totalCounts}
289-
loading={loading}
290-
rowPerPageOptions={[10, 30, 50, 100]}
291-
minBatchSizeToFetch={30}
292-
v2Features={{
293-
pagination: true,
294-
isNewEmptyState : true
295-
}}
296-
isResizable={true}
297-
isRowSelect={false}
298-
columnSelector={false}
299-
canSearch={true}
300-
searchPlaceholder={'Search Execution Logs'}
301-
searchValue={searchText}
302-
onSearchChangeEvent={(value: string) => setSearchText(value)}
303-
withExportCta={{
304-
component: (
305-
<Select
306-
className='dropdown-wrapper'
307-
width="250px"
308-
version="v2"
309-
value={testStacks.length ? selectedStack : ''}
310-
options={stackIds}
311-
placeholder='Select a stack'
312-
onChange={(s: DropdownOption) => {
313-
setSelectedStack({label: s.label, value: s.value})
314-
setSearchText('');
315-
}}
316-
/>
317-
),
318-
showExportCta: true
319-
}}
320-
customEmptyState={
321-
<EmptyState
322-
forPage="list"
323-
heading={searchText === '' ? 'No Logs' : 'No matching results found!'}
324-
description={
325-
searchText === ''
326-
? 'Try Executing the Migration.'
327-
: 'Try changing the search query to find what you are looking for.'
328-
}
329-
moduleIcon={searchText === '' ? 'NoDataEmptyState' : 'NoSearchResult'}
330-
type="secondary"
331-
className="custom-empty-state"
332-
/>
282+
tableHeight={590}
283+
itemSize={60}
284+
columns={columns}
285+
data={data ?? []}
286+
uniqueKey={'timestamp'}
287+
fetchTableData={fetchData}
288+
totalCounts={totalCounts ?? 0}
289+
loading={loading}
290+
rowPerPageOptions={[10, 30, 50, 100]}
291+
minBatchSizeToFetch={30}
292+
v2Features={{
293+
pagination: true,
294+
isNewEmptyState: true
295+
}}
296+
isResizable={true}
297+
isRowSelect={false}
298+
columnSelector={false}
299+
canSearch={true}
300+
searchPlaceholder={'Search Execution Logs'}
301+
searchValue={searchText ?? ''}
302+
onSearchChangeEvent={(value: string) => setSearchText(value)}
303+
withExportCta={{
304+
component: (
305+
<Select
306+
className='dropdown-wrapper'
307+
width="250px"
308+
version="v2"
309+
value={testStacks?.length ? selectedStack : ''}
310+
options={stackIds ?? []}
311+
placeholder='Select a stack'
312+
onChange={(s: DropdownOption) => {
313+
setSelectedStack({
314+
label: s?.label ?? '',
315+
value: s?.value ?? ''
316+
});
317+
setSearchText('');
318+
}}
319+
/>
320+
),
321+
showExportCta: true
322+
}}
323+
customEmptyState={
324+
<EmptyState
325+
forPage="list"
326+
heading={searchText === '' ? 'No Logs' : 'No matching results found!'}
327+
description={
328+
searchText === ''
329+
? 'Try Executing the Migration.'
330+
: 'Try changing the search query to find what you are looking for.'
333331
}
332+
moduleIcon={searchText === '' ? 'NoDataEmptyState' : 'NoSearchResult'}
333+
type="secondary"
334+
className="custom-empty-state"
335+
/>
336+
}
334337
/>
335338
</div>
336339
);

ui/src/components/FilterModale/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ const FilterModal = ({
3838
<li key={item.value}>
3939
<div className="tableFilterModalStories__suggestion-item">
4040
<Checkbox
41-
checked={selectedLevels.some((v) => v.value === item.value)}
42-
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
43-
updateValue({ value: item, isChecked: e.target.checked })
44-
}
45-
version="v2"
46-
label={item.label}
47-
className="text-size"
41+
checked={selectedLevels?.some((v) => v?.value === item?.value) || false}
42+
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
43+
updateValue?.({ value: item, isChecked: e?.target?.checked })
44+
}
45+
version="v2"
46+
label={item?.label || ''}
47+
className="text-size"
4848
/>
4949
</div>
5050
</li>

upload-api/src/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default {
22
plan: {
33
dropdown: { optionLimit: 100 }
44
},
5-
cmsType: 'contentful',
5+
cmsType: 'sitecore',
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/Downloads/contentful-export-qkbsabj2eulh-master-2024-04-30T15-17-15.json'
16+
localPath: '/Users/yash.shinde/Documents/Migration/update-script/package 45.zip'
1717
};

0 commit comments

Comments
 (0)