mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Introduce stale while revalidate pattern (#1555)
This Improves the frontend performance with stale while revalidate pattern. There are noticeable performance problems in the frontend that needed addressing. While implementing the stale-while-revalidate pattern to display cached responses while re-fetching up-to-date data in the background, in the same vein we used the opportunity to remove legacy code involving redux as much as possible, cleaned up many components and converted them to functional react components. Co-authored-by: Sebastian Sdorra <sebastian.sdorra@cloudogu.com> Co-authored-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
This commit is contained in:
committed by
GitHub
parent
ad5c8102c0
commit
3a8d031ed5
@@ -21,49 +21,43 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
import React, { FC, useState } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import React, { FC, useEffect, useState } from "react";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Repository } from "@scm-manager/ui-types";
|
||||
import { ConfirmAlert, DeleteButton, ErrorNotification, Level } from "@scm-manager/ui-components";
|
||||
import { deleteRepo, getDeleteRepoFailure, isDeleteRepoPending } from "../modules/repos";
|
||||
import { useDeleteRepository } from "@scm-manager/ui-api";
|
||||
|
||||
type Props = {
|
||||
loading: boolean;
|
||||
error: Error;
|
||||
repository: Repository;
|
||||
confirmDialog?: boolean;
|
||||
deleteRepo: (p1: Repository, p2: () => void) => void;
|
||||
};
|
||||
|
||||
const DeleteRepo: FC<Props> = ({ confirmDialog = true, repository, deleteRepo, loading, error }: Props) => {
|
||||
const DeleteRepo: FC<Props> = ({ repository, confirmDialog = true }) => {
|
||||
const history = useHistory();
|
||||
const { isLoading, error, remove, isDeleted } = useDeleteRepository({
|
||||
onSuccess: () => {
|
||||
history.push("/repos/");
|
||||
}
|
||||
});
|
||||
const [showConfirmAlert, setShowConfirmAlert] = useState(false);
|
||||
const [t] = useTranslation("repos");
|
||||
const history = useHistory();
|
||||
|
||||
const deleted = () => {
|
||||
history.push("/repos/");
|
||||
};
|
||||
useEffect(() => {
|
||||
if (isDeleted) {
|
||||
setShowConfirmAlert(false);
|
||||
}
|
||||
}, [isDeleted]);
|
||||
|
||||
const deleteRepoCallback = () => {
|
||||
deleteRepo(repository, deleted);
|
||||
remove(repository);
|
||||
};
|
||||
|
||||
const confirmDelete = () => {
|
||||
setShowConfirmAlert(true);
|
||||
};
|
||||
|
||||
const isDeletable = () => {
|
||||
return repository._links.delete;
|
||||
};
|
||||
|
||||
const action = confirmDialog ? confirmDelete : deleteRepoCallback;
|
||||
|
||||
if (!isDeletable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (showConfirmAlert) {
|
||||
return (
|
||||
<ConfirmAlert
|
||||
@@ -96,28 +90,10 @@ const DeleteRepo: FC<Props> = ({ confirmDialog = true, repository, deleteRepo, l
|
||||
{t("deleteRepo.description")}
|
||||
</p>
|
||||
}
|
||||
right={<DeleteButton label={t("deleteRepo.button")} action={action} loading={loading} />}
|
||||
right={<DeleteButton label={t("deleteRepo.button")} action={action} loading={isLoading} />}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state: any, ownProps: Props) => {
|
||||
const { namespace, name } = ownProps.repository;
|
||||
const loading = isDeleteRepoPending(state, namespace, name);
|
||||
const error = getDeleteRepoFailure(state, namespace, name);
|
||||
return {
|
||||
loading,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch: any) => {
|
||||
return {
|
||||
deleteRepo: (repo: Repository, callback: () => void) => {
|
||||
dispatch(deleteRepo(repo, callback));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DeleteRepo);
|
||||
export default DeleteRepo;
|
||||
|
||||
Reference in New Issue
Block a user