-
Notifications
You must be signed in to change notification settings - Fork 226
Update the format of selected state and propagate it to the treeview #1817
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,14 @@ export type LocalDbItem = LocalListDbItem | LocalDatabaseDbItem; | |
|
|
||
| export interface LocalListDbItem { | ||
| kind: DbItemKind.LocalList; | ||
| selected: boolean; | ||
| listName: string; | ||
| databases: LocalDatabaseDbItem[]; | ||
| } | ||
|
|
||
| export interface LocalDatabaseDbItem { | ||
| kind: DbItemKind.LocalDatabase; | ||
| selected: boolean; | ||
| databaseName: string; | ||
| dateAdded: number; | ||
| language: string; | ||
|
|
@@ -51,23 +53,74 @@ export type RemoteDbItem = | |
|
|
||
| export interface RemoteSystemDefinedListDbItem { | ||
| kind: DbItemKind.RemoteSystemDefinedList; | ||
| selected: boolean; | ||
| listName: string; | ||
| listDisplayName: string; | ||
| listDescription: string; | ||
| } | ||
|
|
||
| export interface RemoteUserDefinedListDbItem { | ||
| kind: DbItemKind.RemoteUserDefinedList; | ||
| selected: boolean; | ||
| listName: string; | ||
| repos: RemoteRepoDbItem[]; | ||
| } | ||
|
|
||
| export interface RemoteOwnerDbItem { | ||
| kind: DbItemKind.RemoteOwner; | ||
| selected: boolean; | ||
| ownerName: string; | ||
| } | ||
|
|
||
| export interface RemoteRepoDbItem { | ||
| kind: DbItemKind.RemoteRepo; | ||
| selected: boolean; | ||
| repoFullName: string; | ||
| } | ||
|
|
||
| export function isRemoteSystemDefinedListDbItem( | ||
| dbItem: DbItem, | ||
| ): dbItem is RemoteSystemDefinedListDbItem { | ||
| return dbItem.kind === DbItemKind.RemoteSystemDefinedList; | ||
| } | ||
|
|
||
| export function isRemoteUserDefinedListDbItem( | ||
| dbItem: DbItem, | ||
| ): dbItem is RemoteUserDefinedListDbItem { | ||
| return dbItem.kind === DbItemKind.RemoteUserDefinedList; | ||
| } | ||
|
|
||
| export function isRemoteOwnerDbItem( | ||
| dbItem: DbItem, | ||
| ): dbItem is RemoteOwnerDbItem { | ||
| return dbItem.kind === DbItemKind.RemoteOwner; | ||
| } | ||
|
|
||
| export function isRemoteRepoDbItem(dbItem: DbItem): dbItem is RemoteRepoDbItem { | ||
| return dbItem.kind === DbItemKind.RemoteRepo; | ||
| } | ||
|
|
||
| export function isLocalListDbItem(dbItem: DbItem): dbItem is LocalListDbItem { | ||
| return dbItem.kind === DbItemKind.LocalList; | ||
| } | ||
|
|
||
| export function isLocalDatabaseDbItem( | ||
| dbItem: DbItem, | ||
| ): dbItem is LocalDatabaseDbItem { | ||
| return dbItem.kind === DbItemKind.LocalDatabase; | ||
| } | ||
|
Comment on lines
+81
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These 30 lines are only created for tests. Isn't that a huge code smell? Can't we solve the problem differently? The two
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can definitely solve this differently - it requires checking the We could move the code somewhere else too since it's just for tests but I think that would make it harder to find and much more likely for this code to get duplicated elsewhere. We could also only implement what is needed (and don't include the type guards for local dbs) but to me that feels incomplete. And despite this being 30 LoC, it's 30 lines of straight-forward code. So in general I think you have the right reactions seeing this code, but I think this is a case where it's ok to break the "rules" a bit. And the db-item module comes with a more complete interface. |
||
|
|
||
| export type SelectableDbItem = RemoteDbItem | LocalDbItem; | ||
|
|
||
| export function isSelectableDbItem(dbItem: DbItem): dbItem is SelectableDbItem { | ||
| return SelectableDbItemKinds.includes(dbItem.kind); | ||
| } | ||
|
|
||
| const SelectableDbItemKinds = [ | ||
| DbItemKind.LocalList, | ||
| DbItemKind.LocalDatabase, | ||
| DbItemKind.RemoteSystemDefinedList, | ||
| DbItemKind.RemoteUserDefinedList, | ||
| DbItemKind.RemoteOwner, | ||
| DbItemKind.RemoteRepo, | ||
| ]; | ||
Uh oh!
There was an error while loading. Please reload this page.