|
@@ -1,57 +1,40 @@
|
|
|
import * as React from 'react';
|
|
|
-import isEqual from 'lodash/isEqual';
|
|
|
|
|
|
import TeamStore from 'sentry/stores/teamStore';
|
|
|
import {Team} from 'sentry/types';
|
|
|
|
|
|
-import Badge from './badge';
|
|
|
+import Badge, {BadgeProps} from './badge';
|
|
|
|
|
|
-type Props = React.ComponentProps<typeof Badge>;
|
|
|
+function TeamBadge(props: BadgeProps) {
|
|
|
+ const [team, setTeam] = React.useState<Team>(props.team);
|
|
|
|
|
|
-type State = {
|
|
|
- team: Team;
|
|
|
-};
|
|
|
+ const onTeamStoreUpdate = React.useCallback(
|
|
|
+ (updatedTeam: Set<string>) => {
|
|
|
+ if (!updatedTeam.has(team.id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
-class TeamBadgeContainer extends React.Component<Props, State> {
|
|
|
- state: State = {team: this.props.team};
|
|
|
+ const newTeam = TeamStore.getById(team.id);
|
|
|
|
|
|
- UNSAFE_componentWillReceiveProps(nextProps: Props) {
|
|
|
- if (this.state.team === nextProps.team) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!newTeam) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (isEqual(this.state.team, nextProps.team)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.setState({team: nextProps.team});
|
|
|
- }
|
|
|
-
|
|
|
- componentWillUnmount() {
|
|
|
- this.unlistener?.();
|
|
|
- }
|
|
|
-
|
|
|
- unlistener = TeamStore.listen(
|
|
|
- (team: Set<string>) => this.onTeamStoreUpdate(team),
|
|
|
- undefined
|
|
|
+ setTeam(newTeam);
|
|
|
+ },
|
|
|
+ [team, TeamStore]
|
|
|
);
|
|
|
|
|
|
- onTeamStoreUpdate(updatedTeam: Set<string>) {
|
|
|
- if (!updatedTeam.has(this.state.team.id)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const team = TeamStore.getById(this.state.team.id);
|
|
|
- if (!team || isEqual(team.avatar, this.state.team.avatar)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ React.useEffect(() => {
|
|
|
+ const unsubscribeTeam = TeamStore.listen(
|
|
|
+ (teamSet: Set<string>) => onTeamStoreUpdate(teamSet),
|
|
|
+ undefined
|
|
|
+ );
|
|
|
|
|
|
- this.setState({team});
|
|
|
- }
|
|
|
+ return () => unsubscribeTeam();
|
|
|
+ }, [onTeamStoreUpdate]);
|
|
|
|
|
|
- render() {
|
|
|
- return <Badge {...this.props} team={this.state.team} />;
|
|
|
- }
|
|
|
+ return <Badge {...props} team={team} />;
|
|
|
}
|
|
|
|
|
|
-export default TeamBadgeContainer;
|
|
|
+export {TeamBadge};
|