generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 159
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-47629] Don't crash when a run channel has been deleted #1908
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1266,11 +1266,12 @@ func (s *PlaybookRunServiceImpl) GetPlaybookRunMetadata(playbookRunID string) (* | |
// Get main channel details | ||
channel, err := s.pluginAPI.Channel.Get(playbookRun.ChannelID) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to retrieve channel id '%s'", playbookRun.ChannelID) | ||
s.pluginAPI.Log.Warn("failed to retrieve channel id", "channel_id", playbookRun.ChannelID) | ||
channel = &model.Channel{} | ||
JulienTant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
team, err := s.pluginAPI.Team.Get(channel.TeamId) | ||
team, err := s.pluginAPI.Team.Get(playbookRun.TeamID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the run teamID because the channel might not exist |
||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to retrieve team id '%s'", channel.TeamId) | ||
return nil, errors.Wrapf(err, "failed to retrieve team id '%s'", playbookRun.TeamID) | ||
} | ||
|
||
numParticipants, err := s.store.GetHistoricalPlaybookRunParticipantsCount(playbookRun.ChannelID) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ interface Props { | |
runMetadata?: Metadata; | ||
editable: boolean; | ||
channel: Channel | undefined | null; | ||
channelDeleted: boolean; | ||
followState: FollowState; | ||
playbook?: PlaybookWithChecklist; | ||
role: Role; | ||
|
@@ -91,7 +92,7 @@ const StyledArrowIcon = styled(ArrowForwardIosIcon)` | |
margin-left: 7px; | ||
`; | ||
|
||
const RHSInfoOverview = ({run, role, channel, runMetadata, followState, editable, playbook, onViewParticipants}: Props) => { | ||
const RHSInfoOverview = ({run, role, channel, channelDeleted, runMetadata, followState, editable, playbook, onViewParticipants}: Props) => { | ||
const {formatMessage} = useIntl(); | ||
const addToast = useToaster().add; | ||
const refreshLHS = useLHSRefresh(); | ||
|
@@ -197,24 +198,13 @@ const RHSInfoOverview = ({run, role, channel, runMetadata, followState, editable | |
icon={ProductChannelsIcon} | ||
name={formatMessage({defaultMessage: 'Channel'})} | ||
> | ||
{channel && runMetadata ? <> | ||
<ItemLink | ||
to={`/${runMetadata.team_name}/channels/${channel.name}`} | ||
data-testid='runinfo-channel-link' | ||
> | ||
<ItemContent > | ||
{channel.display_name} | ||
</ItemContent> | ||
<OpenInNewIcon | ||
size={14} | ||
color={'var(--button-bg)'} | ||
/> | ||
</ItemLink> | ||
</> : <ItemDisabledContent> | ||
{role === Role.Participant ? <RequestJoinButton onClick={showRequestJoinConfirm}>{formatMessage({defaultMessage: 'Request to Join'})}</RequestJoinButton> : null} | ||
<LockOutlineIcon size={20}/> {formatMessage({defaultMessage: 'Private'})} | ||
</ItemDisabledContent> | ||
} | ||
<ChannelRow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the channel row to it's own component because we started to have a lot of conditions. |
||
channel={channel} | ||
runMetadata={runMetadata} | ||
channelDeleted={channelDeleted} | ||
role={role} | ||
onClickRequestJoin={showRequestJoinConfirm} | ||
/> | ||
</Item> | ||
{RequestJoinModal} | ||
</Section> | ||
|
@@ -277,7 +267,7 @@ const ItemDisabledContent = styled(ItemContent)` | |
color: rgba(var(--center-channel-color-rgb), 0.64); | ||
`; | ||
|
||
const OverviewRow = styled.div<{onClick?: () => void}>` | ||
const OverviewRow = styled.div<{ onClick?: () => void }>` | ||
padding: 10px 24px; | ||
height: 44px; | ||
display: flex; | ||
|
@@ -321,3 +311,47 @@ const ParticipantsContainer = styled.div` | |
flex-direction: row; | ||
align-items: center; | ||
`; | ||
|
||
interface ChannelRowProps { | ||
channel: Channel | undefined | null; | ||
channelDeleted: boolean; | ||
runMetadata?: Metadata; | ||
role: Role; | ||
onClickRequestJoin: () => void; | ||
} | ||
|
||
const ChannelRow = ({channel, runMetadata, channelDeleted, role, onClickRequestJoin}: ChannelRowProps) => { | ||
const {formatMessage} = useIntl(); | ||
|
||
if (channelDeleted) { | ||
return ( | ||
<ItemDisabledContent> | ||
{formatMessage({defaultMessage: 'Channel deleted'})} | ||
</ItemDisabledContent> | ||
); | ||
} | ||
|
||
if (channel && runMetadata) { | ||
return ( | ||
<ItemLink | ||
to={`/${runMetadata.team_name}/channels/${channel.name}`} | ||
data-testid='runinfo-channel-link' | ||
> | ||
<ItemContent > | ||
JulienTant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{channel.display_name} | ||
</ItemContent> | ||
<OpenInNewIcon | ||
size={14} | ||
color={'var(--button-bg)'} | ||
/> | ||
</ItemLink> | ||
); | ||
} | ||
|
||
return ( | ||
<ItemDisabledContent> | ||
{role === Role.Participant ? <RequestJoinButton onClick={onClickRequestJoin}>{formatMessage({defaultMessage: 'Request to Join'})}</RequestJoinButton> : null} | ||
<LockOutlineIcon size={20}/> {formatMessage({defaultMessage: 'Private'})} | ||
</ItemDisabledContent> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is the main core change: considering that a missing channel is not a big deal and we can continue the process without it.