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(credentials): nested match expressions table #495

Merged
merged 22 commits into from
Aug 15, 2022
Merged

feat(credentials): nested match expressions table #495

merged 22 commits into from
Aug 15, 2022

Conversation

hareetd
Copy link
Contributor

@hareetd hareetd commented Aug 5, 2022

Fixes #466

Includes some minor fixes to the nested table implementation in the AllTargetsArchvedRecordingsTable.

image

@andrewazores
Copy link
Member

Just looks like the test snapshot needs updating.

@hareetd
Copy link
Contributor Author

hareetd commented Aug 5, 2022

Ah, I forgot to update/add tests, thanks.

@andrewazores
Copy link
Member

andrewazores commented Aug 5, 2022

Oh, I see this is still a draft. Carry on :-)

@andrewazores
Copy link
Member

I notice that after first adding a new credential from directly within the Security view, the new row gets added to the table but the count badge is missing. If I navigate away to some other view and then back to Security then the badge appears with the expected number.

@andrewazores
Copy link
Member

Also the badge doesn't seem to live-update with target discovery notifications while I'm on the Security view - at least not "LOST" notifications, which are all I tried.

@hareetd
Copy link
Contributor Author

hareetd commented Aug 5, 2022

Sounds good, thanks for the feedback.

@hareetd hareetd marked this pull request as ready for review August 15, 2022 00:03
@hareetd
Copy link
Contributor Author

hareetd commented Aug 15, 2022

I realized while writing tests that the notification handling for multiple deleted credentials in StoreJmxCredentials was broken. Specifically, the notifications would come through but not all of the corresponding credentials would be removed from the table. My first thought was that the rendering was having issues due to improper state handling.

Considering I have a lot of state objects (credentials, expandedCredentials, checkedCredentials, isHeaderChecked, and counts) that are related to each other and as a result, are frequently updated at the same time, I decided to convert their handling from useState to useReducer. Unfortunately, this didn't fix the original problem.

I then realized since the synchronous notification handling for deleted credentials is more involved than usual (relative to our other components) some of the asynchronous notifications from the Subscription were being missed and going unprocessed. So I decided to use concatMap in conjunction with of to ensure each notification is fully processed before proceeding to the next:

 React.useEffect(() => {
    addSubscription(
      context.notificationChannel.messages(NotificationCategory.CredentialsDeleted)
      .pipe(concatMap(v => of(dispatch({ type: Actions.HANDLE_CREDENTIALS_DELETED_NOTIFICATION, payload: { credential: v.message }}))))
      .subscribe(() => {} /* do nothing - dispatch will have already handled updating state */)
    );
  }, [addSubscription, context, context.notificationChannel]);

I wonder how many of our other components also have this same issue but we haven't realized since the type of notifications they handle don't typically get spammed when testing?

@hareetd
Copy link
Contributor Author

hareetd commented Aug 15, 2022

Taking a look at the ArchivedRecordingsTable, it looks like the notification handling for deleted recordings is fairly involved but there is no such issue present there.

I wonder if my issue is due to the nature of setting up a nested table using useEffects with dependencies (credentials, counts, etc.) that are frequently updated at the same time (at least, at a more frequent rate than our more typical components) or whether my design approach is incorrect?

@hareetd hareetd requested a review from andrewazores August 15, 2022 16:39
@andrewazores
Copy link
Member

I'm not sure - this is a tough thing to track down. useReducer was a good idea to try to tackle the problem.

It might be as simple as a state hook not updating, though. IIRC the elements within the dependencies array are only compared by reference, not by value, and not by any deep comparison. So for example, if you have a piece of state that is actually an array or a Map etc. and you mutate that object, the reference remains the same and the hook will not update.

But your hunch that it could be timing related also seems completely possible.

@andrewazores
Copy link
Member

Last commit looks like it solved it :-)

@hareetd
Copy link
Contributor Author

hareetd commented Aug 15, 2022

Yeah, looks like it was a timing issue. I've modified the AllTargetsArchivedRecordingsTable to ensure synchronous target-related notification handling there as well, just in case.

@andrewazores andrewazores merged commit e871759 into cryostatio:main Aug 15, 2022
@hareetd hareetd deleted the nested-match-expressions-table branch August 15, 2022 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Implement nested table for matchExpression Credentials
2 participants