-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Intermediate component between simple list and full list - Supply as little config as simple list, all of full list or anywhere in between
- Loading branch information
1 parent
fb3db1e
commit 247f2de
Showing
17 changed files
with
510 additions
and
86 deletions.
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
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
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
59 changes: 59 additions & 0 deletions
59
src/frontend/packages/core/src/shared/components/list/defaults-list/defaults-datasource.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,59 @@ | ||
import { Store } from '@ngrx/store'; | ||
|
||
import { isPaginatedAction, PaginatedAction } from '../../../../../../store/src/types/pagination.types'; | ||
import { StratosBaseCatalogueEntity } from '../../../../core/entity-catalogue/entity-catalogue-entity'; | ||
import { entityCatalogue } from '../../../../core/entity-catalogue/entity-catalogue.service'; | ||
import { EntityCatalogueEntityConfig } from '../../../../core/entity-catalogue/entity-catalogue.types'; | ||
import { ListDataSource } from '../data-sources-controllers/list-data-source'; | ||
import { IListDataSourceConfig } from '../data-sources-controllers/list-data-source-config'; | ||
import { IListConfig } from '../list.component.types'; | ||
|
||
export type ListDefaultsActionOrConfig = PaginatedAction | ListDefaultsConfig; | ||
|
||
export interface ListDefaultsConfig { | ||
entityConfig: EntityCatalogueEntityConfig; | ||
endpointGuid?: string; | ||
paginationKey?: string; | ||
extraArgs?: Record<any, any>; | ||
} | ||
|
||
function actionFromConfig(config: ListDefaultsConfig): PaginatedAction { | ||
const catalogueEntity = entityCatalogue.getEntity(config.entityConfig); | ||
const getAllActionBuilder = catalogueEntity.actionOrchestrator.getActionBuilder('getMultiple'); | ||
if (!getAllActionBuilder) { | ||
throw Error(`List Error: ${catalogueEntity.entityKey} has no action builder for the getMultiple action.`); | ||
} | ||
return getAllActionBuilder(config.endpointGuid, config.paginationKey, config.extraArgs); | ||
} | ||
|
||
export function createListActionFromActionOrConfig(actionOrConfig: ListDefaultsActionOrConfig): { | ||
action: PaginatedAction, | ||
catalogueEntity: StratosBaseCatalogueEntity | ||
} { | ||
const action = isPaginatedAction(actionOrConfig) || actionFromConfig(actionOrConfig as ListDefaultsConfig); | ||
const catalogueEntity = entityCatalogue.getEntity(action); | ||
return { | ||
action, | ||
catalogueEntity | ||
}; | ||
} | ||
|
||
export class ListDefaultsDataSource<A, T> extends ListDataSource<T, A> { | ||
|
||
constructor(actionOrConfig: ListDefaultsActionOrConfig, | ||
listConfig: IListConfig<T>, | ||
store: Store<any>, | ||
dataSourceConfig?: Partial<IListDataSourceConfig<A, T>>, ) { | ||
const { action, catalogueEntity } = createListActionFromActionOrConfig(actionOrConfig); | ||
super({ | ||
store, | ||
action, | ||
paginationKey: action.paginationKey, | ||
schema: catalogueEntity.getSchema(action.schemaKey), | ||
getRowUniqueId: entity => catalogueEntity.getGuidFromEntity(entity), | ||
listConfig, | ||
isLocal: true, // assume true unless overwritten | ||
...dataSourceConfig | ||
}); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/frontend/packages/core/src/shared/components/list/defaults-list/defaults-list-config.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,67 @@ | ||
import { Store } from '@ngrx/store'; | ||
|
||
import { IListDataSourceConfig } from '../data-sources-controllers/list-data-source-config'; | ||
import { IListConfig } from '../list.component.types'; | ||
import { CatalogueEntityDrivenListConfig } from '../simple-list/entity-catalogue-list-config'; | ||
import { | ||
createListActionFromActionOrConfig, | ||
ListDefaultsActionOrConfig, | ||
ListDefaultsDataSource as ListDefaultsDataSource, | ||
} from './defaults-datasource'; | ||
|
||
function createListConfig<A, T>( | ||
actionOrConfig?: ListDefaultsActionOrConfig, | ||
listConfig?: Partial<IListConfig<T>> | ||
) { | ||
if (actionOrConfig) { | ||
const { catalogueEntity } = createListActionFromActionOrConfig(actionOrConfig); | ||
return { | ||
...new CatalogueEntityDrivenListConfig<T>(catalogueEntity), | ||
...listConfig | ||
}; | ||
} else if (listConfig) { | ||
// Going on the assumption that the list is not a partial if used in this way | ||
return listConfig as IListConfig<T>; | ||
} else { | ||
throw Error(`Either \`actionOrConfig\` or \`listConfig\` must be supplied when creating a defaults list`); | ||
} | ||
} | ||
|
||
function createDataSource<A, T>( | ||
store: Store<any>, | ||
listConfig: IListConfig<T>, | ||
actionOrConfig?: ListDefaultsActionOrConfig, | ||
dataSourceConfig?: Partial<IListDataSourceConfig<A, T>>, | ||
) { | ||
const existingDs = listConfig.getDataSource ? listConfig.getDataSource() : null; | ||
return existingDs || new ListDefaultsDataSource<A, T>( | ||
actionOrConfig, | ||
listConfig, | ||
store, | ||
dataSourceConfig | ||
); | ||
} | ||
|
||
|
||
export function createListDefaultConfig<A, T>( | ||
store: Store<any>, | ||
actionOrConfig?: ListDefaultsActionOrConfig, | ||
listConfig?: Partial<IListConfig<T>>, | ||
dataSourceConfig?: Partial<IListDataSourceConfig<A, T>>, | ||
): IListConfig<T> { | ||
|
||
const newListConfig = createListConfig<A, T>( | ||
actionOrConfig, | ||
listConfig, | ||
); | ||
|
||
const ds = createDataSource( | ||
store, | ||
newListConfig, | ||
actionOrConfig, | ||
dataSourceConfig | ||
); | ||
newListConfig.getDataSource = () => ds; | ||
|
||
return newListConfig; | ||
} |
1 change: 1 addition & 0 deletions
1
...ntend/packages/core/src/shared/components/list/defaults-list/defaults-list.component.html
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 @@ | ||
<ng-template list-host></ng-template> |
Empty file.
Oops, something went wrong.