[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>
Этот коммит содержится в:
@@ -1,12 +1,13 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// 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 mockStore from 'tests/test_store';
|
||||||
|
|
||||||
import SearchChannelWithPermissionsProvider from './search_channel_with_permissions_provider';
|
import SearchChannelWithPermissionsProvider from './search_channel_with_permissions_provider';
|
||||||
|
|
||||||
|
const getState = store.getState;
|
||||||
|
|
||||||
jest.mock('stores/redux_store', () => ({
|
jest.mock('stores/redux_store', () => ({
|
||||||
dispatch: jest.fn(),
|
dispatch: jest.fn(),
|
||||||
getState: jest.fn(),
|
getState: jest.fn(),
|
||||||
@@ -114,7 +115,7 @@ describe('components/SearchChannelWithPermissionsProvider', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let searchProvider;
|
let searchProvider: SearchChannelWithPermissionsProvider;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const channelSearchFunc = jest.fn();
|
const channelSearchFunc = jest.fn();
|
||||||
@@ -24,11 +24,15 @@ import {Constants} from 'utils/constants';
|
|||||||
import Provider, {ResultsCallback} from './provider';
|
import Provider, {ResultsCallback} from './provider';
|
||||||
import {SuggestionContainer, SuggestionProps} from './suggestion';
|
import {SuggestionContainer, SuggestionProps} from './suggestion';
|
||||||
|
|
||||||
type WrappedChannel = {
|
interface WrappedChannel {
|
||||||
channel: Channel;
|
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 SearchChannelWithPermissionsSuggestion = React.forwardRef<HTMLDivElement, SuggestionProps<WrappedChannel>>((props, ref) => {
|
||||||
const {item} = props;
|
const {item} = props;
|
||||||
const channel = item.channel;
|
const channel = item.channel;
|
||||||
@@ -97,9 +101,9 @@ function channelSearchSorter(wrappedA: WrappedChannel, wrappedB: WrappedChannel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class SearchChannelWithPermissionsProvider extends Provider {
|
export default class SearchChannelWithPermissionsProvider extends Provider {
|
||||||
autocompleteChannelsForSearch: (channelId: string, userId: string) => Promise<ActionResult<Channel[]>>;
|
autocompleteChannelsForSearch: ChannelSearchFunction;
|
||||||
|
|
||||||
constructor(channelSearchFunc: SearchChannelWithPermissionsProvider['autocompleteChannelsForSearch']) {
|
constructor(channelSearchFunc: ChannelSearchFunction) {
|
||||||
super();
|
super();
|
||||||
this.autocompleteChannelsForSearch = channelSearchFunc;
|
this.autocompleteChannelsForSearch = channelSearchFunc;
|
||||||
}
|
}
|
||||||
@@ -179,7 +183,7 @@ export default class SearchChannelWithPermissionsProvider extends Provider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const completedChannels: Record<string, boolean> = {};
|
const completedChannels: Record<Channel['id'], boolean> = {};
|
||||||
|
|
||||||
const channelFilter = this.makeChannelSearchFilter(channelPrefix);
|
const channelFilter = this.makeChannelSearchFilter(channelPrefix);
|
||||||
|
|
||||||
@@ -187,10 +191,6 @@ export default class SearchChannelWithPermissionsProvider extends Provider {
|
|||||||
const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true';
|
const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true';
|
||||||
|
|
||||||
for (const channel of allChannels) {
|
for (const channel of allChannels) {
|
||||||
if (!channel) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (completedChannels[channel.id]) {
|
if (completedChannels[channel.id]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -199,10 +199,7 @@ export default class SearchChannelWithPermissionsProvider extends Provider {
|
|||||||
const newChannel = Object.assign({}, channel);
|
const newChannel = Object.assign({}, channel);
|
||||||
const channelIsArchived = channel.delete_at !== 0;
|
const channelIsArchived = channel.delete_at !== 0;
|
||||||
|
|
||||||
const wrappedChannel = {
|
const wrappedChannel = {channel: newChannel, name: newChannel.name, deactivated: false, type: newChannel.type};
|
||||||
channel: newChannel,
|
|
||||||
name: newChannel.name,
|
|
||||||
};
|
|
||||||
if (!viewArchivedChannels && channelIsArchived) {
|
if (!viewArchivedChannels && channelIsArchived) {
|
||||||
continue;
|
continue;
|
||||||
} else if (!members[channel.id]) {
|
} else if (!members[channel.id]) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user