-
Notifications
You must be signed in to change notification settings - Fork 20
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
fix(react-components): Fix PointCloudFilterCommand because it didn't show up in Search #4703
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e39756
Initial commit
nilscognite 6370662
Fix styling
nilscognite 954fa0b
Fixed minor things
nilscognite aa0a10b
Update BaseFilterCommand.ts
nilscognite d4a122e
Update Transaction.ts
nilscognite 3f66667
Make static
nilscognite b96066d
Smaller fixes
nilscognite 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
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 |
---|---|---|
|
@@ -10,6 +10,11 @@ import { CommandsUpdater } from '../reactUpdaters/CommandsUpdater'; | |
import { type RevealRenderTarget } from '../renderTarget/RevealRenderTarget'; | ||
|
||
export class PointCloudFilterCommand extends BaseFilterCommand { | ||
// ================================================== | ||
// INSTANCE FIELDS | ||
// ================================================== | ||
|
||
private _modelId: number | undefined = undefined; | ||
private _revisionId: number | undefined = undefined; | ||
|
||
// ================================================== | ||
|
@@ -21,30 +26,28 @@ export class PointCloudFilterCommand extends BaseFilterCommand { | |
} | ||
|
||
public override get isEnabled(): boolean { | ||
const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); | ||
if (pointCloud === undefined) { | ||
return false; | ||
} | ||
return true; | ||
return this.getPointCloud() !== undefined; | ||
} | ||
|
||
public override initializeChildrenIfNeeded(): void { | ||
const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); | ||
if (pointCloud === undefined) { | ||
this._children = undefined; | ||
this._modelId = undefined; | ||
this._revisionId = undefined; | ||
return; | ||
} | ||
if (this._revisionId === pointCloud.revisionId) { | ||
return; | ||
if (this._modelId === pointCloud.modelId && this._revisionId === pointCloud.revisionId) { | ||
return; // Nothing changed | ||
} | ||
this._modelId = pointCloud.modelId; | ||
this._revisionId = pointCloud.revisionId; | ||
this._children = undefined; | ||
super.initializeChildrenIfNeeded(); | ||
} | ||
|
||
protected createChildren(): FilterItemCommand[] { | ||
const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); | ||
protected override createChildren(): FilterItemCommand[] { | ||
const pointCloud = this.getPointCloud(); | ||
if (pointCloud === undefined) { | ||
return []; | ||
} | ||
|
@@ -55,25 +58,25 @@ export class PointCloudFilterCommand extends BaseFilterCommand { | |
const children = []; | ||
for (const c of classes) { | ||
const pointClass = new PointClass(c.name, c.code, c.color); | ||
children.push(new FilterItemCommand(pointClass)); | ||
children.push(new FilterItemCommand(pointClass, pointCloud.modelId, pointCloud.revisionId)); | ||
} | ||
return children; | ||
} | ||
|
||
public override get isAllChecked(): boolean { | ||
const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); | ||
const pointCloud = this.getPointCloud(); | ||
if (pointCloud === undefined) { | ||
return false; | ||
} | ||
return isClassesVisible(pointCloud); | ||
return isAllClassesVisible(pointCloud); | ||
} | ||
|
||
public override toggleAllChecked(): void { | ||
const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); | ||
const pointCloud = this.getPointCloud(); | ||
if (pointCloud === undefined) { | ||
return; | ||
} | ||
const isAllChecked = isClassesVisible(pointCloud); | ||
const isAllChecked = isAllClassesVisible(pointCloud); | ||
const classes = pointCloud.getClasses(); | ||
if (classes === undefined || classes.length === 0) { | ||
return; | ||
|
@@ -82,19 +85,39 @@ export class PointCloudFilterCommand extends BaseFilterCommand { | |
pointCloud.setClassVisible(c.code, !isAllChecked); | ||
} | ||
} | ||
|
||
// ================================================== | ||
// INSTANCE METHODS | ||
// ================================================== | ||
|
||
private getPointCloud(): CognitePointCloudModel | undefined { | ||
if (this._modelId === undefined || this._revisionId === undefined) { | ||
return undefined; | ||
} | ||
for (const pointCloud of this.renderTarget.getPointClouds()) { | ||
if (this._modelId === pointCloud.modelId && this._revisionId === pointCloud.revisionId) { | ||
return pointCloud; | ||
} | ||
} | ||
return undefined; | ||
} | ||
} | ||
|
||
// Note: This is not exported, as it is only used internally | ||
|
||
class FilterItemCommand extends BaseFilterItemCommand { | ||
private readonly _modelId: number; | ||
private readonly _revisionId: number; | ||
private readonly _pointClass: PointClass; | ||
|
||
// ================================================== | ||
// CONSTRUCTOR | ||
// ================================================== | ||
|
||
public constructor(pointClass: PointClass) { | ||
public constructor(pointClass: PointClass, modelId: number, revisionId: number) { | ||
super(); | ||
this._modelId = modelId; | ||
this._revisionId = revisionId; | ||
this._pointClass = pointClass; | ||
} | ||
|
||
|
@@ -107,15 +130,15 @@ class FilterItemCommand extends BaseFilterItemCommand { | |
} | ||
|
||
public override get isChecked(): boolean { | ||
const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); | ||
const pointCloud = this.getPointCloud(); | ||
if (pointCloud === undefined) { | ||
return false; | ||
} | ||
return pointCloud.isClassVisible(this._pointClass.code); | ||
} | ||
|
||
public override invokeCore(): boolean { | ||
const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); | ||
const pointCloud = this.getPointCloud(); | ||
if (pointCloud === undefined) { | ||
return false; | ||
} | ||
|
@@ -128,14 +151,27 @@ class FilterItemCommand extends BaseFilterItemCommand { | |
return this._pointClass.color; | ||
} | ||
|
||
public setChecked(value: boolean): void { | ||
const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); | ||
public override setChecked(value: boolean): void { | ||
const pointCloud = this.getPointCloud(); | ||
if (pointCloud === undefined) { | ||
return; | ||
} | ||
pointCloud.setClassVisible(this._pointClass.code, value); | ||
CommandsUpdater.update(this._renderTarget); | ||
} | ||
|
||
// ================================================== | ||
// INSTANCE METHODS | ||
// ================================================== | ||
|
||
private getPointCloud(): CognitePointCloudModel | undefined { | ||
for (const pointCloud of this.renderTarget.getPointClouds()) { | ||
if (this._modelId === pointCloud.modelId && this._revisionId === pointCloud.revisionId) { | ||
return pointCloud; | ||
} | ||
} | ||
return undefined; | ||
Comment on lines
+168
to
+173
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 could also be written with |
||
} | ||
} | ||
|
||
class PointClass { | ||
|
@@ -161,6 +197,10 @@ class PointClass { | |
} | ||
} | ||
|
||
// ================================================== | ||
// PRIVATE FUNCTIONS | ||
// ================================================== | ||
|
||
function getFirstPointCloudWithClasses( | ||
renderTarget: RevealRenderTarget | ||
): CognitePointCloudModel | undefined { | ||
|
@@ -169,11 +209,12 @@ function getFirstPointCloudWithClasses( | |
if (classes === undefined || classes.length === 0) { | ||
continue; | ||
} | ||
return pointCloud; | ||
} | ||
return undefined; | ||
} | ||
|
||
function isClassesVisible(pointCloud: CognitePointCloudModel): boolean { | ||
function isAllClassesVisible(pointCloud: CognitePointCloudModel): boolean { | ||
const classes = pointCloud.getClasses(); | ||
if (classes === undefined || classes.length === 0) { | ||
return false; | ||
|
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.
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.
This function could be rewritten as
return this.renderTarget.getPointClouds().find(pointCloud => pointCloud.modelId === this._modelId && pointCloud.revisionId === this._revisionId)
. It returnsundefined
if no applicable result is found