Skip to content
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

feat(react-components): functionality surrounding Points of interest #4866

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

haakonflatval-cognite
Copy link
Contributor

Type of change

Feat

Jira ticket 📘

https://cognitedata.atlassian.net/browse/

Description 📝

Contains

  • ADS (Cognite's Application Data Service) provider for points of interest
  • Commands for creating and deleting PoIs
  • Components for showing PoI info
    • PoIList shows all loaded PoIs
    • PoIInfoPanelContent shows more details about a single point of interest
  • Hooks for accessing PoI information (from external applications)
  • PoI comment support

How has this been tested? 🔍

Test instructions ℹ️

Checklist ☑️

  • I am proud of this feature.
  • I have performed a self-review of my own code.
  • I have added PR type (Feat, Bug, Chore, Test, Docs, Style, Refactor) to the PR title.
  • I have manually tested this for different scenarios (different models, formats, devices, browsers).
  • I have commented my code in hard-to-understand areas.
  • I have made corresponding changes to the public documentation.
  • I have added unit and visuals tests to prove that my feature works to the best of my ability.
  • I have refactored the code for readability to the best of my ability.
  • I have checked that my changes do not introduce regressions in the public documentation.
  • I have outlined any known defects / lacking capabilities in the contents of this PR.
  • I have listed any remaining work that should follow this PR in the description or jira/miro/etc.
  • I have added TSDoc to any public facing changes.
  • I have added "developer documentation" in any package README.md that is related / applicable to this PR.
  • I have noted down and am currently tracking any technical debt introduced in this PR.
  • I have thoroughly thought about the architecture of this implementation.
  • I have asked peers to test this feature.

@haakonflatval-cognite haakonflatval-cognite requested a review from a team as a code owner November 15, 2024 12:33
Copy link
Contributor

@danpriori danpriori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!
Some comments that involves some discussions and the request for changes are more about to check if does make sense such as the multiple comments on PoIs (how to get a single comment from a single PoI, for example).
If the concerns doesnt make sense or the code is supporting the concern already, then the rest are not a blocker but more some improvements on top of the current version, I think.


public override getPlaceholder(t: TranslateDelegate): string | undefined {
return t('COMMENT_PLACEHOLDER', 'Write a comment');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if it would be better to have the translator instance as a property of the base class (and instantiated in the constructor, perhaps) instead of passing through it as a parameter and flying around on different methods everywhere risking to complicated to be GCollected if some ref was created in other places out of the class instance. If it is a class parameter and used internally only, then it would be Gcollected when the instance is removed.
But ofc, maybe I'm overthinking, or shouldn't work as expected.
And I know this is part of the architecture so we don't have to change that now (if does make sense, ofc) ... I'm just raising this reasoning 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's part of the architecture, so we'd probably need to convince Nils Petter 😅 But I think there is only one Translation instance in practice, so not sure Garbage Collection would be a problem anyway? 🤔

}

public override get tooltip(): TranslateKey {
return { key: 'CREATE_POI', fallback: 'Create point of interest' };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here we are using the translate key as the returning type (assuming that it will be used by the translator outside in some react component, right?.
But in other methods we are returning the string directly by processing the translator within the method by getting the TranslateDelegate argument. Is there a good or easy way to keep the same pattern or doesnt make sense in this case? 🤔

constructor(poiProvider: PointsOfInterestProvider<PoIId>) {
this._poiProvider = poiProvider;
this._loadedPromise = poiProvider.fetchAllPointsOfInterest();
}

public async getPoiCommentsForPoi(id: PoIId): Promise<CommentProperties[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not better PoiID(or PoiId) instead of PoIID or PoIId ? Hard to read 😆

import { Quantity } from '../../base/domainObjectsHelpers/Quantity';
import { type PointsOfInterestProvider } from './PointsOfInterestProvider';
import { isDefined } from '../../../utilities/isDefined';

export class PointsOfInterestDomainObject<PoIIdType> extends VisualDomainObject {
private _selectedPointsOfInterest: PointsOfInterest<PoIIdType> | undefined;
private _selectedPointsOfInterest: PointOfInterest<PoIIdType> | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PoiIdType perhaps? No? 😆

poiObject
}: {
poiObject: PointsOfInterestDomainObject<any>;
}): ReactElement => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not better to use ReactNode here as well even not having any the other returning for now?

domainObject: PointsOfInterestDomainObject<unknown>,
poi: PointOfInterest<unknown>
): UseQueryResult<CommentProperties[]> {
return useQuery({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other parts of the code (Search UI, for instance) whenever we use the useQuery hook, we are moving the hooks to a subfolder called query and adding a sufix, something like: useCommentsForPoIQuery.
Are we gonna follow the same pattern here?

import { useRenderTarget } from '../../RevealCanvas';
import { useOnUpdate } from '../useOnUpdate';

export function usePoIDomainObject(): PointsOfInterestDomainObject<any> | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to get rid of the any here?

export const useSyncSelectedPoI = (
selectedPoi: PointOfInterest<any> | undefined,
setSelectedPoi: (poi: PointOfInterest<any> | undefined) => void
) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of the any here as well or it would demand to much effort?
Btw, these "any"s seems like a temporary definition as we are planning to publish this feature asap, isnt? I think it is fine to keep it for now but maybe we can think about it once we have more time.

@@ -7,6 +7,8 @@ export const queryKeys = {
all: ['cdf'] as const,
// ASSETS
assetsById: (ids: IdEither[]) => [...assets, ids] as const,
// Points of interest
poiCommentsById: (id: any) => [...pois, id] as const,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the id a string, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants