Skip to content

Commit

Permalink
Merge pull request #1880 from jplag/report-viewer/common-file-path
Browse files Browse the repository at this point in the history
Only show parts of path that differ in report viewer
  • Loading branch information
tsaglam authored Jul 19, 2024
2 parents 38e72cd + 5cc2113 commit 7e51788
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
22 changes: 18 additions & 4 deletions report-viewer/src/components/fileDisplaying/CodePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
<template>
<Interactable class="mx-2 !shadow print:!mx-0 print:!border-0 print:!p-0">
<div @click="collapsed = !collapsed" class="flex px-2 font-bold print:whitespace-pre-wrap">
<span class="flex-1">{{ getFileDisplayName(file) }}</span>
<ToolTipComponent direction="right" v-if="getFileDisplayName(file) != file.fileName">
<template #default
><span>{{ getFileDisplayName(file) }}</span></template
>
<template #tooltip
><p class="whitespace max-w-[22rem] text-sm font-normal">
{{ file.fileName }}
</p></template
>
</ToolTipComponent>
<span v-else>{{ file.fileName }}</span>

<span class="flex-1"></span>

<ToolTipComponent direction="left" class="font-normal">
<template #default
><span class="text-gray-600 dark:text-gray-300"
Expand Down Expand Up @@ -144,9 +157,10 @@ defineExpose({
* @return new path of file
*/
function getFileDisplayName(file: SubmissionFile): string {
const filePathLength = file.fileName.length
const fileDisplayName = file.displayFileName ?? file.fileName
const filePathLength = fileDisplayName.length
return filePathLength > 40
? '...' + file.fileName.substring(filePathLength - 40, filePathLength)
: file.fileName
? '...' + fileDisplayName.substring(filePathLength - 40, filePathLength)
: fileDisplayName
}
</script>
4 changes: 4 additions & 0 deletions report-viewer/src/model/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export interface SubmissionFile extends File {
* Number of tokens in the file that are matched.
*/
matchedTokenCount: number
/**
* The name to be displayed in the report viewer
*/
displayFileName: string
}
31 changes: 28 additions & 3 deletions report-viewer/src/model/factories/ComparisonFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getMatchColorCount } from '@/utils/ColorUtils'
import slash from 'slash'
import { BaseFactory } from './BaseFactory'
import { MetricType } from '../MetricType'
import type { SubmissionFile } from '../File'

/**
* Factory class for creating Comparison objects
Expand Down Expand Up @@ -57,8 +58,8 @@ export class ComparisonFactory extends BaseFactory {
firstSubmissionId,
secondSubmissionId,
this.extractSimilarities(json.similarities as Record<string, number>),
filesOfFirstSubmission,
filesOfSecondSubmission,
this.getFilesWithDisplayNames(filesOfFirstSubmission),
this.getFilesWithDisplayNames(filesOfSecondSubmission),
this.colorMatches(matches),
json.first_similarity as number,
json.second_similarity as number
Expand Down Expand Up @@ -91,7 +92,8 @@ export class ComparisonFactory extends BaseFactory {
submissionId: submissionId,
data: await this.getSubmissionFileContent(submissionId, slash(filePath)),
tokenCount: fileList[filePath].token_count,
matchedTokenCount: 0
matchedTokenCount: 0,
displayFileName: slash(filePath)
})
}
} catch (e) {
Expand Down Expand Up @@ -152,4 +154,27 @@ export class ComparisonFactory extends BaseFactory {
}
return sortedSize
}

private static getFilesWithDisplayNames(files: SubmissionFile[]): SubmissionFile[] {
if (files.length == 1) {
return files
}
let longestPrefix = files[0].fileName
for (let i = 1; i < files.length; i++) {
if (longestPrefix == '') {
break
}

while (!files[i].fileName.startsWith(longestPrefix)) {
longestPrefix = longestPrefix.substring(0, longestPrefix.length - 1)
}
}

return files.map((f) => {
return {
...f,
displayFileName: f.fileName.substring(longestPrefix.length)
}
})
}
}
3 changes: 2 additions & 1 deletion report-viewer/src/model/fileHandling/ZipFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class ZipFileHandler extends FileHandler {
data: data,
// These two properties will be determined at a later time (when loading the submission file index)
tokenCount: NaN,
matchedTokenCount: NaN
matchedTokenCount: NaN,
displayFileName: slash(fullPathFileName)
})
})
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const store = {
filesOfSubmission: (name: string) => {
return [
{
name: `${name}/Structure.java`,
fileName: `${name}/Structure.java`,
value: ''
},
{
name: `${name}/Submission.java`,
fileName: `${name}/Submission.java`,
value: ''
}
]
Expand All @@ -30,7 +30,8 @@ const store = {
return {
fileName: name,
submissionId: id,
matchedTokenCount: 0
matchedTokenCount: 0,
displayName: name
}
}
}
Expand Down

0 comments on commit 7e51788

Please sign in to comment.