-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate node path panel to Angular (#2855)
* refactor: migrate node path panel to Angular ref #2318
- Loading branch information
1 parent
21f9aee
commit 1375bdc
Showing
18 changed files
with
159 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
visualization/app/codeCharta/ui/nodePathPanel/nodePathPanel.component.html
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
visualization/app/codeCharta/ui/nodePathPanel/nodePathPanel.component.scss
This file was deleted.
Oops, something went wrong.
73 changes: 0 additions & 73 deletions
73
visualization/app/codeCharta/ui/nodePathPanel/nodePathPanel.component.spec.ts
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
visualization/app/codeCharta/ui/nodePathPanel/nodePathPanel.component.ts
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
visualization/app/codeCharta/ui/nodePathPanel/nodePathPanel.module.ts
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...zation/app/codeCharta/ui/toolBar/hoveredNodePathPanel/hoveredNodePathPanel.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<ng-container *ngIf="hoveredNodePathPanelData$ | async; let hoveredNodePathPanelData"> | ||
<span *ngFor="let step of hoveredNodePathPanelData.path; let last = last"> | ||
<i | ||
*ngIf="last" | ||
class="fa" | ||
[class.fa-file-o]="hoveredNodePathPanelData.isFile" | ||
[class.fa-folder]="!hoveredNodePathPanelData.isFile" | ||
></i> | ||
<span [class.bold]="last">{{ step }}</span> | ||
<i *ngIf="!last" class="fa fa-angle-right"></i> | ||
</span> | ||
</ng-container> |
18 changes: 18 additions & 0 deletions
18
...zation/app/codeCharta/ui/toolBar/hoveredNodePathPanel/hoveredNodePathPanel.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cc-hovered-node-path-panel { | ||
width: 100%; | ||
min-width: 400px; | ||
display: inline-block; | ||
vertical-align: middle; | ||
margin: 0 8px; | ||
font-size: 10pt; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
|
||
.bold { | ||
font-weight: 600; | ||
} | ||
|
||
i { | ||
margin: 0 4px; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ion/app/codeCharta/ui/toolBar/hoveredNodePathPanel/hoveredNodePathPanel.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { TestBed } from "@angular/core/testing" | ||
import { render } from "@testing-library/angular" | ||
import { mocked } from "ts-jest/utils" | ||
import { HoveredNodePathPanelComponent } from "./hoveredNodePathPanel.component" | ||
import { HoveredNodePathPanelModule } from "./hoveredNodePathPanel.module" | ||
import { hoveredNodePathPanelDataSelector } from "./hoveredNodePathPanelData.selector" | ||
|
||
jest.mock("./hoveredNodePathPanelData.selector", () => ({ | ||
hoveredNodePathPanelDataSelector: jest.fn() | ||
})) | ||
const mockedHoveredNodePathPanelDataSelector = mocked(hoveredNodePathPanelDataSelector) | ||
|
||
describe("HoveredNodePathPanelComponent", () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HoveredNodePathPanelModule] | ||
}) | ||
}) | ||
|
||
it("should be empty when there is no node hovered", async () => { | ||
mockedHoveredNodePathPanelDataSelector.mockImplementation(() => undefined) | ||
const { container } = await render(HoveredNodePathPanelComponent, { excludeComponentDeclaration: true }) | ||
expect(container.textContent).toBe("") | ||
}) | ||
|
||
it("should show path to a hovered file", async () => { | ||
mockedHoveredNodePathPanelDataSelector.mockImplementation(() => ({ | ||
path: ["root", "a.ts"], | ||
isFile: true | ||
})) | ||
const { container } = await render(HoveredNodePathPanelComponent, { excludeComponentDeclaration: true }) | ||
|
||
const steps = container.children | ||
expect(steps.length).toBe(2) | ||
|
||
expect(steps[0].textContent).toBe("root") | ||
const iconOfFirstStep = steps[0].querySelector("i") | ||
expect(iconOfFirstStep.className).toBe("fa fa-angle-right") | ||
|
||
expect(steps[1].textContent).toBe("a.ts") | ||
const iconOfLastStep = steps[1].querySelector("i") | ||
expect(iconOfLastStep.className).toBe("fa fa-file-o") | ||
}) | ||
|
||
it("should show path to a hovered folder", async () => { | ||
mockedHoveredNodePathPanelDataSelector.mockImplementation(() => ({ | ||
path: ["root"], | ||
isFile: false | ||
})) | ||
const { container } = await render(HoveredNodePathPanelComponent, { excludeComponentDeclaration: true }) | ||
|
||
const steps = container.children | ||
expect(steps.length).toBe(1) | ||
|
||
expect(steps[0].textContent).toBe("root") | ||
const iconOfLastStep = steps[0].querySelector("i") | ||
expect(iconOfLastStep.className).toBe("fa fa-folder") | ||
}) | ||
}) |
14 changes: 14 additions & 0 deletions
14
...lization/app/codeCharta/ui/toolBar/hoveredNodePathPanel/hoveredNodePathPanel.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import "./hoveredNodePathPanel.component.scss" | ||
import { Component, Inject } from "@angular/core" | ||
import { Store } from "../../../state/angular-redux/store" | ||
import { hoveredNodePathPanelDataSelector } from "./hoveredNodePathPanelData.selector" | ||
|
||
@Component({ | ||
selector: "cc-hovered-node-path-panel", | ||
template: require("./hoveredNodePathPanel.component.html") | ||
}) | ||
export class HoveredNodePathPanelComponent { | ||
hoveredNodePathPanelData$ = this.store.select(hoveredNodePathPanelDataSelector) | ||
|
||
constructor(@Inject(Store) private store: Store) {} | ||
} |
11 changes: 11 additions & 0 deletions
11
visualization/app/codeCharta/ui/toolBar/hoveredNodePathPanel/hoveredNodePathPanel.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CommonModule } from "@angular/common" | ||
import { NgModule } from "@angular/core" | ||
import { HoveredNodePathPanelComponent } from "./hoveredNodePathPanel.component" | ||
|
||
@NgModule({ | ||
imports: [CommonModule], | ||
declarations: [HoveredNodePathPanelComponent], | ||
exports: [HoveredNodePathPanelComponent], | ||
entryComponents: [HoveredNodePathPanelComponent] | ||
}) | ||
export class HoveredNodePathPanelModule {} |
26 changes: 26 additions & 0 deletions
26
.../app/codeCharta/ui/toolBar/hoveredNodePathPanel/hoveredNodePathPanelData.selector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { NodeType } from "../../../codeCharta.model" | ||
import { _getHoveredNodePathPanelData } from "./hoveredNodePathPanelData.selector" | ||
|
||
describe("hoveredNodePathPanelDataSelector", () => { | ||
it("should return undefined when there is no hovered node", () => { | ||
expect(_getHoveredNodePathPanelData()).toBe(undefined) | ||
}) | ||
|
||
it("should return correct data for a file", () => { | ||
expect( | ||
_getHoveredNodePathPanelData({ | ||
path: "/root/a.ts", | ||
type: NodeType.FILE | ||
}) | ||
).toEqual({ path: ["root", "a.ts"], isFile: true }) | ||
}) | ||
|
||
it("should return correct data for a folder", () => { | ||
expect( | ||
_getHoveredNodePathPanelData({ | ||
path: "/root", | ||
type: NodeType.FOLDER | ||
}) | ||
).toEqual({ path: ["root"], isFile: false }) | ||
}) | ||
}) |
11 changes: 11 additions & 0 deletions
11
...ation/app/codeCharta/ui/toolBar/hoveredNodePathPanel/hoveredNodePathPanelData.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CodeMapNode } from "../../../codeCharta.model" | ||
import { createSelector } from "../../../state/angular-redux/createSelector" | ||
import { hoveredNodeSelector } from "../../../state/selectors/hoveredNode.selector" | ||
|
||
export const _getHoveredNodePathPanelData = (hoveredNode?: Pick<CodeMapNode, "path" | "type">) => | ||
hoveredNode && { | ||
path: hoveredNode.path.slice(1).split("/"), | ||
isFile: hoveredNode.type === "File" | ||
} | ||
|
||
export const hoveredNodePathPanelDataSelector = createSelector([hoveredNodeSelector], _getHoveredNodePathPanelData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters