Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/2498/remove example maps #3768

Merged
merged 17 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/---bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ THEN
1.

## Specifications
- is released in [online-demo](https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz): yes | no
- is released in [online-demo](https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz&currentFilesAreSampleFiles=true): yes | no
- CodeCharta Version:
- OS:
- Browser:
2 changes: 1 addition & 1 deletion DEV_START_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
CodeCharta consists of two separate parts:

- The [analysis](https://maibornwolff.github.io/codecharta/docs/analysis/) which is a cli-tool that generates a `.cc.json` file.
- The [visualization](https://maibornwolff.github.io/codecharta/docs/visualization/) that consumes said file and visualises it in form of a tree map. The visualization has both a desktop client and a [web version](https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz).
- The [visualization](https://maibornwolff.github.io/codecharta/docs/visualization/) that consumes said file and visualises it in form of a tree map. The visualization has both a desktop client and a [web version](https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz&currentFilesAreSampleFiles=true).

Both parts are in active development, meaning as a developer you can contribute to both. For more on how we communicate and how you can give feedback, check out [feedback](https://maibornwolff.github.io/codecharta/docs/feedback/).

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">
<br>
<a href="https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz"><img src="https://raw.githubusercontent.com/maibornwolff/codecharta/main/logo/codecharta_logo.svg" alt="CodeCharta" width="200"/></a>
<a href="https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz&currentFilesAreSampleFiles=true"><img src="https://raw.githubusercontent.com/maibornwolff/codecharta/main/logo/codecharta_logo.svg" alt="CodeCharta" width="200"/></a>
<br>
CodeCharta
<br>
Expand Down Expand Up @@ -46,7 +46,7 @@ Latest Release: <br>

- [CodeCharta Visualization](https://maibornwolff.github.io/codecharta/docs/visualization/):

- CC visualizes code bases as 3D cities, so that you can understand it - view the [Web Demo](https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz).
- CC visualizes code bases as 3D cities, so that you can understand it - view the [Web Demo](https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz&currentFilesAreSampleFiles=true).
- It uses code metrics from `.cc.json` files.
- The imported files are validated using JSON Schema as defined in [generatedSchema.json](/visualization/app/codeCharta/util/generatedSchema.json).
- You can change the way the file is displayed and save and later load it as a [Custom View](https://maibornwolff.github.io/codecharta/docs/custom-view/).
Expand Down
2 changes: 1 addition & 1 deletion gh-pages/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ social:
links: # An array of links to social media profiles

# Custom site variables, reference them in liquid like this: {{site.web_visualization_link}}
web_visualization_link: https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz
web_visualization_link: https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz&currentFilesAreSampleFiles=true

# Site Footer
footer:
Expand Down
2 changes: 1 addition & 1 deletion gh-pages/_pages/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ header:
overlay_image: /assets/images/CC-Home.png
actions:
- label: "<i class='fas fa-fw fa-link'></i> Explore Web Studio"
url: "https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz"
url: "https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz&currentFilesAreSampleFiles=true"
- label: "<i class='fas fa-fw fa-link'></i> Quick Start"
url: "/docs/quick-start-guide/"
excerpt: >
Expand Down
2 changes: 1 addition & 1 deletion gh-pages/_posts/dev-guide/2020-08-04-make-a-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ The new version depends on what kind of entries are found in the unreleased part
## Post-Work

- Click `Edit` on your latest [release](https://github.com/MaibornWolff/codecharta/releases) and add the release notes from your gh-pages post
- Quick-test our [web demo](https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz) for it's core and new features again
- Quick-test our [web demo](https://maibornwolff.github.io/codecharta/visualization/app/index.html?file=codecharta.cc.json.gz&file=codecharta_analysis.cc.json.gz&currentFilesAreSampleFiles=true) for it's core and new features again
10 changes: 9 additions & 1 deletion visualization/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

## [unreleased] (Added 🚀 | Changed | Removed 🗑 | Fixed 🐞 | Chore 👨‍💻 👩‍💻)

### Added 🚀

- Add experimental feature: show buildings with an area metric value of 0 [#3789](https://github.com/MaibornWolff/codecharta/pull/3789)

### Fixed 🐞

- Fix that default sample files are not removed when a new file is loaded by the user [#2498](https://github.com/MaibornWolff/codecharta/pull/3768)

## [1.129.1] - 2024-10-18

### Fixed 🐞
Expand All @@ -20,14 +28,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
- Add thousands separation for big numbers [#3758](https://github.com/MaibornWolff/codecharta/pull/3758)
- Add popup when comparing files with different complexity metrics [#3773](https://github.com/MaibornWolff/codecharta/pull/3773)
- Add experimental feature: dynamic floor lable height for large maps [#3778](https://github.com/MaibornWolff/codecharta/pull/3778)
- Add experimental feature: show buildings with an area metric value of 0 [#3789](https://github.com/MaibornWolff/codecharta/pull/3789)

### Fixed 🐞

- Remove horizontal scrollbar in the File/ Node Explorer dropdown and styling fixes [#3765](https://github.com/MaibornWolff/codecharta/pull/3765)
- Fix issue when multiple files are selected then the edge metrics in the primary metrics section are not displayed correctly. [#3753](https://github.com/MaibornWolff/codecharta/pull/3753)
- Metric Scenarios (before Metric Templates) are available again [#3762](https://github.com/MaibornWolff/codecharta/pull/3762)
- Legend Panel closes on outside click [#3770](https://github.com/MaibornWolff/codecharta/pull/3770)
- Fix that default sample files are not removed when a new file is loaded by the user [#2498](https://github.com/MaibornWolff/codecharta/pull/3768)

### Changed

Expand Down
4 changes: 2 additions & 2 deletions visualization/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { RenderCodeMapEffect } from "./codeCharta/state/effects/renderCodeMapEff
import { ResetChosenMetricsEffect } from "./codeCharta/state/effects/resetChosenMetrics/resetChosenMetrics.effect"
import { ResetSelectedEdgeMetricWhenItDoesntExistAnymoreEffect } from "./codeCharta/state/effects/resetSelectedEdgeMetricWhenItDoesntExistAnymore/resetSelectedEdgeMetricWhenItDoesntExistAnymore.effect"
import { SaveCcStateEffect } from "./codeCharta/state/effects/saveCcState/saveCcState.effect"
import { SaveMetricsInQueryParametersEffect } from "./codeCharta/state/effects/saveMetricsInQueryParameters/saveMetricsInQueryParameters.effect"
import { UpdateQueryParametersEffect } from "./codeCharta/state/effects/updateQueryParameters/updateQueryParameters.effect"
import { SetLoadingIndicatorEffect } from "./codeCharta/state/effects/setLoadingIndicator/setLoadingIndicator.effect"
import { UnfocusNodesEffect } from "./codeCharta/state/effects/unfocusNodes/unfocusNodes.effect"
import { UpdateEdgePreviewsEffect } from "./codeCharta/state/effects/updateEdgePreviews/updateEdgePreviews.effect"
Expand Down Expand Up @@ -54,7 +54,7 @@ import { IncompatibleMapsDialogModule } from "./codeCharta/ui/filePanel/filePane
UpdateFileSettingsEffect,
SetLoadingIndicatorEffect,
SaveCcStateEffect,
SaveMetricsInQueryParametersEffect,
UpdateQueryParametersEffect,
UpdateMapColorsEffect,
FocusEffects
]),
Expand Down
1 change: 1 addition & 0 deletions visualization/app/codeCharta/codeCharta.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export function stateObjectReviver(_, valueToRevive) {
}

export interface AppStatus {
currentFilesAreSampleFiles: boolean
hoveredNodeId: number | null
selectedBuildingId: number | null
rightClickedNodeData: {
Expand Down
20 changes: 17 additions & 3 deletions visualization/app/codeCharta/services/loadFile/fileParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export function enrichFileStatesAndRecentFilesWithValidationResults(
fileStates: FileState[],
recentFiles: string[],
nameDataPairs: NameDataPair[],
fileValidationResults: FileValidationResult[]
fileValidationResults: FileValidationResult[],
currentFilesAreSampleFilesCallback: () => boolean,
setCurrentFilesAreNotSampleFilesCallback: () => void
) {
for (const nameDataPair of nameDataPairs) {
const fileValidationResult: FileValidationResult = {
Expand All @@ -50,7 +52,7 @@ export function enrichFileStatesAndRecentFilesWithValidationResults(

if (fileValidationResult.errors.length === 0) {
fileValidationResult.warnings.push(...checkWarnings(nameDataPair?.content))
addFile(fileStates, recentFiles, nameDataPair)
addFile(fileStates, recentFiles, nameDataPair, currentFilesAreSampleFilesCallback, setCurrentFilesAreNotSampleFilesCallback)
}

if (fileValidationResult.errors.length > 0 || fileValidationResult.warnings.length > 0) {
Expand All @@ -59,7 +61,19 @@ export function enrichFileStatesAndRecentFilesWithValidationResults(
}
}

function addFile(fileStates: FileState[], recentFiles: string[], file: NameDataPair) {
function addFile(
fileStates: FileState[],
recentFiles: string[],
file: NameDataPair,
currentFilesAreSampleFilesCallback: () => boolean,
setCurrentFilesAreNotSampleFilesCallback: () => void
) {
if (currentFilesAreSampleFilesCallback()) {
fileStates.length = 0
setCurrentFilesAreNotSampleFilesCallback()
localStorage.removeItem("scenarios")
}

const ccFile = getCCFile(file)
NodeDecorator.decorateMapWithPathAttribute(ccFile)
const currentFileChecksum = ccFile.fileMeta.fileChecksum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MatDialog } from "@angular/material/dialog"
import { metricDataSelector } from "../../state/selectors/accumulatedData/metricData/metricData.selector"
import { State, Store, StoreModule } from "@ngrx/store"
import { appReducers, setStateMiddleware } from "../../state/store/state.manager"
import { setCurrentFilesAreSampleFiles } from "../../state/store/appStatus/currentFilesAreSampleFiles/currentFilesAreSampleFiles.actions"

const mockedMetricDataSelector = metricDataSelector as unknown as jest.Mock
jest.mock("../../state/selectors/accumulatedData/metricData/metricData.selector", () => ({
Expand Down Expand Up @@ -160,6 +161,124 @@ describe("loadFileService", () => {
expect(fileRoot.rootPath).toBe(`/${expected.map.name}`)
})

it("should keep old files when loading new files", () => {
const valid2ndFileContent = klona(validFileContent)
valid2ndFileContent.fileChecksum = "hash_1"

codeChartaService.loadFiles([{ fileName: "FirstFile", content: validFileContent, fileSize: 42 }])
codeChartaService.loadFiles([{ fileName: "SecondFile", content: valid2ndFileContent, fileSize: 42 }])

const CCFilesUnderTest = getCCFiles(state.getValue().files)

expect(CCFilesUnderTest.length).toEqual(2)
expect(CCFilesUnderTest[0].fileMeta.fileName).toEqual("FirstFile")
expect(CCFilesUnderTest[0].fileMeta.fileChecksum).toEqual("invalid-md5-sample")
expect(CCFilesUnderTest[1].fileMeta.fileName).toEqual("SecondFile")
expect(CCFilesUnderTest[1].fileMeta.fileChecksum).toEqual("hash_1")
})

it("should delete sample files when loading new files", () => {
const dispatchSpy = jest.spyOn(store, "dispatch")

const valid2ndFileContent = klona(validFileContent)
valid2ndFileContent.fileChecksum = "hash_1"

codeChartaService.loadFiles([{ fileName: "FirstFile", content: validFileContent, fileSize: 42 }])
store.dispatch(setCurrentFilesAreSampleFiles({ value: true }))

codeChartaService.loadFiles([{ fileName: "SecondFile", content: valid2ndFileContent, fileSize: 42 }])

const CCFilesUnderTest = getCCFiles(state.getValue().files)

expect(dispatchSpy).toHaveBeenCalledWith(setCurrentFilesAreSampleFiles({ value: false }))
expect(CCFilesUnderTest.length).toEqual(1)
expect(CCFilesUnderTest[0].fileMeta.fileName).toEqual("SecondFile")
expect(CCFilesUnderTest[0].fileMeta.fileChecksum).toEqual("hash_1")
})

it("should keep sample file when loading the same sample file again", () => {
const dispatchSpy = jest.spyOn(store, "dispatch")

const valid2ndFileContent = klona(validFileContent)
valid2ndFileContent.fileChecksum = "hash_1"

const valid3rdFileContent = klona(validFileContent)
valid3rdFileContent.fileChecksum = "hash_2"

const valid3rdFileContentWithDifferentHash = klona(validFileContent)
valid3rdFileContentWithDifferentHash.fileChecksum = "hash_2_1"

const valid4thFileContent = klona(validFileContent)
valid4thFileContent.fileChecksum = "hash_3"

codeChartaService.loadFiles([
{ fileName: "FirstFile", content: validFileContent, fileSize: 42 },
{ fileName: "SecondFile", content: valid2ndFileContent, fileSize: 42 },
{ fileName: "ThirdFile", content: valid3rdFileContent, fileSize: 42 }
])
store.dispatch(setCurrentFilesAreSampleFiles({ value: true }))

codeChartaService.loadFiles([
{ fileName: "SecondFile", content: valid2ndFileContent, fileSize: 42 },
{ fileName: "ThirdFile", content: valid3rdFileContentWithDifferentHash, fileSize: 42 },
{ fileName: "FourthFile", content: valid4thFileContent, fileSize: 42 }
])

const CCFilesUnderTest = getCCFiles(state.getValue().files)

expect(dispatchSpy).toHaveBeenCalledWith(setCurrentFilesAreSampleFiles({ value: false }))
expect(CCFilesUnderTest.length).toEqual(3)
expect(CCFilesUnderTest[0].fileMeta.fileName).toEqual("SecondFile")
expect(CCFilesUnderTest[0].fileMeta.fileChecksum).toEqual("hash_1")
expect(CCFilesUnderTest[1].fileMeta.fileName).toEqual("ThirdFile")
expect(CCFilesUnderTest[1].fileMeta.fileChecksum).toEqual("hash_2_1")
expect(CCFilesUnderTest[2].fileMeta.fileName).toEqual("FourthFile")
expect(CCFilesUnderTest[2].fileMeta.fileChecksum).toEqual("hash_3")
})

it("should keep sample files when loading the same sample file and after that another different file", () => {
const dispatchSpy = jest.spyOn(store, "dispatch")

const valid2ndFileContent = klona(validFileContent)
valid2ndFileContent.fileChecksum = "hash_1"

codeChartaService.loadFiles([{ fileName: "FirstFile", content: validFileContent, fileSize: 42 }])
store.dispatch(setCurrentFilesAreSampleFiles({ value: true }))

codeChartaService.loadFiles([{ fileName: "FirstFile", content: validFileContent, fileSize: 42 }])
codeChartaService.loadFiles([{ fileName: "SecondFile", content: valid2ndFileContent, fileSize: 42 }])

const CCFilesUnderTest = getCCFiles(state.getValue().files)

expect(dispatchSpy).toHaveBeenCalledWith(setCurrentFilesAreSampleFiles({ value: false }))
expect(CCFilesUnderTest.length).toEqual(2)
expect(CCFilesUnderTest[0].fileMeta.fileName).toEqual("FirstFile")
expect(CCFilesUnderTest[0].fileMeta.fileChecksum).toEqual("invalid-md5-sample")
expect(CCFilesUnderTest[1].fileMeta.fileName).toEqual("SecondFile")
expect(CCFilesUnderTest[1].fileMeta.fileChecksum).toEqual("hash_1")
})

it("should keep sample file when loading a invalid file", () => {
const dispatchSpy = jest.spyOn(store, "dispatch")

codeChartaService.loadFiles([{ fileName: "FirstFile", content: validFileContent, fileSize: 42 }])
store.dispatch(setCurrentFilesAreSampleFiles({ value: true }))

const invalidFileContent = klona(validFileContent)
invalidFileContent.apiVersion = ""

expect(() => codeChartaService.loadFiles([{ fileName: "SecondFile", content: invalidFileContent, fileSize: 42 }])).toThrow(
"File(s) could not be loaded"
)

const CCFilesUnderTest = getCCFiles(state.getValue().files)

expect(dispatchSpy).not.toHaveBeenCalledWith(setCurrentFilesAreSampleFiles({ value: false }))
expect(CCFilesUnderTest.length).toEqual(1)
expect(CCFilesUnderTest[0].fileMeta.fileName).toEqual("FirstFile")
expect(CCFilesUnderTest[0].fileMeta.fileChecksum).toEqual("invalid-md5-sample")
})

it("should replace files with equal file name and checksum when loading new files", () => {
const valid2ndFileContent = klona(validFileContent)
valid2ndFileContent.fileChecksum = "hash_1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { loadFilesValidationToErrorDialog } from "../../util/loadFilesValidation
import { enrichFileStatesAndRecentFilesWithValidationResults } from "./fileParser"
import { fileRoot } from "./fileRoot"
import { Store, State } from "@ngrx/store"
import { setCurrentFilesAreSampleFiles } from "../../state/store/appStatus/currentFilesAreSampleFiles/currentFilesAreSampleFiles.actions"

export const NO_FILES_LOADED_ERROR_MESSAGE = "File(s) could not be loaded"

Expand Down Expand Up @@ -45,7 +46,14 @@ export class LoadFileService implements OnDestroy {
const recentFiles: string[] = []
const fileValidationResults: CCFileValidationResult[] = []

enrichFileStatesAndRecentFilesWithValidationResults(fileStates, recentFiles, nameDataPairs, fileValidationResults)
enrichFileStatesAndRecentFilesWithValidationResults(
fileStates,
recentFiles,
nameDataPairs,
fileValidationResults,
() => this.state.getValue().appStatus.currentFilesAreSampleFiles,
() => this.store.dispatch(setCurrentFilesAreSampleFiles({ value: false }))
)

if (fileValidationResults.length > 0) {
this.dialog.open(ErrorDialogComponent, {
Expand Down
Loading
Loading