Adds appendConditions to allow adding multiple in one go
This commit is contained in:
committed by
Niels Lyngsø
parent
ac5d7f2d84
commit
3b0ba436ff
@@ -533,4 +533,24 @@ describe('Append Conditions', () => {
|
||||
const updatedWorkspaceExt = extensionRegistry.getByAlias('Umb.Test.Section.2') as ManifestWithDynamicConditions;
|
||||
expect(updatedWorkspaceExt.conditions?.length).to.equal(1);
|
||||
});
|
||||
|
||||
it('allows an extension to update with multiple conditions', () => {
|
||||
const ext = extensionRegistry.getByAlias('Umb.Test.Section.1') as ManifestWithDynamicConditions;
|
||||
expect(ext.conditions?.length).to.equal(1);
|
||||
|
||||
const conditions:Array<UmbConditionConfigBase> = [
|
||||
{
|
||||
alias: 'Umb.Test.Condition.Valid'
|
||||
},
|
||||
{
|
||||
alias: 'Umb.Condition.WorkspaceAlias',
|
||||
match: 'Umb.Workspace.Document'
|
||||
} as WorkspaceAliasConditionConfig
|
||||
]
|
||||
|
||||
extensionRegistry.appendConditions('Umb.Test.Section.1', conditions);
|
||||
|
||||
const extUpdated = extensionRegistry.getByAlias('Umb.Test.Section.1') as ManifestWithDynamicConditions;
|
||||
expect(ext.conditions?.length).to.equal(3);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -440,7 +440,7 @@ export class UmbExtensionRegistry<
|
||||
* Useful to add a condition for example the Save And Publish workspace action shipped by core
|
||||
* As overwriting the whole extension to simply add an extra condition is not ideal as it causes a lot of duplicated code
|
||||
* and could easily get out of sync from the CMS core implementation if a 3rd party dev was to try and overwrite it
|
||||
* @param alias {string} - The alias of the extension to get.
|
||||
* @param alias {string} - The alias of the extension to append the condition to
|
||||
* @param newCondition {UmbConditionConfigBase} - The condition to append to the extension.
|
||||
*/
|
||||
appendCondition(alias: string, newCondition: UmbConditionConfigBase) {
|
||||
@@ -461,4 +461,13 @@ export class UmbExtensionRegistry<
|
||||
// Update the extensions observable
|
||||
this._extensions.setValue(allExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a collection of conditions to an exsiting extension
|
||||
* @param alias {string} - The alias of the extension to append the condition to
|
||||
* @param newConditions {Array<UmbConditionConfigBase>} - A collection of conditions to append to an extension.
|
||||
*/
|
||||
appendConditions(alias: string, newConditions: Array<UmbConditionConfigBase>){
|
||||
newConditions.forEach((condition) => this.appendCondition(alias, condition));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user