-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge refs/heads/master into christjt/BND3D-5419
- Loading branch information
Showing
13 changed files
with
189 additions
and
102 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
42 changes: 42 additions & 0 deletions
42
react-components/src/architecture/base/commands/factory/ToolbarFactory.test.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,42 @@ | ||
/*! | ||
* Copyright 2025 Cognite AS | ||
*/ | ||
|
||
import { describe, expect, test, beforeAll } from 'vitest'; | ||
import { hasToolbar, getToolbar, installToolbar } from './ToolbarFactory'; | ||
import { BaseTool } from '../BaseTool'; | ||
import { BaseCommand } from '../BaseCommand'; | ||
|
||
describe('ToolbarFactory', () => { | ||
beforeAll(() => { | ||
installToolbar(FooTool, [new FooCommand(), new FooCommand()]); | ||
}); | ||
|
||
test('should test has a toolbar', () => { | ||
const tool = new FooTool(); | ||
expect(hasToolbar(tool)).toBe(true); | ||
}); | ||
|
||
test('should test has not a toolbar', () => { | ||
const tool = new BarTool(); | ||
expect(hasToolbar(tool)).toBe(false); | ||
}); | ||
|
||
test('should test get toolbar', () => { | ||
const tool = new FooTool(); | ||
const toolBar = getToolbar(tool); | ||
expect(toolBar).not.toBe(undefined); | ||
if (toolBar !== undefined) { | ||
expect(toolBar.length).toEqual(2); | ||
} | ||
}); | ||
|
||
test('should test can not get toolbar', () => { | ||
const tool = new BarTool(); | ||
expect(getToolbar(tool)).toBe(undefined); | ||
}); | ||
}); | ||
|
||
class FooTool extends BaseTool {} | ||
class BarTool extends BaseTool {} | ||
class FooCommand extends BaseCommand {} |
47 changes: 47 additions & 0 deletions
47
react-components/src/architecture/base/commands/factory/ToolbarFactory.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,47 @@ | ||
/*! | ||
* Copyright 2025 Cognite AS | ||
*/ | ||
|
||
import { type Class } from '../../domainObjectsHelpers/Class'; | ||
import { type BaseCommand } from '../BaseCommand'; | ||
import { type BaseTool } from '../BaseTool'; | ||
|
||
export type Toolbar = Array<BaseCommand | undefined>; | ||
|
||
/** | ||
* Determines if a toolbar can be created for the given tool. | ||
* | ||
* @param tool - The tool to check. | ||
* @returns `true` if a toolbar can be created, otherwise `false`. | ||
*/ | ||
export function hasToolbar(tool: BaseTool): boolean { | ||
const toolType = getClassOf(tool); | ||
return _toolbar.has(toolType); | ||
} | ||
|
||
/** | ||
* Creates a toolbar for the given tool. | ||
* | ||
* @param tool - The tool which the toolbar is to be created. | ||
* @returns A toolbar if creation is successful, otherwise undefined. | ||
*/ | ||
export function getToolbar(tool: BaseTool): Toolbar | undefined { | ||
const toolType = getClassOf(tool); | ||
return _toolbar.get(toolType); | ||
} | ||
|
||
/** | ||
* Installs a toolbar creator for a given tool. | ||
* | ||
* @param toolType - The class of the tool for which the toolbar creator is being installed. | ||
* @param creator - The toolbar creator to be installed. | ||
*/ | ||
export function installToolbar(toolType: Class<BaseTool>, toolbar: Toolbar): void { | ||
_toolbar.set(toolType, toolbar); | ||
} | ||
|
||
const _toolbar = new Map<Class<BaseTool>, Toolbar>(); | ||
|
||
function getClassOf(tool: BaseTool): Class<BaseTool> { | ||
return tool.constructor as Class<BaseTool>; | ||
} |
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
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
Oops, something went wrong.