Fix prop types for "markdown_image_expand" component (#23836)

Этот коммит содержится в:
M-ZubairAhmed
2023-06-27 10:06:50 +05:30
коммит произвёл GitHub
родитель 71c5a8512c
Коммит 7efbb11fae
3 изменённых файлов: 32 добавлений и 30 удалений

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

@@ -1,28 +1,37 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {bindActionCreators, Dispatch} from 'redux';
import {ReactNode} from 'react';
import {connect, ConnectedProps} from 'react-redux';
import {connect} from 'react-redux';
import {GenericAction} from 'mattermost-redux/types/actions';
import {Post} from '@mattermost/types/posts';
import {toggleInlineImageVisibility} from 'actions/post_actions';
import {isInlineImageVisible} from 'selectors/posts';
import {GlobalState} from 'types/store';
import MarkdownImageExpand, {Props} from './markdown_image_expand';
import MarkdownImageExpand from './markdown_image_expand';
const mapStateToProps = (state: GlobalState, {postId, imageKey}: Props) => {
export type OwnProps = {
postId: Post['id'];
imageKey: string;
alt: string;
onToggle?: (visible: boolean) => void;
children: ReactNode;
}
const mapStateToProps = (state: GlobalState, {postId, imageKey}: OwnProps) => {
return {
isExpanded: isInlineImageVisible(state, postId, imageKey),
};
};
const mapDispatchToProps = (dispatch: Dispatch<GenericAction>) => {
return {
actions: bindActionCreators({toggleInlineImageVisibility}, dispatch),
};
const mapDispatchToProps = {
toggleInlineImageVisibility,
};
export default connect(mapStateToProps, mapDispatchToProps)(MarkdownImageExpand);
const connector = connect(mapStateToProps, mapDispatchToProps);
export type PropsFromRedux = ConnectedProps<typeof connector>;
export default connector(MarkdownImageExpand);

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

@@ -17,7 +17,7 @@ describe('components/MarkdownImageExpand', () => {
isExpanded={false}
imageKey={'1'}
onToggle={toggleHandler}
actions={{toggleInlineImageVisibility: imageCollapseHandler}}
toggleInlineImageVisibility={imageCollapseHandler}
>{'An image to expand'}</MarkdownImageExpand>,
);
@@ -34,7 +34,7 @@ describe('components/MarkdownImageExpand', () => {
isExpanded={true}
imageKey={'1'}
onToggle={toggleHandler}
actions={{toggleInlineImageVisibility: imageCollapseHandler}}
toggleInlineImageVisibility={imageCollapseHandler}
>{'An image to expand'}</MarkdownImageExpand>,
);
@@ -51,7 +51,7 @@ describe('components/MarkdownImageExpand', () => {
isExpanded={true}
imageKey={'1'}
onToggle={toggleHandler}
actions={{toggleInlineImageVisibility: imageCollapseHandler}}
toggleInlineImageVisibility={imageCollapseHandler}
>{'An image to expand'}</MarkdownImageExpand>,
);
@@ -70,7 +70,7 @@ describe('components/MarkdownImageExpand', () => {
isExpanded={false}
imageKey={'1'}
onToggle={toggleHandler}
actions={{toggleInlineImageVisibility: imageCollapseHandler}}
toggleInlineImageVisibility={imageCollapseHandler}
>{'An image to expand'}</MarkdownImageExpand>,
);

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

@@ -2,25 +2,18 @@
// See LICENSE.txt for license information.
import React, {useEffect} from 'react';
import type {OwnProps, PropsFromRedux} from './index';
import './markdown_image_expand.scss';
export type Props = {
alt: string;
imageKey: string;
children: React.ReactNode;
isExpanded: boolean;
postId: string;
onToggle?: (isExpanded: boolean) => void;
actions: {
toggleInlineImageVisibility: (postId: string, imageKey: string) => void;
};
};
const MarkdownImageExpand: React.FC<Props> = ({children, alt, isExpanded, postId, actions, onToggle, imageKey}: Props) => {
const {toggleInlineImageVisibility} = actions;
type Props = OwnProps & PropsFromRedux;
const MarkdownImageExpand: React.FC<Props> = ({children, alt, isExpanded, postId, toggleInlineImageVisibility, onToggle, imageKey}: Props) => {
useEffect(() => {
onToggle?.(isExpanded);
if (onToggle) {
onToggle(isExpanded);
}
}, [isExpanded]);
const handleToggleButtonClick = () => {