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

RHOAIENG-9232 Create useTrackUser #3024

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

pilhuhn
Copy link
Contributor

@pilhuhn pilhuhn commented Jul 22, 2024

Closes https://issues.redhat.com/browse/RHOAIENG-9232

Description

Put obtaining user properties into its own hook. This is meant to be extended in the future.

How Has This Been Tested?

Manual testing by developer by inspecting browser console and (for non-dev mode) network tab.

Test Impact

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Commits have been squashed into descriptive, self-contained units of work (e.g. 'WIP' and 'Implements feedback' style messages have been removed)
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

cc @andrewballantyne

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress This PR is in WIP state label Jul 22, 2024
Copy link
Contributor

openshift-ci bot commented Jul 22, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@pilhuhn
Copy link
Contributor Author

pilhuhn commented Jul 22, 2024

@andrewballantyne This more or less works, but is sending the identify event repeatedly -- probably due to some React re-renders. Can you give me a hint please?

@pilhuhn
Copy link
Contributor Author

pilhuhn commented Jul 22, 2024

Thank you @christianvogt your review was super helpful.

@pilhuhn pilhuhn marked this pull request as ready for review July 22, 2024 15:47
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Jul 22, 2024
@pilhuhn
Copy link
Contributor Author

pilhuhn commented Jul 23, 2024 via email

@pilhuhn pilhuhn force-pushed the RHOAIENG-9232 branch 2 times, most recently from 0bf2cb5 to 7ee298c Compare July 25, 2024 18:10
@pilhuhn pilhuhn force-pushed the RHOAIENG-9232 branch 3 times, most recently from e2c6220 to 41e6ad7 Compare August 8, 2024 15:10
@pilhuhn
Copy link
Contributor Author

pilhuhn commented Aug 8, 2024

I think #3024 (comment) is now solved.

@emilys314
Copy link
Contributor

/lgtm, just a rebase so looks good still

@emilys314
Copy link
Contributor

/lgtm

@jeff-phillips-18
Copy link
Contributor

/lgtm

@emilys314
Copy link
Contributor

Okay, I enabled the segment stuff on my test cluster, and then I added this PR image to it.

I can confirm the identify event still run on load correctly (with the same parameters)

Before vs After screenshots the timestamp and session id's are different

before:

Screenshot from 2024-08-09 14-01-25

after:

image

const { isAdmin } = useUser();
const [anonymousId, setAnonymousId] = React.useState<string | undefined>(undefined);

const [loaded, setLoaded] = React.useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary to track this loaded as a separate state.
Compute it as !!anonymousId && acLoaded

[isAdmin, allowCreate, anonymousId],
);

return [props, loaded];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return [props, loaded];
return [props, acLoaded && !!anonymousId];

Comment on lines +30 to +38
if (!anonymousId) {
computeAnonymousUserId().then((val) => {
setAnonymousId(val);
});
}
if (acLoaded && anonymousId) {
setLoaded(true);
}
}, [username, anonymousId, acLoaded]);
Copy link
Contributor

Choose a reason for hiding this comment

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

If username changes, you aren't recomputing the anonymous id. Although I don't think username should change and you are only going to compute the anonymous id once. But should you recompute?

If you don't care to recompute based on username changes, then you can remove all hook dependencies.

Suggested change
if (!anonymousId) {
computeAnonymousUserId().then((val) => {
setAnonymousId(val);
});
}
if (acLoaded && anonymousId) {
setLoaded(true);
}
}, [username, anonymousId, acLoaded]);
computeAnonymousUserId().then((val) => {
setAnonymousId(val);
});
// compute anonymousId only once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The usename is set at login. So I don't think it will ever change during one session.

loaded,
segmentKey,
username,
dashboardConfig,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove dashboardConfig from the list of dependencies because it's too broad.
Assign dashboardConfig.spec.dashboardConfig.disableTracking to a local variable and use it as a dependency instead.

anonymousID?: string;
userId?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

userId isn't used anywhere. Should this be removed? I also thought that we shouldn't include identifiable information in events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could indeed be removed from this PR. UserId would be the web-user-id for the sandbox case.

@manosnoam
Copy link
Contributor

/approve

Copy link
Contributor

openshift-ci bot commented Aug 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jeff-phillips-18, manosnoam

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit e42fdcd into opendatahub-io:main Aug 12, 2024
6 checks passed
@pilhuhn
Copy link
Contributor Author

pilhuhn commented Aug 12, 2024

@christianvogt This was merged in the meanwhile. Should I open a subsequent PR with your suggestions?

@christianvogt
Copy link
Contributor

@pilhuhn Yes please open a new PR for additional changes. This shouldn't have been merged.

@pilhuhn pilhuhn mentioned this pull request Aug 13, 2024
4 tasks
@pilhuhn pilhuhn deleted the RHOAIENG-9232 branch October 8, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants