[MM-21096] webapp: Migrate "components/suggestion/search_channel_with_permissions_provider.jsx" to Typescript (#23323)

* migrate to ts

* linting

* fix test

* refactor

* Remove accidental comments from merge

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Этот коммит содержится в:
Sai Deepesh
2023-06-01 22:15:50 +05:30
коммит произвёл GitHub
родитель 31c67fff4b
Коммит 5d54f599e5
2 изменённых файлов: 14 добавлений и 16 удалений

Просмотреть файл

@@ -1,12 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {getState} from 'stores/redux_store';
import store from 'stores/redux_store';
import mockStore from 'tests/test_store';
import SearchChannelWithPermissionsProvider from './search_channel_with_permissions_provider';
const getState = store.getState;
jest.mock('stores/redux_store', () => ({
dispatch: jest.fn(),
getState: jest.fn(),
@@ -114,7 +115,7 @@ describe('components/SearchChannelWithPermissionsProvider', () => {
},
};
let searchProvider;
let searchProvider: SearchChannelWithPermissionsProvider;
beforeEach(() => {
const channelSearchFunc = jest.fn();

Просмотреть файл

@@ -24,11 +24,15 @@ import {Constants} from 'utils/constants';
import Provider, {ResultsCallback} from './provider';
import {SuggestionContainer, SuggestionProps} from './suggestion';
type WrappedChannel = {
interface WrappedChannel {
channel: Channel;
name: string;
name: Channel['name'];
deactivated: boolean;
type: Channel['type'];
}
type ChannelSearchFunction = (teamId: string, channelPrefix: string) => Promise<ActionResult>
const SearchChannelWithPermissionsSuggestion = React.forwardRef<HTMLDivElement, SuggestionProps<WrappedChannel>>((props, ref) => {
const {item} = props;
const channel = item.channel;
@@ -97,9 +101,9 @@ function channelSearchSorter(wrappedA: WrappedChannel, wrappedB: WrappedChannel)
}
export default class SearchChannelWithPermissionsProvider extends Provider {
autocompleteChannelsForSearch: (channelId: string, userId: string) => Promise<ActionResult<Channel[]>>;
autocompleteChannelsForSearch: ChannelSearchFunction;
constructor(channelSearchFunc: SearchChannelWithPermissionsProvider['autocompleteChannelsForSearch']) {
constructor(channelSearchFunc: ChannelSearchFunction) {
super();
this.autocompleteChannelsForSearch = channelSearchFunc;
}
@@ -179,7 +183,7 @@ export default class SearchChannelWithPermissionsProvider extends Provider {
return;
}
const completedChannels: Record<string, boolean> = {};
const completedChannels: Record<Channel['id'], boolean> = {};
const channelFilter = this.makeChannelSearchFilter(channelPrefix);
@@ -187,10 +191,6 @@ export default class SearchChannelWithPermissionsProvider extends Provider {
const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true';
for (const channel of allChannels) {
if (!channel) {
continue;
}
if (completedChannels[channel.id]) {
continue;
}
@@ -199,10 +199,7 @@ export default class SearchChannelWithPermissionsProvider extends Provider {
const newChannel = Object.assign({}, channel);
const channelIsArchived = channel.delete_at !== 0;
const wrappedChannel = {
channel: newChannel,
name: newChannel.name,
};
const wrappedChannel = {channel: newChannel, name: newChannel.name, deactivated: false, type: newChannel.type};
if (!viewArchivedChannels && channelIsArchived) {
continue;
} else if (!members[channel.id]) {