Skip to content

Commit

Permalink
Merge pull request #465 from iterative/add-new-decorations
Browse files Browse the repository at this point in the history
Update available tracked statuses
  • Loading branch information
mattseddon authored May 24, 2021
2 parents 5b05d53 + 4382741 commit a292c16
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
32 changes: 24 additions & 8 deletions extension/src/Repository/DecorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ import { isStringInEnum } from '../util'
export type DecorationState = Record<Status, Set<string>>

enum Status {
ADDED = 'added',
DELETED = 'deleted',
MODIFIED = 'modified',
NEW = 'new',
NOT_IN_CACHE = 'notInCache',
RENAMED = 'renamed',
STAGE_MODIFIED = 'stageModified',
TRACKED = 'tracked'
}

export class DecorationProvider implements FileDecorationProvider {
private static DecorationAdded: FileDecoration = {
badge: 'A',
color: new ThemeColor('gitDecoration.addedResourceForeground'),
tooltip: 'DVC added'
}

private static DecorationDeleted: FileDecoration = {
badge: 'D',
color: new ThemeColor('gitDecoration.deletedResourceForeground'),
Expand All @@ -34,18 +42,24 @@ export class DecorationProvider implements FileDecorationProvider {
tooltip: 'DVC modified'
}

private static DecorationNew: FileDecoration = {
badge: 'A',
color: new ThemeColor('gitDecoration.addedResourceForeground'),
tooltip: 'DVC added'
}

private static DecorationNotInCache: FileDecoration = {
badge: 'NC',
color: new ThemeColor('gitDecoration.renamedResourceForeground'),
tooltip: 'DVC not in cache'
}

private static DecorationRenamed: FileDecoration = {
badge: 'R',
color: new ThemeColor('gitDecoration.renamedResourceForeground'),
tooltip: 'DVC renamed'
}

private static DecorationStageModified: FileDecoration = {
badge: 'M',
color: new ThemeColor('gitDecoration.stageModifiedResourceForeground'),
tooltip: 'DVC staged modified'
}

private static DecorationTracked: FileDecoration = {
tooltip: 'DVC tracked'
}
Expand Down Expand Up @@ -86,9 +100,11 @@ export class DecorationProvider implements FileDecorationProvider {
}

private decorationMapping: Partial<Record<Status, FileDecoration>> = {
added: DecorationProvider.DecorationAdded,
deleted: DecorationProvider.DecorationDeleted,
modified: DecorationProvider.DecorationModified,
new: DecorationProvider.DecorationNew,
renamed: DecorationProvider.DecorationRenamed,
stageModified: DecorationProvider.DecorationStageModified,
notInCache: DecorationProvider.DecorationNotInCache
}

Expand Down
10 changes: 7 additions & 3 deletions extension/src/Repository/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export class RepositoryState

private dvcRoot: string

public added: Set<string> = new Set()
public deleted: Set<string> = new Set()
public modified: Set<string> = new Set()
public new: Set<string> = new Set()
public notInCache: Set<string> = new Set()
public renamed: Set<string> = new Set()
public stageModified: Set<string> = new Set()
public tracked: Set<string> = new Set()
public untracked: Set<string> = new Set()

Expand Down Expand Up @@ -80,9 +82,9 @@ export class RepositoryState
public updateStatus(statusOutput: StatusOutput) {
const status = this.reduceToChangedOutsStatuses(statusOutput)

this.added = new Set<string>()
this.modified = status.modified || new Set<string>()
this.deleted = status.deleted || new Set<string>()
this.new = status.new || new Set<string>()
this.notInCache = status['not in cache'] || new Set<string>()
}

Expand All @@ -103,10 +105,12 @@ export class RepositoryState

public getState() {
return {
added: this.added,
deleted: this.deleted,
modified: this.modified,
new: this.new,
notInCache: this.notInCache,
renamed: this.renamed,
stageModified: this.stageModified,
tracked: this.tracked,
untracked: this.untracked
}
Expand Down
16 changes: 10 additions & 6 deletions extension/src/Repository/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ beforeEach(() => {
describe('Repository', () => {
const dvcRoot = resolve(__dirname, '..', '..', 'demo')
const emptyState = new RepositoryState(dvcRoot).getState()
const emptySet = new Set<string>()

describe('ready', () => {
it('should wait for the state to be ready before resolving', async () => {
Expand Down Expand Up @@ -108,7 +109,6 @@ describe('Repository', () => {
resolve(dvcRoot, logDir),
resolve(dvcRoot, MNISTDataDir)
])
const emptySet = new Set()

const expectedExecutionOptions = {
cliPath: undefined,
Expand All @@ -124,10 +124,12 @@ describe('Repository', () => {

expect(repository.getState()).toEqual(
expect.objectContaining({
added: emptySet,
deleted: emptySet,
notInCache: emptySet,
new: emptySet,
modified,
renamed: emptySet,
stageModified: emptySet,
tracked,
untracked
})
Expand Down Expand Up @@ -170,8 +172,6 @@ describe('Repository', () => {
]
} as unknown) as StatusOutput)

const emptySet = new Set<string>()

mockedGetAllUntracked.mockResolvedValueOnce(emptySet)

mockedListDvcOnlyRecursive.mockResolvedValueOnce([
Expand Down Expand Up @@ -211,10 +211,12 @@ describe('Repository', () => {
)

expect(repository.getState()).toEqual({
added: emptySet,
deleted,
modified: emptySet,
new: emptySet,
notInCache: emptySet,
renamed: emptySet,
stageModified: emptySet,
tracked,
untracked: emptySet
})
Expand Down Expand Up @@ -309,9 +311,11 @@ describe('Repository', () => {
)

expect(repository.getState()).toEqual({
added: emptySet,
deleted,
modified,
new: new Set(),
renamed: emptySet,
stageModified: emptySet,
notInCache,
tracked,
untracked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ describe('SourceControlManagement', () => {
expect(sourceControlManagement.getState()).toEqual([])

const updatedState = ({
added: new Set(['/some/new/path']),
deleted: new Set(['/some/deleted/path', '/some/other/deleted/path']),
dispose: () => undefined,
new: new Set(['/some/new/path']),
tracked: new Set(['/some/excluded/tracked/path'])
} as unknown) as SourceControlManagementState

sourceControlManagement.setState(updatedState)

expect(sourceControlManagement.getState()).toEqual([
{ resourceUri: Uri.file('/some/new/path'), contextValue: 'added' },
{
resourceUri: Uri.file('/some/deleted/path'),
contextValue: 'deleted'
},
{
resourceUri: Uri.file('/some/other/deleted/path'),
contextValue: 'deleted'
},
{ resourceUri: Uri.file('/some/new/path'), contextValue: 'new' }
}
])

sourceControlManagement.setState(initialState)
Expand Down
4 changes: 3 additions & 1 deletion extension/src/Repository/views/SourceControlManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { isStringInEnum } from '../../util'
export type SourceControlManagementState = Record<Status, Set<string>>

enum Status {
ADDED = 'added',
DELETED = 'deleted',
MODIFIED = 'modified',
NEW = 'new',
NOT_IN_CACHE = 'notInCache',
RENAMED = 'renamed',
STAGE_MODIFIED = 'stageModified',
UNTRACKED = 'untracked'
}

Expand Down

0 comments on commit a292c16

Please sign in to comment.