Skip to content

Commit e59df23

Browse files
authored
ref(ts): Convert groupActivity to Typescript (#21921)
* ref(ts): Convert groupActivity to Typescript * missing props * default error json constant * showtime should be false * route component props * route component params
1 parent 7de4660 commit e59df23

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

src/sentry/static/sentry/app/components/activity/note/types.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {OnChangeHandlerFunc} from 'react-mentions';
22

3+
import {DEFAULT_ERROR_JSON} from 'app/constants';
4+
35
/**
46
* Represents a mentionable user or team.
57
*/
@@ -20,10 +22,12 @@ export type Mentioned = [string, string];
2022
*/
2123
export type MentionChangeEvent = Parameters<OnChangeHandlerFunc>[0];
2224

23-
export type CreateError = {
24-
detail: {
25-
message: string;
26-
code: number;
27-
extra: any;
28-
};
29-
};
25+
export type CreateError =
26+
| {
27+
detail: {
28+
message: string;
29+
code: number;
30+
extra: any;
31+
};
32+
}
33+
| typeof DEFAULT_ERROR_JSON;

src/sentry/static/sentry/app/constants/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,7 @@ export const IS_ACCEPTANCE_TEST = !!process.env.IS_ACCEPTANCE_TEST;
248248
export const NODE_ENV = process.env.NODE_ENV;
249249
export const DISABLE_RR_WEB = !!process.env.DISABLE_RR_WEB;
250250
export const SPA_DSN = process.env.SPA_DSN;
251+
252+
export const DEFAULT_ERROR_JSON = {
253+
detail: t('Unknown error. Please try again.'),
254+
};

src/sentry/static/sentry/app/views/alerts/details/activity/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import {replaceAtArrayIndex} from 'app/utils/replaceAtArrayIndex';
1212
import {NoteType} from 'app/types/alerts';
1313
import {CreateError} from 'app/components/activity/note/types';
14-
import {t} from 'app/locale';
14+
import {DEFAULT_ERROR_JSON} from 'app/constants';
1515
import {uniqueId} from 'app/utils/guid';
1616
import ConfigStore from 'app/stores/configStore';
1717
import withApi from 'app/utils/withApi';
@@ -25,10 +25,6 @@ import {
2525
} from '../../types';
2626
import Activity from './activity';
2727

28-
function makeDefaultErrorJson() {
29-
return {detail: t('Unknown error. Please try again.')};
30-
}
31-
3228
type Activities = Array<ActivityType | ActivityType>;
3329

3430
type Props = {
@@ -146,7 +142,7 @@ class ActivityContainer extends React.PureComponent<Props, State> {
146142
activities,
147143
createBusy: false,
148144
createError: true,
149-
createErrorJSON: error.responseJSON || makeDefaultErrorJson(),
145+
createErrorJSON: error.responseJSON || DEFAULT_ERROR_JSON,
150146
};
151147
});
152148
}

src/sentry/static/sentry/app/views/organizationGroupDetails/groupActivity.jsx renamed to src/sentry/static/sentry/app/views/organizationGroupDetails/groupActivity.tsx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import PropTypes from 'prop-types';
21
import React from 'react';
2+
import {RouteComponentProps} from 'react-router/lib/Router';
33

44
import {
55
addErrorMessage,
@@ -15,27 +15,34 @@ import ConfigStore from 'app/stores/configStore';
1515
import ErrorBoundary from 'app/components/errorBoundary';
1616
import Note from 'app/components/activity/note';
1717
import NoteInputWithStorage from 'app/components/activity/note/inputWithStorage';
18-
import SentryTypes from 'app/sentryTypes';
1918
import withApi from 'app/utils/withApi';
2019
import withOrganization from 'app/utils/withOrganization';
20+
import {Activity, Group, Organization, User} from 'app/types';
21+
import {Client} from 'app/api';
22+
import {CreateError} from 'app/components/activity/note/types';
23+
import {DEFAULT_ERROR_JSON} from 'app/constants';
2124

2225
import GroupActivityItem from './groupActivityItem';
2326

24-
function makeDefaultErrorJson() {
25-
return {detail: t('Unknown error. Please try again.')};
26-
}
27+
type Props = {
28+
api: Client;
29+
organization: Organization;
30+
group: Group;
31+
} & RouteComponentProps<{orgId: string}, {}>;
2732

28-
class GroupActivity extends React.Component {
29-
// TODO(dcramer): only re-render on group/activity change
30-
static propTypes = {
31-
api: PropTypes.object,
32-
organization: SentryTypes.Organization.isRequired,
33-
group: SentryTypes.Group,
34-
};
33+
type State = {
34+
createBusy: boolean;
35+
error: boolean;
36+
errorJSON: CreateError | null;
37+
inputId: string;
38+
};
3539

36-
state = {
40+
class GroupActivity extends React.Component<Props, State> {
41+
// TODO(dcramer): only re-render on group/activity change
42+
state: State = {
3743
createBusy: false,
3844
error: false,
45+
errorJSON: null,
3946
inputId: uniqueId(),
4047
};
4148

@@ -80,7 +87,7 @@ class GroupActivity extends React.Component {
8087
this.setState({
8188
createBusy: false,
8289
error: true,
83-
errorJSON: error.responseJSON || makeDefaultErrorJson(),
90+
errorJSON: error.responseJSON || DEFAULT_ERROR_JSON,
8491
});
8592
addErrorMessage(t('Unable to post comment'));
8693
}
@@ -89,22 +96,15 @@ class GroupActivity extends React.Component {
8996
handleNoteUpdate = async (note, {modelId, text: oldText}) => {
9097
const {api, group} = this.props;
9198

92-
this.setState({
93-
updateBusy: true,
94-
});
9599
addLoadingMessage(t('Updating comment...'));
96100

97101
try {
98102
await updateNote(api, group, note, modelId, oldText);
99-
this.setState({
100-
updateBusy: false,
101-
});
102103
clearIndicators();
103104
} catch (error) {
104105
this.setState({
105-
updateBusy: false,
106106
error: true,
107-
errorJSON: error.responseJSON || makeDefaultErrorJson(),
107+
errorJSON: error.responseJSON || DEFAULT_ERROR_JSON,
108108
});
109109
addErrorMessage(t('Unable to update comment'));
110110
}
@@ -115,6 +115,7 @@ class GroupActivity extends React.Component {
115115
const me = ConfigStore.get('user');
116116
const projectSlugs = group && group.project ? [group.project.slug] : [];
117117
const noteProps = {
118+
minHeight: 140,
118119
group,
119120
projectSlugs,
120121
placeholder: t(
@@ -141,21 +142,21 @@ class GroupActivity extends React.Component {
141142
)}
142143
</ActivityItem>
143144

144-
{group.activity.map(item => {
145+
{group.activity.map((item: Activity) => {
145146
const authorName = item.user ? item.user.name : 'Sentry';
146147

147148
if (item.type === 'note') {
148149
return (
149150
<ErrorBoundary mini key={`note-${item.id}`}>
150151
<Note
152+
showTime={false}
151153
text={item.data.text}
152154
modelId={item.id}
153-
user={item.user}
155+
user={item.user as User}
154156
dateCreated={item.dateCreated}
155157
authorName={authorName}
156158
onDelete={this.handleNoteDelete}
157159
onUpdate={this.handleNoteUpdate}
158-
busy={this.state.updateBusy}
159160
{...noteProps}
160161
/>
161162
</ErrorBoundary>
@@ -164,7 +165,6 @@ class GroupActivity extends React.Component {
164165
return (
165166
<ErrorBoundary mini key={`item-${item.id}`}>
166167
<ActivityItem
167-
item={item}
168168
author={{type: item.user ? 'user' : 'system', user: item.user}}
169169
date={item.dateCreated}
170170
header={

0 commit comments

Comments
 (0)