mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Trigger update of sources from component
The old trigger in the dispatcher function led to updates even when the component was no longer mounted (aka displayed).
This commit is contained in:
@@ -7,7 +7,7 @@ import styled from "styled-components";
|
||||
import { binder } from "@scm-manager/ui-extensions";
|
||||
import { Repository, File } from "@scm-manager/ui-types";
|
||||
import { ErrorNotification, Loading, Notification } from "@scm-manager/ui-components";
|
||||
import { getFetchSourcesFailure, isFetchSourcesPending, getSources } from "../modules/sources";
|
||||
import { getFetchSourcesFailure, isFetchSourcesPending, getSources, fetchSources } from "../modules/sources";
|
||||
import FileTreeLeaf from "./FileTreeLeaf";
|
||||
|
||||
type Props = WithTranslation & {
|
||||
@@ -19,6 +19,8 @@ type Props = WithTranslation & {
|
||||
path: string;
|
||||
baseUrl: string;
|
||||
|
||||
updateSources: () => void;
|
||||
|
||||
// context props
|
||||
match: any;
|
||||
};
|
||||
@@ -40,6 +42,13 @@ export function findParent(path: string) {
|
||||
}
|
||||
|
||||
class FileTree extends React.Component<Props> {
|
||||
componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<{}>, snapshot?: any): void {
|
||||
const { tree, updateSources } = this.props;
|
||||
if (tree?._embedded?.children && tree._embedded.children.find(c => c.partialResult)) {
|
||||
setTimeout(updateSources, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { error, loading, tree } = this.props;
|
||||
|
||||
@@ -123,6 +132,14 @@ class FileTree extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = (dispatch: any, ownProps: Props) => {
|
||||
const { repository, revision, path } = ownProps;
|
||||
|
||||
const updateSources = () => dispatch(fetchSources(repository, revision, path, false));
|
||||
|
||||
return { updateSources };
|
||||
};
|
||||
|
||||
const mapStateToProps = (state: any, ownProps: Props) => {
|
||||
const { repository, revision, path } = ownProps;
|
||||
|
||||
@@ -141,5 +158,5 @@ const mapStateToProps = (state: any, ownProps: Props) => {
|
||||
|
||||
export default compose(
|
||||
withRouter,
|
||||
connect(mapStateToProps)
|
||||
connect(mapStateToProps, mapDispatchToProps)
|
||||
)(withTranslation("repos")(FileTree));
|
||||
|
||||
Reference in New Issue
Block a user