Skip to content

Commit

Permalink
Feature/1880/indicate total nodes and excluded / flattened nodes in f…
Browse files Browse the repository at this point in the history
…ile explorer (#1929)

* add new function to get all nodes #1880

* get all nodes in order to indicate them in file explorer next to the number of the matching nodes #1880

* fix some tests and rename a variable in matching file conter #1880

* add test for new function getAllNodes #1880

* run prettier #1880

Co-authored-by: Shivan Oskan <shivan.oskan@maibornwolff.de>
Co-authored-by: RomanenkoVladimir <volodymyr.romanenko@icloud.com>
  • Loading branch information
3 people committed Apr 16, 2021
1 parent da9167c commit 1c2e91e
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
### Added 🚀

- Hints for Global Settings ([#1715](https://github.com/MaibornWolff/codecharta/issues/1715))
- Indicate total nodes and excluded / flattened nodes in file explorer ([#1880](https://github.com/MaibornWolff/codecharta/issues/1880))

### Fixed 🐞

Expand Down
12 changes: 6 additions & 6 deletions visualization/app/codeCharta/state/nodeSearch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { setSearchedNodePaths } from "./store/dynamicSettings/searchedNodePaths/
import { SearchPatternService, SearchPatternSubscriber } from "./store/dynamicSettings/searchPattern/searchPattern.service"

export interface NodeSearchSubscriber {
onNodeSearchComplete(searchedNodes: CodeMapNode[])
onNodeSearchComplete(searchedNodes: CodeMapNode[], searchPattern: string)
}

export class NodeSearchService implements SearchPatternSubscriber {
Expand All @@ -26,17 +26,17 @@ export class NodeSearchService implements SearchPatternSubscriber {

onSearchPatternChanged(searchPattern: string) {
this.searchedNodes = getNodesByGitignorePath(this.codeMapPreRenderService.getRenderMap(), searchPattern)
this.notifyNodeSearchComplete()
this.notifyNodeSearchComplete(searchPattern)
this.storeService.dispatch(setSearchedNodePaths(new Set(this.searchedNodes.map(x => x.path))))
}

private notifyNodeSearchComplete() {
this.$rootScope.$broadcast(NodeSearchService.NODE_SEARCH_COMPLETE_EVENT, this.searchedNodes)
private notifyNodeSearchComplete(searchPattern: string) {
this.$rootScope.$broadcast(NodeSearchService.NODE_SEARCH_COMPLETE_EVENT, this.searchedNodes, searchPattern)
}

static subscribe($rootScope: IRootScopeService, subscriber: NodeSearchSubscriber) {
$rootScope.$on(NodeSearchService.NODE_SEARCH_COMPLETE_EVENT, (_event_, data) => {
subscriber.onNodeSearchComplete(data)
$rootScope.$on(NodeSearchService.NODE_SEARCH_COMPLETE_EVENT, (_event_, searchedNodes, searchPattern) => {
subscriber.onNodeSearchComplete(searchedNodes, searchPattern)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { NodeSearchService } from "../../state/nodeSearch.service"
import { BlacklistService } from "../../state/store/fileSettings/blacklist/blacklist.service"
import { StoreService } from "../../state/store.service"
import { addBlacklistItem } from "../../state/store/fileSettings/blacklist/blacklist.actions"
import { CodeMapPreRenderService } from "../codeMap/codeMap.preRender.service"

describe("MatchingFilesCounterController", () => {
let matchingFilesCounterController: MatchingFilesCounterController
let $rootScope: IRootScopeService
let storeService: StoreService
let codeMapPreRenderService: CodeMapPreRenderService

beforeEach(() => {
restartSystem()
Expand All @@ -23,10 +25,11 @@ describe("MatchingFilesCounterController", () => {
instantiateModule("app.codeCharta.ui.matchingFilesCounter")
$rootScope = getService<IRootScopeService>("$rootScope")
storeService = getService<StoreService>("storeService")
codeMapPreRenderService = getService<CodeMapPreRenderService>("codeMapPreRenderService")
}

function rebuildController() {
matchingFilesCounterController = new MatchingFilesCounterController($rootScope, storeService)
matchingFilesCounterController = new MatchingFilesCounterController($rootScope, storeService, codeMapPreRenderService)
}

describe("constructor", () => {
Expand Down Expand Up @@ -59,9 +62,9 @@ describe("MatchingFilesCounterController", () => {

matchingFilesCounterController["updateViewModel"]()

expect(matchingFilesCounterController["_viewModel"].fileCount).toEqual(2)
expect(matchingFilesCounterController["_viewModel"].flattenCount).toEqual(2)
expect(matchingFilesCounterController["_viewModel"].excludeCount).toEqual(2)
expect(matchingFilesCounterController["_viewModel"].fileCount).toEqual("2/0")
expect(matchingFilesCounterController["_viewModel"].flattenCount).toEqual("2/0")
expect(matchingFilesCounterController["_viewModel"].excludeCount).toEqual("2/0")
})
})

Expand All @@ -81,8 +84,7 @@ describe("MatchingFilesCounterController", () => {
rootNode.children[1].children[1],
rootNode.children[1].children[2]
]
matchingFilesCounterController.onNodeSearchComplete(searchNodes)

matchingFilesCounterController.onNodeSearchComplete(searchNodes, "r")
expect(matchingFilesCounterController["searchedNodeLeaves"]).toEqual(nodeLeaves)
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
import "./matchingFilesCounter.component.scss"
import { BlacklistType, CodeMapNode } from "../../codeCharta.model"
import { isLeaf, isPathBlacklisted } from "../../util/codeMapHelper"
import { getAllNodes, isLeaf, isPathBlacklisted } from "../../util/codeMapHelper"
import { IRootScopeService } from "angular"
import { NodeSearchService, NodeSearchSubscriber } from "../../state/nodeSearch.service"
import { BlacklistService, BlacklistSubscriber } from "../../state/store/fileSettings/blacklist/blacklist.service"
import { StoreService } from "../../state/store.service"
import { CodeMapPreRenderService } from "../codeMap/codeMap.preRender.service"

export class MatchingFilesCounterController implements NodeSearchSubscriber, BlacklistSubscriber {
private _viewModel: {
fileCount: number
flattenCount: number
excludeCount: number
fileCount: string
flattenCount: string
excludeCount: string
searchPattern: string
} = {
fileCount: 0,
flattenCount: 0,
excludeCount: 0,
fileCount: "",
flattenCount: "",
excludeCount: "",
searchPattern: ""
}

private searchedNodeLeaves: CodeMapNode[] = []
private allNodes: CodeMapNode[] = []

constructor(private $rootScope: IRootScopeService, private storeService: StoreService) {
constructor(
private $rootScope: IRootScopeService,
private storeService: StoreService,
private codeMapPreRenderService: CodeMapPreRenderService
) {
NodeSearchService.subscribe(this.$rootScope, this)
BlacklistService.subscribe(this.$rootScope, this)
}

onNodeSearchComplete(searchedNodes: CodeMapNode[]) {
onNodeSearchComplete(searchedNodes: CodeMapNode[], searchPattern: string) {
this.searchedNodeLeaves = searchedNodes.filter(node => isLeaf(node))
this.allNodes = getAllNodes(this.codeMapPreRenderService.getRenderMap())
this._viewModel.searchPattern = searchPattern
this.updateViewModel()
}

Expand All @@ -36,14 +44,25 @@ export class MatchingFilesCounterController implements NodeSearchSubscriber, Bla
}

private updateViewModel() {
this._viewModel.fileCount = this.searchedNodeLeaves.length
this._viewModel.flattenCount = this.getBlacklistedFileCount(BlacklistType.flatten)
this._viewModel.excludeCount = this.getBlacklistedFileCount(BlacklistType.exclude)
if (this._viewModel.searchPattern.length === 0) {
this._viewModel.fileCount = `${this.allNodes.length}`
this._viewModel.flattenCount = `${this.getBlacklistedFileCount(BlacklistType.flatten, this.allNodes)}`
this._viewModel.excludeCount = `${this.getBlacklistedFileCount(BlacklistType.exclude, this.allNodes)}`
}
this._viewModel.fileCount = `${this.searchedNodeLeaves.length}/${this.allNodes.length}`
this._viewModel.flattenCount = `${this.getBlacklistedFileCount(
BlacklistType.flatten,
this.searchedNodeLeaves
)}/${this.getBlacklistedFileCount(BlacklistType.flatten, this.allNodes)}`
this._viewModel.excludeCount = `${this.getBlacklistedFileCount(
BlacklistType.exclude,
this.searchedNodeLeaves
)}/${this.getBlacklistedFileCount(BlacklistType.exclude, this.allNodes)}`
}

private getBlacklistedFileCount(blacklistType: BlacklistType) {
private getBlacklistedFileCount(blacklistType: BlacklistType, nodes: CodeMapNode[]) {
const blacklist = this.storeService.getState().fileSettings.blacklist
return this.searchedNodeLeaves.reduce((count, { path }) => {
return nodes.reduce((count, { path }) => {
if (isPathBlacklisted(path, blacklist, blacklistType)) {
count++
}
Expand Down
16 changes: 15 additions & 1 deletion visualization/app/codeCharta/util/codeMapHelper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { CCFile } from "../codeCharta.model"
import packageJson from "../../../package.json"
import { getMapResolutionScaleFactor, MAP_RESOLUTION_SCALE } from "./codeMapHelper"
import { getAllNodes, getMapResolutionScaleFactor, MAP_RESOLUTION_SCALE } from "./codeMapHelper"
import { FileSelectionState, FileState } from "../model/files/files"
import { VALID_NODE_WITH_PATH } from "./dataMocks"

describe("CodeMapHelper", () => {
describe("getMapResolutionScaleFactor", () => {
Expand Down Expand Up @@ -134,4 +135,17 @@ describe("CodeMapHelper", () => {
expect(getMapResolutionScaleFactor(fileStateMultiple)).toBe(MAP_RESOLUTION_SCALE.BIG_MAP)
})
})

describe("getAllNodes", () => {
it("should return array of all nodes for given root", () => {
const rootNode = VALID_NODE_WITH_PATH
const nodeLeaves = [rootNode.children[0], rootNode.children[1].children[0], rootNode.children[1].children[1]]
expect(getAllNodes(rootNode)).toEqual(nodeLeaves)
})

it("should return empty array for undefined root", () => {
const rootNode = undefined
expect(getAllNodes(rootNode)).toEqual([])
})
})
})
12 changes: 12 additions & 0 deletions visualization/app/codeCharta/util/codeMapHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ export function transformPath(toTransform: string) {
return toTransform.slice(removeNumberOfCharactersFromStart)
}

export function getAllNodes(root: CodeMapNode) {
const filtered = []
if (root !== undefined) {
for (const { data } of hierarchy(root)) {
if (data.type !== "Folder") {
filtered.push(data)
}
}
}
return filtered
}

export function getNodesByGitignorePath(root: CodeMapNode, gitignorePath: string) {
gitignorePath = gitignorePath.trimStart()
if (gitignorePath.length === 0) {
Expand Down

0 comments on commit 1c2e91e

Please sign in to comment.