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

Tech/move filestates to redux #853

Merged
merged 56 commits into from Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
87a23dc
Add files to redux state
NearW Jan 24, 2020
695eef6
Fixed wrong parenthesis in splitter template
NearW Jan 24, 2020
a3a8d69
Add model folder and move model to it
NearW Jan 24, 2020
b7497fa
Add files that combine logic of fileStateService and fileStateHelper
NearW Jan 24, 2020
f1938fa
Add reducer implementation
NearW Jan 24, 2020
ee302ca
Add missing multiple mode test
NearW Jan 24, 2020
5af56d5
Merge remote-tracking branch 'remotes/origin/master' into tech/move-f…
NearW Jan 30, 2020
c0fae6e
Merge remote-tracking branch 'remotes/origin/master' into tech/move-f…
NearW Jan 31, 2020
02adf90
Merge branch 'master' into tech/move-filestates-to-redux
NearW Jan 31, 2020
c4a004b
Refactor move files to rootReducer
NearW Feb 8, 2020
f83a249
Merge remote-tracking branch 'remotes/origin/master' into tech/move-f…
NearW Feb 8, 2020
1c764c0
Add update files in redux store
NearW Feb 12, 2020
e9d9676
Refactor rename methods to indicate that parameter are multiple files
NearW Feb 12, 2020
052940b
Refactor clone files before setting them
NearW Feb 12, 2020
36a4b65
Refactor use lodash deepClone for now
NearW Feb 12, 2020
cae3f4d
Refactor using CCAction instead of Action and make payload optional
NearW Feb 12, 2020
3fefdfa
Fix setSingle, setMultiple and setDelta not comparing correctly
NearW Feb 12, 2020
3787f19
Refactor replace read from fileStateService
NearW Feb 12, 2020
b73dba4
Remove FileStateService and FileStateHelper
NearW Feb 12, 2020
677b4a4
Merge remote-tracking branch 'remotes/origin/master' into tech/move-f…
NearW Feb 12, 2020
ede9eaf
Fix split filesActions into newFilesImported and selectionChanged to …
NearW Feb 14, 2020
5455cb4
Refactor rename subscribe method
NearW Feb 14, 2020
553f785
Refactor use Files in viewModel
NearW Feb 14, 2020
601642f
Fix inverting files in multiple mode not updating the viewModel corre…
NearW Feb 14, 2020
2c11162
Remove settingsMerger
NearW Feb 14, 2020
6048815
Refactor replace lodash clone with rfdc
NearW Feb 14, 2020
556a47b
Merge remote-tracking branch 'remotes/origin/master' into tech/move-f…
NearW Feb 14, 2020
1618a10
Merge branch 'master' into tech/move-filestates-to-redux
NearW Feb 19, 2020
48eedaa
Move model back to codeCharta folder to make reviewing easier
NearW Feb 20, 2020
6d15873
Merge remote-tracking branch 'remotes/origin/master' into tech/move-f…
NearW Feb 20, 2020
5d1f757
Remove empty block in test
NearW Feb 20, 2020
115095e
Refactor renamed parameter in lambda functions to x
NearW Feb 21, 2020
586f974
Refactor use includes instead of indexOf
NearW Feb 21, 2020
2b37cff
Refactor replaced filter with existing method
NearW Feb 21, 2020
bf2d99f
Remove obsolete filter
NearW Feb 21, 2020
9f02aa4
Refactor flip if-Statement
NearW Feb 21, 2020
29eca76
Refactor use visibleFileStates
NearW Feb 21, 2020
502b148
Refactor replace wrong method name in test descriptions
NearW Feb 21, 2020
782ecbf
Refactor replace test to expect unary metric exactly once
NearW Feb 21, 2020
38354be
Refactor flip if statement
NearW Feb 21, 2020
0e8d131
Update visualization/app/codeCharta/state/store/files/files.reducer.s…
NearW Feb 21, 2020
8ecbe94
Update visualization/app/codeCharta/state/store/fileSettings/markedPa…
NearW Feb 21, 2020
c43889e
Update visualization/app/codeCharta/state/store/files/files.reducer.s…
NearW Feb 21, 2020
371d3da
Update visualization/app/codeCharta/state/store/files/files.reducer.s…
NearW Feb 21, 2020
336e132
Update visualization/app/codeCharta/state/store/files/files.reducer.s…
NearW Feb 21, 2020
c2cd467
Merge remote-tracking branch 'origin/tech/move-filestates-to-redux' i…
NearW Feb 21, 2020
3d562a4
Refactor wrap test in describe
NearW Feb 21, 2020
0144738
Update test description
NearW Feb 21, 2020
143f1b8
Refactor use fileStatesAvailable
NearW Feb 21, 2020
62216b6
Fixed wrongly copy pasted test
NearW Feb 21, 2020
8cf76d3
Remove obsolete test
NearW Feb 21, 2020
cfcdd53
Refactor fileStatesAvailable usage
NearW Feb 21, 2020
1b81b79
Merge remote-tracking branch 'origin/master' into tech/move-filestate…
alschmut Feb 21, 2020
86adef6
Do not dispatch new fileSelection if no file selected in multiple state
alschmut Mar 7, 2020
04e1997
Update CHANGELOG.md
alschmut Mar 7, 2020
788cc32
Merge branch 'master' into tech/move-filestates-to-redux
JaiJoPa Mar 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
### Fixed 🐞

- Loading Gif not displayed when preparing to render a new map #857
- Selecting zero files in Multiple mode will not trigger the 3D CodeMap creation

### Chore 👨‍💻 👩‍💻

Expand Down
13 changes: 1 addition & 12 deletions visualization/app/codeCharta/codeCharta.component.spec.ts
Expand Up @@ -7,7 +7,6 @@ import { CodeChartaController } from "./codeCharta.component"
import { getService, instantiateModule } from "../../mocks/ng.mockhelper"
import { State } from "./codeCharta.model"
import { ScenarioHelper } from "./util/scenarioHelper"
import { FileStateService } from "./state/fileState.service"
import { InjectorService } from "./state/injector.service"
import { StoreService } from "./state/store.service"
import { STATE } from "./util/dataMocks"
Expand All @@ -20,7 +19,6 @@ describe("codeChartaController", () => {
let storeService: StoreService
let dialogService: DialogService
let codeChartaService: CodeChartaService
let fileStateService: FileStateService
let injectorService: InjectorService
let state: State

Expand All @@ -41,22 +39,13 @@ describe("codeChartaController", () => {
storeService = getService<StoreService>("storeService")
dialogService = getService<DialogService>("dialogService")
codeChartaService = getService<CodeChartaService>("codeChartaService")
fileStateService = getService<FileStateService>("fileStateService")
injectorService = getService<InjectorService>("injectorService")

state = _.cloneDeep(STATE)
}

function rebuildController() {
codeChartaController = new CodeChartaController(
$location,
$http,
storeService,
dialogService,
codeChartaService,
fileStateService,
injectorService
)
codeChartaController = new CodeChartaController($location, $http, storeService, dialogService, codeChartaService, injectorService)
}

afterEach(() => {
Expand Down
10 changes: 4 additions & 6 deletions visualization/app/codeCharta/codeCharta.component.ts
Expand Up @@ -5,7 +5,6 @@ import { CodeChartaService } from "./codeCharta.service"
import { ScenarioHelper } from "./util/scenarioHelper"
import { DialogService } from "./ui/dialog/dialog.service"
import { NameDataPair } from "./codeCharta.model"
import { FileStateService } from "./state/fileState.service"
import { InjectorService } from "./state/injector.service"
import { StoreService } from "./state/store.service"
import { setState } from "./state/store/state.actions"
Expand All @@ -32,7 +31,6 @@ export class CodeChartaController {
private storeService: StoreService,
private dialogService: DialogService,
private codeChartaService: CodeChartaService,
private fileStateService: FileStateService,
// tslint:disable-next-line
private injectorService: InjectorService // We have to inject it somewhere
) {
Expand Down Expand Up @@ -86,14 +84,14 @@ export class CodeChartaController {

private setRenderStateFromUrl() {
const renderState: string = this.urlUtils.getParameterByName("mode")
const files = this.fileStateService.getCCFiles()
const files = this.storeService.getState().files.getCCFiles()

if (renderState === "Delta" && files.length >= 2) {
this.fileStateService.setDelta(files[0], files[1])
this.storeService.getState().files.setDelta(files[0], files[1])
} else if (renderState === "Multiple") {
this.fileStateService.setMultiple(files)
this.storeService.getState().files.setMultiple(files)
} else {
this.fileStateService.setSingle(files[0])
this.storeService.getState().files.setSingle(files[0])
}
}

Expand Down
4 changes: 3 additions & 1 deletion visualization/app/codeCharta/codeCharta.model.ts
@@ -1,5 +1,6 @@
import { Vector3 } from "three"
import { Action } from "redux"
import { Files } from "./model/files"

export interface NameDataPair {
fileName: string
Expand Down Expand Up @@ -249,8 +250,9 @@ export interface State {
dynamicSettings: DynamicSettings
appSettings: AppSettings
treeMap: TreeMapSettings
files: Files
}

export interface CCAction extends Action {
payload: any
payload?: any
}
76 changes: 50 additions & 26 deletions visualization/app/codeCharta/codeCharta.service.spec.ts
Expand Up @@ -2,29 +2,31 @@ import "./codeCharta.module"

import { CodeChartaService } from "./codeCharta.service"
import { getService, instantiateModule } from "../../mocks/ng.mockhelper"
import { FileStateService } from "./state/fileState.service"
import { TEST_FILE_CONTENT } from "./util/dataMocks"
import { CCFile, BlacklistType, NodeType } from "./codeCharta.model"
import _ from "lodash"
import { StoreService } from "./state/store.service"
import { resetFiles } from "./state/store/files/files.actions"

describe("codeChartaService", () => {
let codeChartaService: CodeChartaService
let storeService: StoreService
let validFileContent
let fileStateService: FileStateService

beforeEach(() => {
restartSystem()
rebuildService()
validFileContent = _.cloneDeep(TEST_FILE_CONTENT)
storeService.dispatch(resetFiles())
})

function restartSystem() {
instantiateModule("app.codeCharta")
fileStateService = getService<FileStateService>("fileStateService")
storeService = getService<StoreService>("storeService")
}

function rebuildService() {
codeChartaService = new CodeChartaService(fileStateService)
codeChartaService = new CodeChartaService(storeService)
}

describe("loadFiles", () => {
Expand Down Expand Up @@ -65,34 +67,50 @@ describe("codeChartaService", () => {
path: "/root",
type: NodeType.FOLDER
},
settings: { fileSettings: { attributeTypes: { nodes: [], edges: [] }, blacklist: [], edges: [], markedPackages: [] } }
settings: {
fileSettings: {
attributeTypes: { nodes: [], edges: [] },
blacklist: [],
edges: [],
markedPackages: []
}
}
}

beforeEach(() => {
fileStateService.addFile = jest.fn()
fileStateService.setSingle = jest.fn()
})

function letTestFail() {
expect(true).toBeFalsy()
}

it("should load a file without edges", done => {
validFileContent.edges = undefined

codeChartaService.loadFiles([{ fileName: validFileContent.fileName, content: validFileContent }]).then(() => {
expect(fileStateService.addFile).toHaveBeenCalledWith(expected)
expect(fileStateService.setSingle).toHaveBeenCalled()
done()
})
codeChartaService
.loadFiles([
{
fileName: validFileContent.fileName,
content: validFileContent
}
])
.then(() => {
expect(storeService.getState().files.getCCFiles()[0]).toEqual(expected)
expect(storeService.getState().files.isSingleState()).toBeTruthy()
done()
})
})

it("should resolve valid file", done => {
codeChartaService.loadFiles([{ fileName: validFileContent.fileName, content: validFileContent }]).then(() => {
expect(fileStateService.addFile).toHaveBeenCalledWith(expected)
expect(fileStateService.setSingle).toHaveBeenCalled()
done()
})
codeChartaService
.loadFiles([
{
fileName: validFileContent.fileName,
content: validFileContent
}
])
.then(() => {
expect(storeService.getState().files.getCCFiles()[0]).toEqual(expected)
expect(storeService.getState().files.isSingleState()).toBeTruthy()
done()
})
})

it("should reject null", done => {
Expand Down Expand Up @@ -135,12 +153,18 @@ describe("codeChartaService", () => {
it("should convert old blacklist type", done => {
validFileContent.blacklist = [{ path: "foo", type: "hide" }]

codeChartaService.loadFiles([{ fileName: validFileContent.fileName, content: validFileContent }]).then(() => {
const expectedWithBlacklist = _.cloneDeep(expected)
expectedWithBlacklist.settings.fileSettings.blacklist = [{ path: "foo", type: BlacklistType.flatten }]
expect(fileStateService.addFile).toHaveBeenLastCalledWith(expectedWithBlacklist)
done()
})
codeChartaService
.loadFiles([
{
fileName: validFileContent.fileName,
content: validFileContent
}
])
.then(() => {
const blacklist = [{ path: "foo", type: BlacklistType.flatten }]
expect(storeService.getState().files.getCCFiles()[0].settings.fileSettings.blacklist).toEqual(blacklist)
done()
})
})
})
})
10 changes: 5 additions & 5 deletions visualization/app/codeCharta/codeCharta.service.ts
@@ -1,15 +1,16 @@
import { FileValidator } from "./util/fileValidator"
import { AttributeTypes, CCFile, NameDataPair, BlacklistType, BlacklistItem } from "./codeCharta.model"
import { FileStateService } from "./state/fileState.service"
import _ from "lodash"
import { NodeDecorator } from "./util/nodeDecorator"
import { StoreService } from "./state/store.service"
import { addFile, setSingle } from "./state/store/files/files.actions"

export class CodeChartaService {
public static ROOT_NAME = "root"
public static ROOT_PATH = "/" + CodeChartaService.ROOT_NAME
public static readonly CC_FILE_EXTENSION = ".cc.json"

constructor(private fileStateService: FileStateService) {}
constructor(private storeService: StoreService) {}

public loadFiles(nameDataPairs: NameDataPair[]): Promise<void> {
return new Promise((resolve, reject) => {
Expand All @@ -18,13 +19,12 @@ export class CodeChartaService {
if (errors.length === 0) {
const ccFile = this.getCCFile(nameDataPair.fileName, nameDataPair.content)
NodeDecorator.preDecorateFile(ccFile)
this.fileStateService.addFile(ccFile)
this.storeService.dispatch(addFile(ccFile))
} else {
reject(errors)
}
})

this.fileStateService.setSingle(this.fileStateService.getCCFiles()[0])
this.storeService.dispatch(setSingle(this.storeService.getState().files.getCCFiles()[0]))
resolve()
})
}
Expand Down