Skip to content

fix(store): minor-fixes-after-storeEventsWrapper #390

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

Merged
merged 5 commits into from
Feb 20, 2025

Conversation

Shreyas281299
Copy link

@Shreyas281299 Shreyas281299 commented Feb 18, 2025

COMPLETES #SPARK-610353

This pull request addresses

The final round of review for the PR -#369
Since we were on a clock these non-blocking comments were left.

by making the following changes

  • Removed the isAgentLoggedIn local state in station-login
  • Reverted worker thread logic for user-state timmer
  • Removed webex as dependency in cc-task, exporting the types from cc-store

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

  • The testing is done with the amplify link
Screen.Recording.2025-02-19.at.11.23.19.AM.mov
  • Changes state from available to any other state and made sure timmer is refreshed
  • Refresh with state as available- timmer should start from 0
  • Refresh with state as meeting- timmer held the last state change time

Checklist before merging

  • I have not skipped any automated checks
  • All existing and new tests passed
  • I have updated the testing document
  • I have tested the functionality with amplify link

Make sure to have followed the contributing guidelines before submitting.

Copy link

coderabbitai bot commented Feb 18, 2025

📝 Walkthrough

Walkthrough

This pull request removes the isAgentLoggedIn state and its related logic from the station-login hook and associated components. The changes include updating the properties passed to the StationLoginPresentational component, as well as modifying the type definitions by removing the isAgentLoggedIn property. Additionally, the MobX store configuration has been altered by removing certain observable properties, affecting how state is tracked. In the task module, adjustments were made to introduce and utilize a new deviceType property across hooks and components, notably in the CallControl and useCallControl implementations, along with corresponding updates in their tests. Other notable modifications include dependency management updates in the package manifest and a simplification of worker handling in the useUserState hook.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Shreyas281299 Shreyas281299 changed the title fix(store): review-comments fix(store): minor-fixes-after-storeEventsWrapper Feb 19, 2025
@@ -8,18 +8,13 @@ export const useStationLogin = (props: UseStationLoginProps) => {
const loginCb = props.onLogin;
const logoutCb = props.onLogout;
const logger = props.logger;
const [isAgentLoggedIn, setIsAgentLoggedIn] = useState(props.isAgentLoggedIn);
Copy link
Author

@Shreyas281299 Shreyas281299 Feb 19, 2025

Choose a reason for hiding this comment

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

original comment- See if we can remove the isAgentLogged in props as we already have this in the store

Removed the local state

@@ -22,8 +21,10 @@ const StationLoginComponent: React.FunctionComponent<StationLoginProps> = ({onLo
teams,
loginOptions,
deviceType,
isAgentLoggedIn,
showMultipleLoginAlert,
Copy link
Author

Choose a reason for hiding this comment

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

Original comment- we can move showMultipleLoginAlert to results as we already have it rather than putting it directly in the presentation component

Moved

incomingTask: observable,
taskList: observable,
wrapupRequired: observable,
currentState: observable,
Copy link
Author

Choose a reason for hiding this comment

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

Store is already updating these values and the latest values are reaching the components, so we dont need them as observable here, makeAutoObservable method is doing this for us.

@@ -97,6 +97,7 @@ enum CC_EVENTS{

export type {
IContactCenter,
ITask,
Copy link
Author

Choose a reason for hiding this comment

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

Importing ITask from cc-sdk and exporting it from store, all the types from cc-sdk wll be imported and exported from the store, this will ensure cc-store is the only place where we use cc-sdk as a dependency

IWrapupCode,
WithWebex,
IContactCenter,
ITask,
Copy link
Author

Choose a reason for hiding this comment

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

ITask imported from store/types

@@ -235,14 +244,15 @@ class StoreWrapper implements IStoreWrapper {
}
};

setupIncomingTaskHandler = (ccSDK: any) => {
setupIncomingTaskHandler = (ccSDK: IContactCenter) => {
Copy link
Author

Choose a reason for hiding this comment

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

Removed any type

// return this.store.registerCC(webex);
// };

it('should call registerCC', () => {
Copy link
Author

Choose a reason for hiding this comment

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

For coverage, I forgot to add test for this

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-390.d1b38q61t1z947.amplifyapp.com

@@ -156,7 +177,7 @@ describe('storeEventsWrapper', () => {
});

it('should setWrapupCodes', () => {
const mockCodes = [{code1: 'code1'}, {code2: 'code2'}];
const mockCodes = [{id: 'code1', name: 'code1'}];
Copy link
Author

Choose a reason for hiding this comment

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

The types was mismatching, so fixed this

@@ -20,8 +20,7 @@
},
"dependencies": {
"@webex/cc-store": "workspace:*",
"mobx-react-lite": "^4.1.0",
"webex": "3.7.0-wxcc.15"
Copy link
Author

Choose a reason for hiding this comment

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

webex will be dependency only in cc-store and no where else.

Comment on lines +11 to +15
const result = {
...useCallControl({currentTask, deviceType, onHoldResume, onEnd, onWrapUp, logger}),
wrapupRequired,
wrapupCodes,
};
Copy link
Author

Choose a reason for hiding this comment

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

refactor to avoid passing props directly to the presentational

@@ -114,7 +115,7 @@ export const useCallControl = (props: useCallControlProps) => {
);

useEffect(() => {
if (!currentTask) return;
if (!currentTask || !isBrowser) return;
Copy link
Author

Choose a reason for hiding this comment

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

We will only add media listeners when the login type is BROWSER as thats the only case when we will ahve this event

Comment on lines -379 to -380
onTaskAccepted: null,
onTaskDeclined: null,
Copy link
Author

Choose a reason for hiding this comment

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

These are optional, so we can just remove it rather than keeping them as null

})
);

await act(async () => {
await result.current.wrapupCall('Wrap reason', 123);
await result.current.wrapupCall('Wrap reason', '123');
Copy link
Author

Choose a reason for hiding this comment

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

There was a types issue

} else {
workerRef.current.postMessage({type: 'start', startTime: Date.now()});
}
if (workerRef.current && lastStateChangeTimestamp) {
Copy link
Author

Choose a reason for hiding this comment

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

I don't know why this code was not working when I tried earlier but I just reverted to the original code and the timer was working fine, so reverted these changes. Since this was already tested no new tests are required, The changes were added as part of #371

@Shreyas281299
Copy link
Author

@CodeRabbit review

Copy link

coderabbitai bot commented Feb 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/contact-center/task/tests/IncomingTask/index.tsx (1)

18-38: Consider adding test cases for non-null incomingTask scenarios.

While the current test verifies the basic component setup, consider adding test cases to verify:

  1. Component behavior when incomingTask is non-null
  2. Error handling scenarios
  3. Edge cases like undefined or invalid task data
packages/contact-center/task/tests/helper.ts (1)

869-895: Improve test description.

The test description "test undefined audioRef.current" could be more descriptive. Consider renaming it to something like "should handle undefined audioRef.current gracefully".

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b13e84b and 445e805.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (18)
  • packages/contact-center/station-login/src/helper.ts (0 hunks)
  • packages/contact-center/station-login/src/station-login/index.tsx (1 hunks)
  • packages/contact-center/station-login/src/station-login/station-login.types.ts (1 hunks)
  • packages/contact-center/station-login/tests/helper.ts (0 hunks)
  • packages/contact-center/station-login/tests/station-login/index.tsx (2 hunks)
  • packages/contact-center/store/src/store.ts (0 hunks)
  • packages/contact-center/store/src/store.types.ts (2 hunks)
  • packages/contact-center/store/src/storeEventsWrapper.ts (2 hunks)
  • packages/contact-center/store/tests/store.ts (0 hunks)
  • packages/contact-center/store/tests/storeEventsWrapper.ts (4 hunks)
  • packages/contact-center/task/package.json (1 hunks)
  • packages/contact-center/task/src/CallControl/index.tsx (1 hunks)
  • packages/contact-center/task/src/helper.ts (2 hunks)
  • packages/contact-center/task/src/task.types.ts (3 hunks)
  • packages/contact-center/task/tests/CallControl/index.tsx (1 hunks)
  • packages/contact-center/task/tests/IncomingTask/index.tsx (1 hunks)
  • packages/contact-center/task/tests/helper.ts (21 hunks)
  • packages/contact-center/user-state/src/helper.ts (1 hunks)
💤 Files with no reviewable changes (4)
  • packages/contact-center/store/src/store.ts
  • packages/contact-center/station-login/src/helper.ts
  • packages/contact-center/store/tests/store.ts
  • packages/contact-center/station-login/tests/helper.ts
🧰 Additional context used
🧠 Learnings (5)
packages/contact-center/user-state/src/helper.ts (1)
Learnt from: mkesavan13
PR: webex/widgets#347
File: packages/contact-center/user-state/src/helper.ts:10-19
Timestamp: 2024-12-06T01:07:12.444Z
Learning: In `packages/contact-center/user-state/src/helper.ts`, within the `useUserState` hook, the timer reset in the `useEffect` hook is handled during the state change success. Therefore, modifying the dependency array is unnecessary.
packages/contact-center/station-login/src/station-login/station-login.types.ts (2)
Learnt from: pagour98
PR: webex/widgets#385
File: packages/contact-center/station-login/src/station-login/station-login.types.ts:129-132
Timestamp: 2025-02-13T06:59:01.103Z
Learning: In the station-login component's type definitions, it's acceptable for `UseStationLoginProps` to have a subset of props (`cc`, `onLogin`, `onLogout`, `logger`, `isAgentLoggedIn`) compared to `IStationLoginProps` and `StationLoginPresentationalProps`, even if properties like `handleContinue` and `showMultipleLoginAlert` exist in the latter interfaces.
Learnt from: pagour98
PR: webex/widgets#385
File: packages/contact-center/station-login/src/station-login/index.tsx:10-10
Timestamp: 2025-02-13T06:58:01.805Z
Learning: In the StationLogin component (packages/contact-center/station-login/src/station-login/index.tsx), `handleContinue` and `showMultipleLoginAlert` props have been intentionally removed from store destructuring as part of the Agent Multi-Login configurability changes.
packages/contact-center/station-login/src/station-login/index.tsx (4)
Learnt from: pagour98
PR: webex/widgets#385
File: packages/contact-center/station-login/src/station-login/index.tsx:10-10
Timestamp: 2025-02-13T06:58:01.805Z
Learning: In the StationLogin component (packages/contact-center/station-login/src/station-login/index.tsx), `handleContinue` and `showMultipleLoginAlert` props have been intentionally removed from store destructuring as part of the Agent Multi-Login configurability changes.
Learnt from: pagour98
PR: webex/widgets#385
File: packages/contact-center/station-login/src/station-login/station-login.types.ts:129-132
Timestamp: 2025-02-13T06:59:01.103Z
Learning: In the station-login component's type definitions, it's acceptable for `UseStationLoginProps` to have a subset of props (`cc`, `onLogin`, `onLogout`, `logger`, `isAgentLoggedIn`) compared to `IStationLoginProps` and `StationLoginPresentationalProps`, even if properties like `handleContinue` and `showMultipleLoginAlert` exist in the latter interfaces.
Learnt from: Kesari3008
PR: webex/widgets#239
File: packages/contact-center/station-login/src/station-login/station-login.presentational.tsx:0-0
Timestamp: 2024-11-19T13:45:03.435Z
Learning: In `packages/contact-center/station-login/src/station-login/station-login.presentational.tsx`, certain code sections are temporary or removable, and comments regarding these sections can be ignored in future reviews.
Learnt from: Kesari3008
PR: webex/widgets#239
File: packages/contact-center/station-login/tests/station-login/station-login.presentational.tsx:0-0
Timestamp: 2024-11-19T13:44:14.152Z
Learning: The file `packages/contact-center/station-login/tests/station-login/station-login.presentational.tsx` is going to change completely, so writing tests for these changes are being ignored.
packages/contact-center/task/tests/CallControl/index.tsx (2)
Learnt from: Shreyas281299
PR: webex/widgets#362
File: packages/contact-center/task/tests/CallControl/index.tsx:29-46
Timestamp: 2025-01-20T09:52:57.754Z
Learning: UI testing is not mandatory for components in the @webex/widgets repository. Focus should be on functional testing rather than UI element verification.
Learnt from: Shreyas281299
PR: webex/widgets#362
File: packages/contact-center/task/tests/CallControl/call-control.presentational.tsx:0-0
Timestamp: 2025-01-20T09:52:20.775Z
Learning: UI testing is not mandatory for React components in the webex/widgets repository.
packages/contact-center/station-login/tests/station-login/index.tsx (2)
Learnt from: Kesari3008
PR: webex/widgets#239
File: packages/contact-center/station-login/tests/station-login/station-login.presentational.tsx:0-0
Timestamp: 2024-11-19T13:44:14.152Z
Learning: The file `packages/contact-center/station-login/tests/station-login/station-login.presentational.tsx` is going to change completely, so writing tests for these changes are being ignored.
Learnt from: Kesari3008
PR: webex/widgets#239
File: packages/contact-center/station-login/src/station-login/station-login.presentational.tsx:0-0
Timestamp: 2024-11-19T13:45:03.435Z
Learning: In `packages/contact-center/station-login/src/station-login/station-login.presentational.tsx`, certain code sections are temporary or removable, and comments regarding these sections can be ignored in future reviews.
🔇 Additional comments (23)
packages/contact-center/task/tests/IncomingTask/index.tsx (1)

22-28: LGTM! The mock return value aligns with the hook's new structure.

The changes correctly reflect the restructured return value of the useIncomingTask hook, maintaining the essential test coverage while removing obsolete properties.

packages/contact-center/task/src/CallControl/index.tsx (2)

10-15: LGTM! Props consolidation improves code organization.

The refactoring to consolidate all props into a single result object improves code organization and follows the previous review suggestion to avoid passing props directly.


17-17: LGTM! Clean prop spreading.

The simplified prop spreading to the presentational component makes the code more maintainable.

packages/contact-center/station-login/src/station-login/index.tsx (2)

24-25: LGTM! Props consolidation aligns with previous feedback.

The addition of isAgentLoggedIn and showMultipleLoginAlert to the props object aligns with the previous review feedback about moving these properties to the result object.


27-27: LGTM! Clean prop spreading.

The simplified prop spreading to the presentational component improves code maintainability.

packages/contact-center/task/tests/CallControl/index.tsx (1)

36-42: LGTM! Test assertions are more flexible and complete.

The changes improve test robustness by:

  • Using expect.any(Object) for currentTask makes the test more flexible
  • Adding deviceType assertion ensures the new property is properly tested
packages/contact-center/station-login/tests/station-login/index.tsx (3)

8-16: LGTM! Mock objects improve test isolation.

The introduction of dedicated mock objects improves test isolation and makes the test setup more maintainable.


36-38: LGTM! Presentational component spy improves test coverage.

The addition of the presentational component spy ensures proper rendering is tested.


42-48: LGTM! Updated assertions match component changes.

The test assertions correctly reflect the changes in the component's props structure.

packages/contact-center/user-state/src/helper.ts (1)

39-44: LGTM! Timer reset logic has been simplified.

The changes align with the previous learning that timer reset should be handled during state change success. The simplified logic correctly calculates elapsed time and resets the worker timer.

packages/contact-center/station-login/src/station-login/station-login.types.ts (1)

129-129: LGTM! Removal of isAgentLoggedIn aligns with Agent Multi-Login changes.

The removal of isAgentLoggedIn from UseStationLoginProps is consistent with the previous learnings about Agent Multi-Login configurability changes.

packages/contact-center/store/src/store.types.ts (1)

100-110: LGTM! Centralizing type exports in cc-store.

The addition of ITask to the exports aligns with the goal of centralizing all cc-sdk type exports in cc-store, improving dependency management.

packages/contact-center/task/src/task.types.ts (3)

1-1: LGTM! Imports consolidated from cc-store.

The consolidation of imports from @webex/cc-store aligns with the centralization of type exports.


191-196: LGTM! Well-documented deviceType property addition.

The addition of the deviceType property to ControlProps is properly documented with JSDoc comments.


212-215: LGTM! Consistent type updates.

The useCallControlProps type has been correctly updated to include the new deviceType property.

packages/contact-center/task/package.json (1)

21-24: Webex Dependency Removal is Correct and Consistent.

The removal of the "webex": "3.7.0-wxcc.15" dependency aligns with the overall refactoring strategy—ensuring that any Webex-related functionality is now consolidated within @webex/cc-store. This change is consistent with prior review guidance (see previous comment by Shreyas281299). Please verify that no residual references to the removed dependency exist elsewhere in the codebase.

packages/contact-center/task/src/helper.ts (2)

97-99: LGTM! Good defensive programming.

The addition of deviceType parameter and isBrowser check improves the robustness of the hook by ensuring device-specific functionality is handled correctly.


118-118: LGTM! Improved conditional check.

The addition of !isBrowser to the condition ensures media listeners are only added for browser devices, which is the correct behavior as confirmed by past review comments.

packages/contact-center/store/src/storeEventsWrapper.ts (2)

247-247: LGTM! Improved type safety.

Replacing any with IContactCenter type improves type safety and code maintainability.


255-255: Track the TODO for removing event listeners.

The TODO comment indicates a potential memory leak issue that needs to be addressed. Please ensure this is tracked in JIRA ticket SPARK-617635.

packages/contact-center/store/tests/storeEventsWrapper.ts (3)

127-140: LGTM! Good test coverage for registerCC.

The test verifies both the basic call and the call with parameters, ensuring the method works correctly in different scenarios.


176-176: LGTM! Updated mock codes structure.

The mock codes structure has been updated to use id and name properties, aligning with the expected format.


896-912: LGTM! Good test for device type handling.

The test verifies that media listeners are not added for non-browser devices, which is an important edge case.

@adhmenon
Copy link
Contributor

Changes look alright. Can we have the updated test plan with the tests done? (just to see that nothing breaks).

@Shreyas281299 Shreyas281299 merged commit 8738ab2 into webex:ccwidgets Feb 20, 2025
3 checks passed
@sreenara
Copy link
Contributor

🎉 This PR is included in version 1.28.0-ccwidgets.19 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Shreyas281299 pushed a commit to Shreyas281299/widgets that referenced this pull request Feb 21, 2025
# [1.28.0-ccwidgets.19](webex/widgets@v1.28.0-ccwidgets.18...v1.28.0-ccwidgets.19) (2025-02-20)

### Bug Fixes

* **store:** minor-fixes-after-storeEventsWrapper ([webex#390](webex#390)) ([8738ab2](webex@8738ab2))
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.

4 participants