-
Notifications
You must be signed in to change notification settings - Fork 21
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
UIE-21 Code Structure and Dependencies PoC #3834
Draft
msilva-broad
wants to merge
1
commit into
dev
Choose a base branch
from
msilva/UIE-21_code-structure_deps
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { analysisComponentDependencies } from 'src/dependencies/analysis/analysis-component-resolver' | ||
import { getDefaultAnalysisComponentDeps } from 'src/dependencies/analysis/analysis-component-resolver.defaults' | ||
import { analysisProviderDependencies } from 'src/dependencies/analysis/analysis-provider-resolver' | ||
import { getDefaultAnalysisProviderDeps } from 'src/dependencies/analysis/analysis-provider-resolver.defaults' | ||
import { analysisStateDependencies } from 'src/dependencies/analysis/analysis-state-resolver' | ||
import { getDefaultAnalysisStateDeps } from 'src/dependencies/analysis/analysis-state-resolver.defaults' | ||
import { componentDependencies } from 'src/dependencies/component-resolver' | ||
import { getDefaultComponentDeps } from 'src/dependencies/component-resolver.defaults' | ||
import { dataClientDependencies } from 'src/dependencies/data-client-resolver' | ||
import { getDefaultDataClientDeps } from 'src/dependencies/data-client-resolver.defaults' | ||
|
||
|
||
export const initAppDependencies = () => { | ||
dataClientDependencies.set(getDefaultDataClientDeps) | ||
componentDependencies.set(getDefaultComponentDeps) | ||
|
||
// Analysis dependencies | ||
analysisProviderDependencies.set(getDefaultAnalysisProviderDeps) | ||
analysisStateDependencies.set(getDefaultAnalysisStateDeps) | ||
analysisComponentDependencies.set(getDefaultAnalysisComponentDeps) | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/dependencies/analysis/analysis-component-resolver.defaults.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,10 @@ | ||
import { | ||
ExportAnalysisModal | ||
} from 'src/pages/workspaces/workspace/analysis/modals/ExportAnalysisModal/ExportAnalysisModal.component' | ||
|
||
import { AnalysisComponentDeps } from './analysis-component-resolver' | ||
|
||
|
||
export const getDefaultAnalysisComponentDeps = (): AnalysisComponentDeps => ({ | ||
ExportAnalysisModal: ExportAnalysisModal.resolve() | ||
}) |
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,10 @@ | ||
import { ComposedKey, createDependencyResolver } from '../dependency-core' | ||
|
||
|
||
type ExportAnalysisModalComponentExports = | ||
typeof import('src/pages/workspaces/workspace/analysis/modals/ExportAnalysisModal/ExportAnalysisModal.component') | ||
|
||
export type AnalysisComponentDeps = | ||
ComposedKey<ExportAnalysisModalComponentExports, 'ExportAnalysisModal'> | ||
|
||
export const analysisComponentDependencies = createDependencyResolver<AnalysisComponentDeps>() |
9 changes: 9 additions & 0 deletions
9
src/dependencies/analysis/analysis-provider-resolver.defaults.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,9 @@ | ||
import { AnalysisProviderDependencies } from 'src/dependencies/analysis/analysis-provider-resolver' | ||
import { AnalysisProvider } from 'src/libs/ajax/analysis-providers/AnalysisProvider' | ||
|
||
|
||
export const getDefaultAnalysisProviderDeps = (): AnalysisProviderDependencies => { | ||
return ({ | ||
AnalysisProvider: AnalysisProvider.resolve() | ||
}) | ||
} |
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,9 @@ | ||
import { ComposedKey, createDependencyResolver } from '../dependency-core' | ||
|
||
|
||
type AnalysisProviderExports = | ||
typeof import('src/libs/ajax/analysis-providers/AnalysisProvider') | ||
|
||
export type AnalysisProviderDependencies = ComposedKey<AnalysisProviderExports, 'AnalysisProvider'> | ||
|
||
export const analysisProviderDependencies = createDependencyResolver<AnalysisProviderDependencies>() |
11 changes: 11 additions & 0 deletions
11
src/dependencies/analysis/analysis-state-resolver.defaults.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 { | ||
useAnalysisExportState, | ||
} from 'src/pages/workspaces/workspace/analysis/modals/ExportAnalysisModal/ExportAnalysisModal.state' | ||
|
||
import { AnalysisStateDependencies } from './analysis-state-resolver' | ||
|
||
|
||
export const getDefaultAnalysisStateDeps = (): AnalysisStateDependencies => ({ | ||
useAnalysisExportState: useAnalysisExportState.resolve() | ||
}) | ||
|
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,10 @@ | ||
import { ComposedKey, createDependencyResolver } from '../dependency-core' | ||
|
||
|
||
type ExportAnalysisModalStateExports = | ||
typeof import('src/pages/workspaces/workspace/analysis/modals/ExportAnalysisModal/ExportAnalysisModal.state') | ||
|
||
export type AnalysisStateDependencies = | ||
ComposedKey<ExportAnalysisModalStateExports, 'useAnalysisExportState'> | ||
|
||
export const analysisStateDependencies = createDependencyResolver<AnalysisStateDependencies>() |
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,8 @@ | ||
import { ButtonPrimary, ButtonSecondary } from 'src/components/common' | ||
import { ComponentDependencies } from 'src/dependencies/component-resolver' | ||
|
||
|
||
export const getDefaultComponentDeps = (): ComponentDependencies => ({ | ||
ButtonPrimary, | ||
ButtonSecondary | ||
}) |
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,10 @@ | ||
import { createDependencyResolver, UnComposedKey } from 'src/dependencies/dependency-core' | ||
|
||
|
||
type CommonComponentsExports = typeof import('src/components/common') | ||
|
||
export type ComponentDependencies = | ||
UnComposedKey<CommonComponentsExports, 'ButtonPrimary'> & | ||
UnComposedKey<CommonComponentsExports, 'ButtonSecondary'> | ||
|
||
export const componentDependencies = createDependencyResolver<ComponentDependencies>() |
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,9 @@ | ||
import { DataClientDependencies } from 'src/dependencies/data-client-resolver' | ||
import { AzureStorage } from 'src/libs/ajax/AzureStorage' | ||
import { GoogleStorage } from 'src/libs/ajax/GoogleStorage' | ||
|
||
|
||
export const getDefaultDataClientDeps = (): DataClientDependencies => ({ | ||
GoogleStorage, | ||
AzureStorage | ||
}) |
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 { createDependencyResolver, UnComposedKey } from 'src/dependencies/dependency-core' | ||
|
||
|
||
type GoogleStorageExports = typeof import('src/libs/ajax/GoogleStorage') | ||
type AzureStorageExports = typeof import('src/libs/ajax/AzureStorage') | ||
|
||
export type DataClientDependencies = | ||
UnComposedKey<GoogleStorageExports, 'GoogleStorage'> & | ||
UnComposedKey<AzureStorageExports, 'AzureStorage'> | ||
|
||
export const dataClientDependencies = createDependencyResolver<DataClientDependencies>() |
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,80 @@ | ||
export interface DependencyResolver<Deps> { | ||
get: () => Deps | ||
set: (getDeps: () => Deps) => void | ||
override: (getOverrides: () => Partial<Deps>) => void | ||
reset: () => void | ||
} | ||
|
||
/** | ||
* Types a thing (typically the main export of a file) as requiring specific | ||
* late-binding dependencies (Deps) and participating in the | ||
* "Composable Dependency" DI-Container pattern. | ||
* [wiki link TBD] | ||
*/ | ||
export interface Composable<Deps, Output> { | ||
compose: (deps: Deps) => Output | ||
resolve: () => Output | ||
} | ||
|
||
/** | ||
* Utility type for the resolved Output type of a Composable<<Deps, Output>> type | ||
*/ | ||
export type Composed<C extends Composable<any, any>> = ReturnType<C['resolve']> | ||
|
||
/** | ||
* Utility type to safely specify an export by export name and have that be the | ||
* key name of a dependency collection item. Key names must exist as an export | ||
* of the same name. ComposedKey works with exports that satisfy the Composed | ||
* type signature, and will enforce this requirement. The dependency is typed | ||
* as the Output type of the Composed type signature. Dependency collections can be | ||
* specified using this and UnComposedKey utility types as needed: | ||
* @example | ||
* type XxxxExports = typeof import('path/to/Xxxx') | ||
* //... | ||
* export type SomeDependencies = | ||
* ComposedKey<XxxxExports, 'xName'> & | ||
* ComposedKey<YyyyExports, 'yName'> & | ||
* UncomposedKey<ZzzzExports, 'zName'> | ||
*/ | ||
export type ComposedKey<Exports, K extends string & keyof Exports> = Exports[K] extends Composable<any, any> | ||
? { [Property in K]: Composed<Exports[K]> } : never | ||
|
||
/** | ||
* Utility type to safely specify an export by export name and have that be the | ||
* key name of a dependency collection item. Key names must exist as an export of the same name. | ||
* The type signature of the named export will be the contract of the dependency. | ||
* Dependency collections can be specified using this and ComposedKey utitlity types as needed: | ||
* @example | ||
* type XxxxExports = typeof import('path/to/Xxxx') | ||
* //... | ||
* export type SomeDependencies = | ||
* ComposedKey<XxxxExports, 'xName'> & | ||
* ComposedKey<YyyyExports, 'yName'> & | ||
* UncomposedKey<ZzzzExports, 'zName'> | ||
*/ | ||
export type UnComposedKey<Exports, K extends string & keyof Exports> = | ||
{ [Property in K]: Exports[K] } | ||
|
||
|
||
export const createDependencyResolver = <Deps>(): DependencyResolver<Deps> => { | ||
const getNullDeps = (): Deps => { | ||
throw Error('Dependency Resolver not initialized.') | ||
} | ||
let getCurrentDeps: () => Deps = getNullDeps | ||
const resolver: DependencyResolver<Deps> = { | ||
get: () => getCurrentDeps(), | ||
set: (getDeps: () => Deps): void => { | ||
getCurrentDeps = getDeps | ||
}, | ||
override: (getOverrides: () => Partial<Deps>): void => { | ||
getCurrentDeps = () => ({ | ||
...getCurrentDeps(), | ||
...getOverrides() | ||
}) | ||
}, | ||
reset: () => { | ||
getCurrentDeps = getNullDeps | ||
} | ||
} | ||
return resolver | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { DataClientDependencies, dataClientDependencies } from 'src/dependencies/data-client-resolver' | ||
import { Composable } from 'src/dependencies/dependency-core' | ||
import { GoogleWorkspaceInfo, isGoogleWorkspaceInfo, WorkspaceInfo } from 'src/libs/workspace-utils' | ||
import { AnalysisFile, getExtension, stripExtension } from 'src/pages/workspaces/workspace/analysis/file-utils' | ||
import { ToolLabel } from 'src/pages/workspaces/workspace/analysis/tool-utils' | ||
|
||
|
||
export type AnalysisProviderDeps = { | ||
dataClients: Pick<DataClientDependencies, 'AzureStorage' | 'GoogleStorage'> | ||
} | ||
|
||
export interface AnalysisProviderContract { | ||
listAnalyses: (workspaceInfo: WorkspaceInfo, signal?: AbortSignal) => Promise<AnalysisFile[]> | ||
copyAnalysis: ( | ||
sourceWorkspace: WorkspaceInfo, | ||
printName: string, | ||
toolLabel: ToolLabel, | ||
targetWorkspace: WorkspaceInfo, | ||
newName: string, | ||
signal?: AbortSignal | ||
) => Promise<void> | ||
} | ||
|
||
export type ComposableAnalysisProvider = Composable<AnalysisProviderDeps, AnalysisProviderContract> | ||
|
||
export const AnalysisProvider: ComposableAnalysisProvider = { | ||
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. this provider is implemented in a pending PR for IA team, shown here to have an more robust example of the proposed UI stack. |
||
compose: (deps: AnalysisProviderDeps) => { | ||
const { AzureStorage, GoogleStorage } = deps.dataClients | ||
|
||
const provider: AnalysisProviderContract = { | ||
listAnalyses: async (workspaceInfo: WorkspaceInfo, signal?: AbortSignal): Promise<AnalysisFile[]> => { | ||
const selectedAnalyses: AnalysisFile[] = | ||
isGoogleWorkspaceInfo(workspaceInfo) ? | ||
await GoogleStorage(signal).listAnalyses(workspaceInfo.googleProject, workspaceInfo.bucketName) : | ||
// TODO: cleanup once TS is merged in for AzureStorage module | ||
(await AzureStorage(signal).listNotebooks(workspaceInfo.workspaceId) as any) | ||
return selectedAnalyses | ||
}, | ||
copyAnalysis: async ( | ||
sourceWorkspace: WorkspaceInfo, | ||
printName: string, | ||
toolLabel: ToolLabel, | ||
targetWorkspace: WorkspaceInfo, | ||
newName: string, | ||
signal?: AbortSignal | ||
): Promise<void> => { | ||
if (isGoogleWorkspaceInfo(sourceWorkspace)) { | ||
await GoogleStorage() | ||
.analysis(sourceWorkspace.googleProject, sourceWorkspace.bucketName, printName, toolLabel) | ||
// assumes GCP to GCP copy | ||
.copy(`${newName}.${getExtension(printName)}`, (targetWorkspace as GoogleWorkspaceInfo).bucketName, false) | ||
} else { | ||
await AzureStorage(signal) | ||
.blob(sourceWorkspace.workspaceId, printName) | ||
.copy(stripExtension(newName), targetWorkspace.workspaceId) | ||
} | ||
} | ||
} | ||
return provider | ||
}, | ||
resolve: () => AnalysisProvider.compose({ dataClients: dataClientDependencies.get() }) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minimal conversion of ajax.js to .ts is not central to the DI patterns. I did this just to avoid type anoyances/polution of the core code bits elsewhere.