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-983]: Resolved TS errors in action and disconnect modal files #1141

Merged
merged 1 commit into from
Dec 22, 2024
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
62 changes: 35 additions & 27 deletions webapp/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@
import {PostTypes} from 'mattermost-redux/action_types';
import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/common';

import {Action, Dispatch, Store} from 'redux';

import manifest from '../manifest';

import ActionTypes from 'action_types';
import {buildQueryString, doFetch, doFetchWithResponse} from 'client';
import {getInstalledInstances, getPluginServerRoute, getUserConnectedInstances} from 'selectors';
import {isDesktopApp, isMinimumDesktopAppVersion} from 'utils/user_agent';

import {
APIResponse,
AttachCommentRequest,
AutoCompleteParams,
ChannelSubscription,
CreateIssueRequest,
InstanceType,
ProjectMetadata,
SearchIssueParams,
SearchUsersParams,
} from 'types/model';

import {GlobalState} from 'types/store';

export const openConnectModal = () => {
return {
type: ActionTypes.OPEN_CONNECT_MODAL,
Expand All @@ -43,7 +51,7 @@ export const closeDisconnectModal = () => {
};
};

export const openCreateModal = (postId) => {
export const openCreateModal = (postId: string) => {
return {
type: ActionTypes.OPEN_CREATE_ISSUE_MODAL,
data: {
Expand All @@ -52,7 +60,7 @@ export const openCreateModal = (postId) => {
};
};

export const openCreateModalWithoutPost = (description, channelId) => (dispatch) => dispatch({
export const openCreateModalWithoutPost = (description: string, channelId: string) => (dispatch) => dispatch({
type: ActionTypes.OPEN_CREATE_ISSUE_MODAL_WITHOUT_POST,
data: {
description,
Expand All @@ -66,7 +74,7 @@ export const closeCreateModal = () => {
};
};

export const openAttachCommentToIssueModal = (postId) => {
export const openAttachCommentToIssueModal = (postId: string) => {
return {
type: ActionTypes.OPEN_ATTACH_COMMENT_TO_ISSUE_MODAL,
data: {
Expand All @@ -82,7 +90,7 @@ export const closeAttachCommentToIssueModal = () => {
};

export const fetchJiraIssueMetadataForProjects = (projectKeys: string[], instanceID: string) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
const projectKeysParam = projectKeys.join(',');
let data = null;
Expand All @@ -104,7 +112,7 @@ export const fetchJiraIssueMetadataForProjects = (projectKeys: string[], instanc
};

export const fetchJiraProjectMetadata = (instanceID: string) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
let data = null;
try {
Expand All @@ -124,7 +132,7 @@ export const fetchJiraProjectMetadata = (instanceID: string) => {
};

export const fetchJiraProjectMetadataForAllInstances = () => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const instances = getInstalledInstances(getState());
const promises = instances.map((instance) => dispatch(fetchJiraProjectMetadata(instance.instance_id)));
const responses = await Promise.all(promises) as APIResponse<ProjectMetadata>[];
Expand Down Expand Up @@ -152,28 +160,28 @@ export const fetchJiraProjectMetadataForAllInstances = () => {
};

export const searchIssues = (params: SearchIssueParams) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const url = getPluginServerRoute(getState()) + '/api/v2/get-search-issues';
return doFetchWithResponse(`${url}${buildQueryString(params)}`);
};
};

export const searchAutoCompleteFields = (params) => {
return async (dispatch, getState) => {
export const searchAutoCompleteFields = (params: AutoCompleteParams) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const url = getPluginServerRoute(getState()) + '/api/v2/get-search-autocomplete-fields';
return doFetchWithResponse(`${url}${buildQueryString(params)}`);
};
};

export const searchUsers = (params) => {
return async (dispatch, getState) => {
export const searchUsers = (params: SearchUsersParams) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const url = getPluginServerRoute(getState()) + '/api/v2/get-search-users';
return doFetchWithResponse(`${url}${buildQueryString(params)}`);
};
};

export const createIssue = (payload: CreateIssueRequest) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
try {
const data = await doFetch(`${baseUrl}/api/v2/create-issue`, {
Expand All @@ -188,8 +196,8 @@ export const createIssue = (payload: CreateIssueRequest) => {
};
};

export const attachCommentToIssue = (payload) => {
return async (dispatch, getState) => {
export const attachCommentToIssue = (payload: AttachCommentRequest) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
try {
const data = await doFetch(`${baseUrl}/api/v2/attach-comment-to-issue`, {
Expand All @@ -205,7 +213,7 @@ export const attachCommentToIssue = (payload) => {
};

export const createChannelSubscription = (subscription: ChannelSubscription) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
try {
const data = await doFetch(`${baseUrl}/api/v2/subscriptions/channel`, {
Expand All @@ -226,7 +234,7 @@ export const createChannelSubscription = (subscription: ChannelSubscription) =>
};

export const editChannelSubscription = (subscription: ChannelSubscription) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
try {
const data = await doFetch(`${baseUrl}/api/v2/subscriptions/channel`, {
Expand All @@ -247,7 +255,7 @@ export const editChannelSubscription = (subscription: ChannelSubscription) => {
};

export const deleteChannelSubscription = (subscription: ChannelSubscription) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
try {
await doFetch(`${baseUrl}/api/v2/subscriptions/channel/${subscription.id}?instance_id=${subscription.instance_id}`, {
Expand All @@ -267,7 +275,7 @@ export const deleteChannelSubscription = (subscription: ChannelSubscription) =>
};

export const fetchChannelSubscriptions = (channelId: string) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
const connectedInstances = getUserConnectedInstances(getState());

Expand Down Expand Up @@ -310,7 +318,7 @@ export const fetchChannelSubscriptions = (channelId: string) => {
};

export function getSettings() {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
let data;
const baseUrl = getPluginServerRoute(getState());
try {
Expand All @@ -331,7 +339,7 @@ export function getSettings() {
}

export function getConnected() {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
let data;
const baseUrl = getPluginServerRoute(getState());
try {
Expand All @@ -357,7 +365,7 @@ export function getConnected() {
}

export function disconnectUser(instanceID: string) {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
try {
await doFetch(`${baseUrl}/api/v3/disconnect`, {
Expand All @@ -373,7 +381,7 @@ export function disconnectUser(instanceID: string) {
}

export function handleConnectFlow(instanceID?: string) {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const state = getState();
const instances = getInstalledInstances(state);
const connectedInstances = getUserConnectedInstances(state);
Expand Down Expand Up @@ -432,7 +440,7 @@ export function handleConnectFlow(instanceID?: string) {
}

export function redirectConnect(instanceID: string) {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const instancePrefix = '/instance/' + btoa(instanceID);
const target = '/plugins/' + manifest.id + instancePrefix + '/user/connect';
window.open(target, '_blank');
Expand Down Expand Up @@ -462,7 +470,7 @@ export function handleConnectChange(store) {
};
}

export const openChannelSettings = (channelId) => {
export const openChannelSettings = (channelId: string) => {
return {
type: ActionTypes.OPEN_CHANNEL_SETTINGS,
data: {
Expand All @@ -477,7 +485,7 @@ export const closeChannelSettings = () => {
};
};

export function handleInstanceStatusChange(store) {
export function handleInstanceStatusChange(store: Store<object, Action<object>>) {
return (msg) => {
// Update the user's UI state when the instance state changes
getConnected()(store.dispatch, store.getState);
Expand All @@ -494,7 +502,7 @@ export function handleInstanceStatusChange(store) {
}

export function sendEphemeralPost(message: string, channelId?: string) {
return (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const timestamp = Date.now();
const post = {
id: 'jiraPlugin' + Date.now(),
Expand All @@ -518,7 +526,7 @@ export function sendEphemeralPost(message: string, channelId?: string) {
}

export const fetchIssueByKey = (issueKey: string, instanceID: string) => {
return async (dispatch, getState) => {
return async (dispatch: Dispatch, getState: GlobalState) => {
const baseUrl = getPluginServerRoute(getState());
let data = null;
const params = `issue_key=${issueKey}&instance_id=${instanceID}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class DisconnectModalForm extends PureComponent<Props, State> {
selectedInstance: '',
};

submit = async (e) => {
submit = async (e: React.FormEvent<HTMLFormElement>) => {
if (e.preventDefault) {
e.preventDefault();
}
Expand All @@ -46,7 +46,7 @@ export default class DisconnectModalForm extends PureComponent<Props, State> {
});
};

closeModal = (e) => {
closeModal = (e: React.FormEvent<HTMLFormElement>) => {
this.props.closeModal();
};

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/modals/disconnect_modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See LICENSE.txt for license information.

import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {Dispatch, bindActionCreators} from 'redux';

import {closeDisconnectModal, disconnectUser, sendEphemeralPost} from 'actions';
import {getUserConnectedInstances, isDisconnectModalVisible} from 'selectors';
Expand All @@ -18,7 +18,7 @@ const mapStateToProps = (state: GlobalState) => {
};
};

const mapDispatchToProps = (dispatch) => bindActionCreators({
const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators({
closeModal: closeDisconnectModal,
disconnectUser,
sendEphemeralPost,
Expand Down
12 changes: 12 additions & 0 deletions webapp/src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ export type SearchIssueParams = {
instance_id: string;
};

export type AutoCompleteParams = {
fieldValue: string;
fieldName: string;
instance_id: string;
};

export type SearchUsersParams = {
q: string;
project: string;
instance_id: string;
};

export type AttachCommentRequest = {
post_id: string;
current_team: string;
Expand Down
Loading