mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +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,28 +21,35 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import React, { FC, useEffect, useState } from "react";
|
||||
import { Repository } from "@scm-manager/ui-types";
|
||||
import { CUSTOM_NAMESPACE_STRATEGY } from "../modules/repos";
|
||||
import { Repository, CUSTOM_NAMESPACE_STRATEGY } from "@scm-manager/ui-types";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { InputField } from "@scm-manager/ui-components";
|
||||
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
||||
import * as validator from "./form/repositoryValidation";
|
||||
import { getNamespaceStrategies } from "../../admin/modules/namespaceStrategies";
|
||||
import { connect } from "react-redux";
|
||||
import { useNamespaceStrategies } from "@scm-manager/ui-api";
|
||||
|
||||
type Props = {
|
||||
repository: Repository;
|
||||
onChange: (repository: Repository) => void;
|
||||
namespaceStrategy: string;
|
||||
setValid: (valid: boolean) => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
const NamespaceAndNameFields: FC<Props> = ({ repository, onChange, namespaceStrategy, setValid, disabled }) => {
|
||||
const [t] = useTranslation("repos");
|
||||
const [namespaceValidationError, setNamespaceValidationError] = useState(false);
|
||||
const useNamespaceStrategy = () => {
|
||||
const { data } = useNamespaceStrategies();
|
||||
if (data) {
|
||||
return data.current;
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
const NamespaceAndNameFields: FC<Props> = ({ repository, onChange, setValid, disabled }) => {
|
||||
const namespaceStrategy = useNamespaceStrategy();
|
||||
const [nameValidationError, setNameValidationError] = useState(false);
|
||||
const [namespaceValidationError, setNamespaceValidationError] = useState(false);
|
||||
const [t] = useTranslation("repos");
|
||||
|
||||
useEffect(() => {
|
||||
if (repository.name) {
|
||||
@@ -93,6 +100,11 @@ const NamespaceAndNameFields: FC<Props> = ({ repository, onChange, namespaceStra
|
||||
return <ExtensionPoint name="repos.create.namespace" props={props} renderAll={false} />;
|
||||
};
|
||||
|
||||
// not yet loaded
|
||||
if (namespaceStrategy === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{renderNamespaceField()}
|
||||
@@ -109,11 +121,4 @@ const NamespaceAndNameFields: FC<Props> = ({ repository, onChange, namespaceStra
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state: any) => {
|
||||
const namespaceStrategy = getNamespaceStrategies(state).current;
|
||||
return {
|
||||
namespaceStrategy
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(NamespaceAndNameFields);
|
||||
export default NamespaceAndNameFields;
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
import React, { FC, useState } from "react";
|
||||
import { Trans, useTranslation, WithTranslation, withTranslation } from "react-i18next";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import classNames from "classnames";
|
||||
import styled from "styled-components";
|
||||
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
||||
import { Changeset, Link, ParentChangeset, Repository, Tag } from "@scm-manager/ui-types";
|
||||
import { Changeset, Link, ParentChangeset, Repository } from "@scm-manager/ui-types";
|
||||
import {
|
||||
AvatarImage,
|
||||
AvatarWrapper,
|
||||
@@ -42,18 +42,16 @@ import {
|
||||
Icon,
|
||||
Level,
|
||||
SignatureIcon,
|
||||
Tooltip,
|
||||
ErrorNotification,
|
||||
CreateTagModal
|
||||
Tooltip
|
||||
} from "@scm-manager/ui-components";
|
||||
import ContributorTable from "./ContributorTable";
|
||||
import { Link as ReactLink } from "react-router-dom";
|
||||
import CreateTagModal from "./CreateTagModal";
|
||||
|
||||
type Props = WithTranslation & {
|
||||
type Props = {
|
||||
changeset: Changeset;
|
||||
repository: Repository;
|
||||
fileControlFactory?: FileControlFactory;
|
||||
refetchChangeset?: () => void;
|
||||
};
|
||||
|
||||
const RightMarginP = styled.p`
|
||||
@@ -112,6 +110,7 @@ const ChangesetSummary = styled.div`
|
||||
|
||||
const SeparatedParents = styled.div`
|
||||
margin-left: 1em;
|
||||
|
||||
a + a:before {
|
||||
content: ",\\00A0";
|
||||
color: #4a4a4a;
|
||||
@@ -158,15 +157,15 @@ const Contributors: FC<{ changeset: Changeset }> = ({ changeset }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const ChangesetDetails: FC<Props> = ({ changeset, repository, fileControlFactory, t, refetchChangeset }) => {
|
||||
const ChangesetDetails: FC<Props> = ({ changeset, repository, fileControlFactory }) => {
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [isTagCreationModalVisible, setTagCreationModalVisible] = useState(false);
|
||||
const [error, setError] = useState<Error | undefined>();
|
||||
const [t] = useTranslation("repos");
|
||||
|
||||
const description = changesets.parseDescription(changeset.description);
|
||||
const id = <ChangesetId repository={repository} changeset={changeset} link={false} />;
|
||||
const date = <DateFromNow date={changeset.date} />;
|
||||
const parents = changeset._embedded.parents.map((parent: ParentChangeset, index: number) => (
|
||||
const parents = changeset._embedded.parents?.map((parent: ParentChangeset, index: number) => (
|
||||
<ReactLink title={parent.id} to={parent.id} key={index}>
|
||||
{parent.id.substring(0, 7)}
|
||||
</ReactLink>
|
||||
@@ -177,10 +176,6 @@ const ChangesetDetails: FC<Props> = ({ changeset, repository, fileControlFactory
|
||||
setCollapsed(!collapsed);
|
||||
};
|
||||
|
||||
if (error) {
|
||||
return <ErrorNotification error={error} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={classNames("content", "is-marginless")}>
|
||||
@@ -208,12 +203,12 @@ const ChangesetDetails: FC<Props> = ({ changeset, repository, fileControlFactory
|
||||
<p>
|
||||
<Trans i18nKey="repos:changeset.summary" components={[id, date]} />
|
||||
</p>
|
||||
{parents?.length > 0 && (
|
||||
{parents && parents?.length > 0 ? (
|
||||
<SeparatedParents>
|
||||
{t("changeset.parents.label", { count: parents?.length }) + ": "}
|
||||
{parents}
|
||||
</SeparatedParents>
|
||||
)}
|
||||
) : null}
|
||||
</ChangesetSummary>
|
||||
</div>
|
||||
<div className="media-right">
|
||||
@@ -235,15 +230,9 @@ const ChangesetDetails: FC<Props> = ({ changeset, repository, fileControlFactory
|
||||
)}
|
||||
{isTagCreationModalVisible && (
|
||||
<CreateTagModal
|
||||
revision={changeset.id}
|
||||
repository={repository}
|
||||
changeset={changeset}
|
||||
onClose={() => setTagCreationModalVisible(false)}
|
||||
onCreated={() => {
|
||||
refetchChangeset?.();
|
||||
setTagCreationModalVisible(false);
|
||||
}}
|
||||
onError={setError}
|
||||
tagCreationLink={(changeset._links["tag"] as Link).href}
|
||||
existingTagsLink={(repository._links["tags"] as Link).href}
|
||||
/>
|
||||
)}
|
||||
</article>
|
||||
@@ -285,4 +274,4 @@ const ChangesetDetails: FC<Props> = ({ changeset, repository, fileControlFactory
|
||||
);
|
||||
};
|
||||
|
||||
export default withTranslation("repos")(ChangesetDetails);
|
||||
export default ChangesetDetails;
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import React, { FC, useEffect, useState } from "react";
|
||||
import { Modal, InputField, Button, Loading, ErrorNotification } from "@scm-manager/ui-components";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Changeset, Repository } from "@scm-manager/ui-types";
|
||||
import { useCreateTag, useTags } from "@scm-manager/ui-api";
|
||||
import { validation } from "@scm-manager/ui-components/";
|
||||
|
||||
type Props = {
|
||||
changeset: Changeset;
|
||||
repository: Repository;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
const CreateTagModal: FC<Props> = ({ repository, changeset, onClose }) => {
|
||||
const { isLoading, error, data: tags } = useTags(repository);
|
||||
const { isLoading: isLoadingCreate, error: errorCreate, create, tag: createdTag } = useCreateTag(
|
||||
repository,
|
||||
changeset
|
||||
);
|
||||
const [t] = useTranslation("repos");
|
||||
const [newTagName, setNewTagName] = useState("");
|
||||
useEffect(() => {
|
||||
if (createdTag) {
|
||||
onClose();
|
||||
}
|
||||
}, [createdTag, onClose]);
|
||||
|
||||
const tagNames = tags?._embedded.tags.map(tag => tag.name);
|
||||
|
||||
let validationError = "";
|
||||
|
||||
if (tagNames !== undefined && newTagName !== "") {
|
||||
if (tagNames.includes(newTagName)) {
|
||||
validationError = "tags.create.form.field.name.error.exists";
|
||||
} else if (!validation.isBranchValid(newTagName)) {
|
||||
validationError = "tags.create.form.field.name.error.format";
|
||||
}
|
||||
}
|
||||
|
||||
let body;
|
||||
if (isLoading) {
|
||||
body = <Loading />;
|
||||
} else if (error) {
|
||||
body = <ErrorNotification error={error} />;
|
||||
} else if (errorCreate) {
|
||||
body = <ErrorNotification error={errorCreate} />;
|
||||
} else {
|
||||
body = (
|
||||
<>
|
||||
<InputField
|
||||
name="name"
|
||||
label={t("tags.create.form.field.name.label")}
|
||||
onChange={val => setNewTagName(val)}
|
||||
value={newTagName}
|
||||
validationError={!!validationError}
|
||||
errorMessage={t(validationError)}
|
||||
/>
|
||||
<div className="mt-6">{t("tags.create.hint")}</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={t("tags.create.title")}
|
||||
active={true}
|
||||
body={body}
|
||||
footer={
|
||||
<>
|
||||
<Button action={onClose}>{t("tags.create.cancel")}</Button>
|
||||
<Button
|
||||
color="success"
|
||||
action={() => create(newTagName)}
|
||||
loading={isLoadingCreate}
|
||||
disabled={isLoading || isLoadingCreate || !!validationError || newTagName.length === 0}
|
||||
>
|
||||
{t("tags.create.confirm")}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
closeFunction={onClose}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateTagModal;
|
||||
@@ -25,9 +25,8 @@ import React, { FC, useEffect, useState } from "react";
|
||||
import styled from "styled-components";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
||||
import { Repository, RepositoryType } from "@scm-manager/ui-types";
|
||||
import { IndexResources, Repository, RepositoryType, CUSTOM_NAMESPACE_STRATEGY } from "@scm-manager/ui-types";
|
||||
import { Checkbox, Level, Select, SubmitButton } from "@scm-manager/ui-components";
|
||||
import { CUSTOM_NAMESPACE_STRATEGY } from "../../modules/repos";
|
||||
import NamespaceAndNameFields from "../NamespaceAndNameFields";
|
||||
import RepositoryInformationForm from "../RepositoryInformationForm";
|
||||
|
||||
@@ -52,7 +51,7 @@ type Props = {
|
||||
repositoryTypes?: RepositoryType[];
|
||||
namespaceStrategy?: string;
|
||||
loading: boolean;
|
||||
indexResources?: any;
|
||||
indexResources?: IndexResources;
|
||||
};
|
||||
|
||||
type RepositoryCreation = Repository & {
|
||||
|
||||
Reference in New Issue
Block a user