Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Base vcs redux center (state / actions / reducer) #68

Merged
merged 3 commits into from Nov 8, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/browser/app/app.component.ts
Expand Up @@ -6,6 +6,7 @@ import { NoteFinderComponent } from '../note/note-collection';
import { NoteCollectionService } from '../note/note-collection/note-collection.service';
import { WORKSPACE_DATABASE, WorkspaceDatabase } from '../shared';
import { Themes, ThemeService } from '../ui/style';
import { VcsManagerComponent } from '../vcs/vcs-view';
import { AppLayoutSidenavOutlet } from './app-layout';
import { AppStateWithFeatures } from './app.state';

Expand All @@ -25,6 +26,14 @@ export class AppComponent implements OnInit {
description: 'Notes (⌘+1)',
outletComponent: NoteFinderComponent,
},
{
id: 'gd-vcs-manager',
name: 'Version Control',
iconName: 'git',
shortcut: '',
description: 'Version Control (⌘+2)',
outletComponent: VcsManagerComponent,
},
];

readonly noteContentLoaded: Observable<boolean> = this.store.pipe(
Expand Down
2 changes: 2 additions & 0 deletions src/browser/app/app.module.ts
Expand Up @@ -6,6 +6,7 @@ import { StoreModule } from '@ngrx/store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { NoteModule } from '../note';
import { UiModule } from '../ui/ui.module';
import { VcsModule } from '../vcs';
import { AppLayoutModule } from './app-layout';
import { AppComponent } from './app.component';
import { appReducer } from './app.reducer';
Expand All @@ -21,6 +22,7 @@ import { appReducer } from './app.reducer';
EffectsModule.forRoot([]),
AppLayoutModule,
NoteModule,
VcsModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
Expand Down
39 changes: 39 additions & 0 deletions src/browser/vcs/dummies.ts
@@ -0,0 +1,39 @@
import * as path from 'path';
import { Dummy, TextDummy, TypesDummy } from '../../../test/helpers';
import { VcsFileChange, VcsFileChangeStatusTypes } from '../../core/vcs';


export class VcsFileChangeDummy implements Dummy<VcsFileChange> {
private filePath = new TextDummy('file');
private status = new TypesDummy<VcsFileChangeStatusTypes>([
VcsFileChangeStatusTypes.REMOVED,
VcsFileChangeStatusTypes.MODIFIED,
VcsFileChangeStatusTypes.RENAMED,
VcsFileChangeStatusTypes.NEW,
]);

constructor(public readonly workspaceDir: string = '/test/workspace') {
}

create(status = this.status.create()): VcsFileChange {
const filePath = this.filePath.create();
let fileChange = {
filePath,
workingDirectoryPath: this.workspaceDir,
absoluteFilePath: path.resolve(this.workspaceDir, filePath),
status,
} as VcsFileChange;

if (status === VcsFileChangeStatusTypes.RENAMED) {
fileChange = {
...fileChange,
headToIndexDiff: {
oldFilePath: 'old-file',
newFilePath: filePath,
},
};
}

return fileChange;
}
}
3 changes: 3 additions & 0 deletions src/browser/vcs/index.ts
@@ -1,3 +1,6 @@
export * from './vcs.module';
export * from './vcs.service';
export * from './vcs-authentication-database';
export * from './vcs.state';
export * from './vcs.actions';
export * from './vcs.reducer';
2 changes: 2 additions & 0 deletions src/browser/vcs/vcs-view/index.ts
@@ -0,0 +1,2 @@
export * from './vcs-view.module';
export * from './vcs-manager/vcs-manager.component';
@@ -0,0 +1,2 @@
<div class="VcsManager">
</div>
@@ -0,0 +1,2 @@
.VcsManager {
}
17 changes: 17 additions & 0 deletions src/browser/vcs/vcs-view/vcs-manager/vcs-manager.component.ts
@@ -0,0 +1,17 @@
import { Component, OnInit } from '@angular/core';


@Component({
selector: 'gd-vcs-manager',
templateUrl: './vcs-manager.component.html',
styleUrls: ['./vcs-manager.component.scss'],
})
export class VcsManagerComponent implements OnInit {

constructor() {
}

ngOnInit() {
}

}
21 changes: 21 additions & 0 deletions src/browser/vcs/vcs-view/vcs-view.module.ts
@@ -0,0 +1,21 @@
import { NgModule } from '@angular/core';
import { UiModule } from '../../ui/ui.module';
import { VcsManagerComponent } from './vcs-manager/vcs-manager.component';


@NgModule({
imports: [
UiModule,
],
declarations: [
VcsManagerComponent,
],
entryComponents: [
VcsManagerComponent,
],
exports: [
VcsManagerComponent,
],
})
export class VcsViewModule {
}
19 changes: 19 additions & 0 deletions src/browser/vcs/vcs.actions.ts
@@ -0,0 +1,19 @@
import { Action } from '@ngrx/store';
import { VcsFileChange } from '../../core/vcs';


export enum VcsActionTypes {
UPDATE_FILE_CHANGES = '[Vcs] Update file changes',
}


export class UpdateFileChangesAction implements Action {
readonly type = VcsActionTypes.UPDATE_FILE_CHANGES;

constructor(public readonly payload: { fileChanges: VcsFileChange[] }) {
}
}


export type VcsAction =
UpdateFileChangesAction;
6 changes: 6 additions & 0 deletions src/browser/vcs/vcs.module.ts
@@ -1,19 +1,25 @@
import { NgModule } from '@angular/core';
import { StoreModule } from '@ngrx/store';
import { VcsAuthenticationDatabaseProvider } from './vcs-authentication-database';
import { VcsRemoteModule } from './vcs-remote';
import { VcsViewModule } from './vcs-view';
import { vcsReducerMap } from './vcs.reducer';
import { VcsService } from './vcs.service';


@NgModule({
imports: [
VcsRemoteModule,
VcsViewModule,
StoreModule.forFeature('vcs', vcsReducerMap),
],
providers: [
VcsAuthenticationDatabaseProvider,
VcsService,
],
exports: [
VcsRemoteModule,
VcsViewModule,
],
})
export class VcsModule {
Expand Down
20 changes: 20 additions & 0 deletions src/browser/vcs/vcs.reducer.spec.ts
@@ -0,0 +1,20 @@
import { createDummies } from '../../../test/helpers';
import { VcsFileChangeDummy } from './dummies';
import { UpdateFileChangesAction } from './vcs.actions';
import { vcsReducer } from './vcs.reducer';


describe('browser.vcs.vcsReducer', () => {
const fileChangeDummy = new VcsFileChangeDummy();

describe('UPDATE_FILE_CHANGES', () => {
it('should set file changes.', () => {
const fileChanges = createDummies(fileChangeDummy, 10);
const action = new UpdateFileChangesAction({ fileChanges });

const result = vcsReducer(undefined, action);

expect(result.fileChanges).toEqual(fileChanges);
});
});
});
24 changes: 24 additions & 0 deletions src/browser/vcs/vcs.reducer.ts
@@ -0,0 +1,24 @@
import { ActionReducerMap } from '@ngrx/store';
import { VcsAction, VcsActionTypes } from './vcs.actions';
import { createVcsInitialState, VcsState, VcsStateWithRoot } from './vcs.state';


export function vcsReducer(
state: VcsState = createVcsInitialState(),
action: VcsAction,
): VcsState {
switch (action.type) {
case VcsActionTypes.UPDATE_FILE_CHANGES:
return {
...state,
fileChanges: [...action.payload.fileChanges],
};
default:
return state;
}
}


export const vcsReducerMap: ActionReducerMap<VcsStateWithRoot> = {
vcs: vcsReducer,
};
18 changes: 18 additions & 0 deletions src/browser/vcs/vcs.state.ts
@@ -0,0 +1,18 @@
import { VcsFileChange } from '../../core/vcs';


export function createVcsInitialState(): VcsState {
return {
fileChanges: [],
};
}


export interface VcsState {
readonly fileChanges: VcsFileChange[];
}


export interface VcsStateWithRoot {
vcs: VcsState;
}