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

Refactor/2318/migrate node serach service #2495

Merged
merged 9 commits into from
Nov 12, 2021
Merged
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/)

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

### Changed

- Chore: Remove `nodeSearch.service.ts` and `searchedNodePaths` from store as they can be derived from `searchPattern`.
shaman-apprentice marked this conversation as resolved.
Show resolved Hide resolved

## [1.83.1] - 2021-11-10

Expand Down
1 change: 0 additions & 1 deletion visualization/app/codeCharta/codeCharta.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export interface DynamicSettings {
distributionMetric: string
edgeMetric: string
focusedNodePath: string
searchedNodePaths: Set<string>
searchPattern: string
margin: number
colorRange: ColorRange
Expand Down
2 changes: 0 additions & 2 deletions visualization/app/codeCharta/state/injector.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { DistributionMetricService } from "./store/dynamicSettings/distributionM
import { ColorMetricService } from "./store/dynamicSettings/colorMetric/colorMetric.service"
import { AreaMetricService } from "./store/dynamicSettings/areaMetric/areaMetric.service"
import { BlacklistService } from "./store/fileSettings/blacklist/blacklist.service"
import { NodeSearchService } from "./nodeSearch.service"
import { IsPresentationModeService } from "./store/appSettings/isPresentationMode/isPresentationMode.service"
import { MetricDataService } from "./store/metricData/metricData.service"
import { ExperimentalFeaturesEnabledService } from "./store/appSettings/enableExperimentalFeatures/experimentalFeaturesEnabled.service"
Expand Down Expand Up @@ -100,7 +99,6 @@ export class InjectorService {
private colorMetricService: ColorMetricService,
private areaMetricService: AreaMetricService,
private blacklistService: BlacklistService,
private nodeSearchService: NodeSearchService,
private isPresentationModeService: IsPresentationModeService,
private layoutAlgorithmService: LayoutAlgorithmService,
private maxTreeMapFilesService: MaxTreeMapFilesService,
Expand Down
151 changes: 0 additions & 151 deletions visualization/app/codeCharta/state/nodeSearch.service.spec.ts

This file was deleted.

42 changes: 0 additions & 42 deletions visualization/app/codeCharta/state/nodeSearch.service.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { TEST_FILE_WITH_PATHS } from "../../../util/dataMocks"
import { getNodesByGitignorePath } from "./getNodesByGitignorePath"

describe("getNodesByGitignorePath", () => {
it("should retrieve no nodes for an empty search", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, "")

expect(searchedNodes.length).toBe(0)
})

it("should retrieve no nodes if searched within nothing", () => {
const searchedNodes = getNodesByGitignorePath(undefined, "")

expect(searchedNodes.length).toBe(0)
})

it("should find nodes based on a wildcard search", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, "*small*")

expect(searchedNodes.length).toBe(2)
expect(searchedNodes[0].path).toBe("/root/Parent Leaf/small leaf")
expect(searchedNodes[1].path).toBe("/root/Parent Leaf/other small leaf")
})

it("should find nodes based on string search", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, "small")

expect(searchedNodes.length).toBe(2)
expect(searchedNodes[0].path).toBe("/root/Parent Leaf/small leaf")
expect(searchedNodes[1].path).toBe("/root/Parent Leaf/other small leaf")
})

it("should find no nodes based on prefix search with non existing prefix", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, "oot/*")

expect(searchedNodes.length).toBe(0)
})

it("should find all nodes based on prefix search with prefix of root node", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, "root*")

expect(searchedNodes.length).toBe(6)
})

it("should find nodes based on exact match", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, '"/root/Parent Leaf"')

expect(searchedNodes.length).toBe(4)
expect(searchedNodes[0].path).toBe("/root/Parent Leaf")
expect(searchedNodes[1].path).toBe("/root/Parent Leaf/small leaf")
expect(searchedNodes[2].path).toBe("/root/Parent Leaf/other small leaf")
expect(searchedNodes[3].path).toBe("/root/Parent Leaf/empty folder")
})

it("should not ignore a leading whitespace with exact match", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, '" /root/Parent Leaf"')

expect(searchedNodes.length).toBe(0)
})

it("should find nodes based on inverted search", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, "!leaf")

expect(searchedNodes.length).toBe(1)
expect(searchedNodes[0].path).toBe("/root")
})

it("should find nodes based on multiple inverted search", () => {
const searchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, " \tsmall, \tbig")
expect(searchedNodes.length).toBe(3)
expect(searchedNodes[0].path).toBe("/root/big leaf")
expect(searchedNodes[1].path).toBe("/root/Parent Leaf/small leaf")
expect(searchedNodes[2].path).toBe("/root/Parent Leaf/other small leaf")

const invertedSearchedNodes = getNodesByGitignorePath(TEST_FILE_WITH_PATHS.map, "! \tsmall, \tbig")

expect(invertedSearchedNodes.length).toBe(3)
expect(invertedSearchedNodes[0].path).toBe("/root")
expect(invertedSearchedNodes[1].path).toBe("/root/Parent Leaf")
expect(invertedSearchedNodes[2].path).toBe("/root/Parent Leaf/empty folder")
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { hierarchy } from "d3-hierarchy"

import { CodeMapNode } from "../../../codeCharta.model"
import { returnIgnore, transformPath } from "../../../util/codeMapHelper"

export function getNodesByGitignorePath(root: CodeMapNode, gitignorePath: string) {
gitignorePath = gitignorePath.trimStart()
if (gitignorePath.length === 0 || !root) {
return []
}
const ignoreResults = returnIgnore(gitignorePath)
const filtered = []
for (const { data } of hierarchy(root)) {
if (ignoreResults.ignoredNodePaths.ignores(transformPath(data.path)) === ignoreResults.condition) {
filtered.push(data)
}
}
return filtered
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createSelector } from "../../angular-redux/store"
import { searchedNodesSelector } from "./searchedNodes.selector"

export const searchedNodePathsSelector = createSelector([searchedNodesSelector], searchedNodes => new Set(searchedNodes.map(x => x.path)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createSelector } from "../../angular-redux/store"
import { getNodesByGitignorePath } from "./getNodesByGitignorePath"
import { unifiedMapNodeSelector } from "../accumulatedData/unifiedMapNode.selector"
import { searchPatternSelector } from "../../store/dynamicSettings/searchPattern/searchPattern.selector"

export const searchedNodesSelector = createSelector([unifiedMapNodeSelector, searchPatternSelector], (unifiedMapNode, searchPattern) =>
getNodesByGitignorePath(unifiedMapNode, searchPattern)
)
2 changes: 0 additions & 2 deletions visualization/app/codeCharta/state/state.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { AreaMetricService } from "./store/dynamicSettings/areaMetric/areaMetric
import { BlacklistService } from "./store/fileSettings/blacklist/blacklist.service"
import { InjectorService } from "./injector.service"
import { StoreService } from "./store.service"
import { NodeSearchService } from "./nodeSearch.service"
import "../codeCharta.module"
import camelCase from "lodash.camelcase"
import { IsPresentationModeService } from "./store/appSettings/isPresentationMode/isPresentationMode.service"
Expand Down Expand Up @@ -106,7 +105,6 @@ angular
.service(camelCase(BlacklistService.name), BlacklistService)
.service(camelCase(InjectorService.name), InjectorService)
.service(camelCase(StoreService.name), StoreService)
.service(camelCase(NodeSearchService.name), NodeSearchService)
.service(camelCase(LayoutAlgorithmService.name), LayoutAlgorithmService)
.service(camelCase(MaxTreeMapFilesService.name), MaxTreeMapFilesService)
.service(camelCase(SharpnessModeService.name), SharpnessModeService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { defaultEdgeMetric } from "./edgeMetric/edgeMetric.actions"
import { defaultFocusedNodePath } from "./focusedNodePath/focusedNodePath.actions"
import { defaultHeightMetric } from "./heightMetric/heightMetric.actions"
import { defaultMargin } from "./margin/margin.actions"
import { defaultSearchedNodePaths } from "./searchedNodePaths/searchedNodePaths.actions"
import { defaultSearchPattern } from "./searchPattern/searchPattern.actions"

export enum DynamicSettingsActions {
Expand Down Expand Up @@ -44,7 +43,6 @@ export const defaultDynamicSettings: DynamicSettings = {
distributionMetric: defaultDistributionMetric,
edgeMetric: defaultEdgeMetric,
focusedNodePath: defaultFocusedNodePath,
searchedNodePaths: defaultSearchedNodePaths,
searchPattern: defaultSearchPattern,
margin: defaultMargin,
colorRange: defaultColorRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { edgeMetric } from "./edgeMetric/edgeMetric.reducer"
import { colorRange } from "./colorRange/colorRange.reducer"
import { margin } from "./margin/margin.reducer"
import { searchPattern } from "./searchPattern/searchPattern.reducer"
import { searchedNodePaths } from "./searchedNodePaths/searchedNodePaths.reducer"
import { focusedNodePath } from "./focusedNodePath/focusedNodePath.reducer"
import { heightMetric } from "./heightMetric/heightMetric.reducer"
import { distributionMetric } from "./distributionMetric/distributionMetric.reducer"
Expand All @@ -23,7 +22,6 @@ const dynamicSettings = combineReducers({
colorRange,
margin,
searchPattern,
searchedNodePaths,
focusedNodePath,
heightMetric,
distributionMetric,
Expand Down