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

Mm 46916 lhs not refreshed after unfollow #1497

Merged
merged 4 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests-e2e/cypress/integration/lhs_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,31 @@ describe('lhs', () => {
});
});

it('lhs refresh on follow/unfollow', () => {
cy.apiLogin(testViewerUser).then(() => {
// # Visit the playbook run
cy.visit(`/playbooks/runs/${playbookRun.id}`);

// # Follow the run
cy.findByTestId('rdp-rhs-follow-button').click();

// # Wait to lhs refresh
cy.wait(3000);

// * Verify that the run was added to the lhs
cy.findByTestId('Runs').findByTestId(playbookRun.name).should('exist');

// # Click on unfollow menu item
getRunDropdownItemByText('Runs', playbookRun.name, 'Unfollow').click().then(() => {
// # Wait to lhs refresh
cy.wait(3000);

// * Verify that the run is removed lhs
cy.findByTestId('Runs').findByTestId(playbookRun.name).should('not.exist');
});
});
});

it('leave run', () => {
// # Add viewer user to the channel
cy.apiAddUserToChannel(playbookRun.channel_id, testViewerUser.id);
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/components/backstage/lhs_run_dot_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {useLeaveRun} from './playbook_runs/playbook_run/context_menu';
import {useFollowers} from './playbook_runs/playbook_run/playbook_run';
import {CopyRunLinkMenuItem, FavoriteRunMenuItem, FollowRunMenuItem, LeaveRunMenuItem} from './playbook_runs/playbook_run/controls';
import {DotMenuButtonStyled} from './shared';
import {useLHSRefresh} from './lhs_navigation';

interface Props {
playbookRunId: string;
Expand All @@ -33,6 +34,7 @@ export const LHSRunDotMenu = ({playbookRunId, isFavorite, ownerUserId, participa
const {add: addToast} = useToaster();
const updateRun = useUpdateRun(playbookRunId);
const currentUser = useSelector(getCurrentUser);
const refreshLHS = useLHSRefresh();

const followState = useFollowers(followerIDs);
const {isFollowing, followers, setFollowers} = followState;
Expand All @@ -50,6 +52,7 @@ export const LHSRunDotMenu = ({playbookRunId, isFavorite, ownerUserId, participa
.then(() => {
const newFollowers = isFollowing ? followers.filter((userId) => userId !== currentUser.id) : [...followers, currentUser.id];
setFollowers(newFollowers);
refreshLHS();
})
.catch(() => {
addToast(formatMessage({defaultMessage: 'It was not possible to {isFollowing, select, true {unfollow} other {follow}} the run'}, {isFollowing}), ToastType.Failure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export const useFollow = (runID: string, followState: FollowState) => {
const addToast = useToaster().add;
const {isFollowing, followers, setFollowers} = followState;
const currentUser = useSelector(getCurrentUser);
const refreshLHS = useLHSRefresh();

const toggleFollow = () => {
const action = isFollowing ? unfollowPlaybookRun : followPlaybookRun;
action(runID)
.then(() => {
const newFollowers = isFollowing ? followers.filter((userId) => userId !== currentUser.id) : [...followers, currentUser.id];
setFollowers(newFollowers);
refreshLHS();
})
.catch(() => {
addToast(formatMessage({defaultMessage: 'It was not possible to {isFollowing, select, true {unfollow} other {follow}} the run'}, {isFollowing}), ToastType.Failure);
Expand All @@ -70,7 +72,10 @@ export const useFollow = (runID: string, followState: FollowState) => {
}

return (
<FollowButton onClick={toggleFollow}>
<FollowButton
data-testid={'rdp-rhs-follow-button'}
onClick={toggleFollow}
>
{formatMessage({defaultMessage: 'Follow'})}
</FollowButton>
);
Expand Down