mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 12:05:52 +01:00
Restructure global configuration forms for each repository type
Squash commits of branch feature/repository-type-configuration: - Refactor hg configuration form - Add support of description text for checkbox and input fields - Refactor git configuration form - Refactor svn configuration form - Add aria-describedby for checkbox and input fields - Change hgBinary can also be null - Fix naming of test - Fix spelling - Change logic of successfull notification to only be shown if the config rest api returns without an error Reviewed-by: Philipp Ahrendt <philipp.ahrendt@cloudogu.com>, Till-André Diegeler <till-andre.diegeler@cloudogu.com> Reviewed-by: Philipp Ahrendt <philipp.ahrendt@cloudogu.com>
This commit is contained in:
10
gradle/changelog/repository-type-config-forms.yaml
Normal file
10
gradle/changelog/repository-type-config-forms.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
- type: added
|
||||
description: Support of description text for input fields and checkboxes
|
||||
- type: added
|
||||
description: aria-describedby for input fields and checkboxes
|
||||
- type: changed
|
||||
description: Disabling git repositories is now the first setting within the configuration form
|
||||
- type: changed
|
||||
description: Disabling hg repositories is now the first setting within the configuration form
|
||||
- type: changed
|
||||
description: Disabling svn repositories is now the first setting within the configuration form
|
||||
@@ -14,13 +14,11 @@
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
import React, { FC, useEffect } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import React, { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useConfigLink } from "@scm-manager/ui-api";
|
||||
import { ConfigurationForm, InputField, Checkbox, validation } from "@scm-manager/ui-components";
|
||||
import { Title, useDocumentTitle } from "@scm-manager/ui-core";
|
||||
import { ConfigurationForm, Form, Title, useDocumentTitle } from "@scm-manager/ui-core";
|
||||
import { HalRepresentation } from "@scm-manager/ui-types";
|
||||
import { validation } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
link: string;
|
||||
@@ -40,62 +38,41 @@ const GitGlobalConfiguration: FC<Props> = ({ link }) => {
|
||||
const [t] = useTranslation("plugins");
|
||||
useDocumentTitle(t("scm-git-plugin.config.title"));
|
||||
|
||||
const { initialConfiguration, isReadOnly, update, ...formProps } = useConfigLink<Configuration>(link);
|
||||
const { formState, handleSubmit, register, reset } = useForm<Configuration>({ mode: "onChange" });
|
||||
|
||||
useEffect(() => {
|
||||
if (initialConfiguration) {
|
||||
reset(initialConfiguration);
|
||||
}
|
||||
}, [initialConfiguration, reset]);
|
||||
|
||||
const isValidDefaultBranch = (value: string) => {
|
||||
return validation.isBranchValid(value);
|
||||
const validateLfsWriteAuthorization = (value: string) => {
|
||||
const authorizationTime = parseInt(value);
|
||||
return Number.isInteger(authorizationTime) && authorizationTime > 0;
|
||||
};
|
||||
|
||||
return (
|
||||
<ConfigurationForm
|
||||
isValid={formState.isValid}
|
||||
isReadOnly={isReadOnly}
|
||||
onSubmit={handleSubmit(update)}
|
||||
{...formProps}
|
||||
>
|
||||
<ConfigurationForm<Configuration> link={link} translationPath={["plugins", "scm-git-plugin.config"]}>
|
||||
{({ watch }) => (
|
||||
<>
|
||||
<Title>{t("scm-git-plugin.config.title")}</Title>
|
||||
<InputField
|
||||
label={t("scm-git-plugin.config.gcExpression")}
|
||||
helpText={t("scm-git-plugin.config.gcExpressionHelpText")}
|
||||
disabled={isReadOnly}
|
||||
{...register("gcExpression")}
|
||||
/>
|
||||
<Checkbox
|
||||
label={t("scm-git-plugin.config.nonFastForwardDisallowed")}
|
||||
helpText={t("scm-git-plugin.config.nonFastForwardDisallowedHelpText")}
|
||||
disabled={isReadOnly}
|
||||
{...register("nonFastForwardDisallowed")}
|
||||
/>
|
||||
<InputField
|
||||
label={t("scm-git-plugin.config.defaultBranch")}
|
||||
helpText={t("scm-git-plugin.config.defaultBranchHelpText")}
|
||||
disabled={isReadOnly}
|
||||
validationError={!!formState.errors.defaultBranch}
|
||||
errorMessage={t("scm-git-plugin.config.defaultBranchValidationError")}
|
||||
{...register("defaultBranch", { validate: isValidDefaultBranch })}
|
||||
/>
|
||||
<InputField
|
||||
<Form.Row>
|
||||
<Form.Checkbox name="disabled" readOnly={!watch("allowDisable")} />
|
||||
</Form.Row>
|
||||
{!watch("disabled") ? (
|
||||
<>
|
||||
<Form.Row>
|
||||
<Form.Input name="gcExpression" />
|
||||
</Form.Row>
|
||||
<Form.Row>
|
||||
<Form.Checkbox name="nonFastForwardDisallowed" />
|
||||
</Form.Row>
|
||||
<Form.Row>
|
||||
<Form.Input name="defaultBranch" rules={{ required: true, validate: validation.isBranchValid }} />
|
||||
</Form.Row>
|
||||
<Form.Row>
|
||||
<Form.Input
|
||||
name="lfsWriteAuthorizationExpirationInMinutes"
|
||||
type="number"
|
||||
label={t("scm-git-plugin.config.lfsWriteAuthorizationExpirationInMinutes")}
|
||||
helpText={t("scm-git-plugin.config.lfsWriteAuthorizationExpirationInMinutesHelpText")}
|
||||
disabled={isReadOnly}
|
||||
validationError={!!formState.errors.lfsWriteAuthorizationExpirationInMinutes}
|
||||
errorMessage={t("scm-git-plugin.config.lfsWriteAuthorizationExpirationInMinutesValidationError")}
|
||||
{...register("lfsWriteAuthorizationExpirationInMinutes", { min: 1, required: true })}
|
||||
/>
|
||||
<Checkbox
|
||||
label={t("scm-git-plugin.config.disabled")}
|
||||
helpText={t("scm-git-plugin.config.disabledHelpText")}
|
||||
disabled={isReadOnly || !initialConfiguration?.allowDisable}
|
||||
{...register("disabled")}
|
||||
rules={{ required: true, validate: validateLfsWriteAuthorization }}
|
||||
/>
|
||||
</Form.Row>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</ConfigurationForm>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -21,18 +21,24 @@
|
||||
"config": {
|
||||
"link": "Git",
|
||||
"title": "Git Konfiguration",
|
||||
"gcExpression": "GC Cron Ausdruck",
|
||||
"gcExpressionHelpText": "Benutze Quartz Cron Ausdrücke (SECOND MINUTE HOUR DAYOFMONTH MONTH DAYOFWEEK), um git GC regelmäßig auszuführen.",
|
||||
"nonFastForwardDisallowed": "Deaktiviere \"Non Fast-Forward\"",
|
||||
"nonFastForwardDisallowedHelpText": "Git Pushes ablehnen, die nicht \"fast-forward\" sind, wie \"--force\".",
|
||||
"defaultBranch": "Default Branch",
|
||||
"defaultBranchHelpText": "Dieser Name wird bei der Initialisierung neuer Git Repositories genutzt. Er hat keine weiteren Auswirkungen (insbesondere hat er keinen Einfluss auf den Branchnamen bei leeren Repositories).",
|
||||
"defaultBranchValidationError": "Dies ist kein valider Branchname",
|
||||
"lfsWriteAuthorizationExpirationInMinutes": "Ablaufzeit für LFS Autorisierung",
|
||||
"lfsWriteAuthorizationExpirationInMinutesHelpText": "Ablaufzeit für den Autorisierungstoken in Minuten, der für LFS Speicheranfragen ausgestellt wird. Wenn der SCM-Manager hinter einem Reverse-Proxy mit Zwischenspeicherung (z. B. Nginx) betrieben wird, sollte dieser Wert auf die Zeit gesetzt werden, die ein LFS-Upload maximal benötigen kann.",
|
||||
"lfsWriteAuthorizationExpirationInMinutesValidationError": "Has to be at least 1 minute",
|
||||
"disabled": "Deaktiviert",
|
||||
"disabledHelpText": "Aktiviere oder deaktiviere das Git Plugin. Nur erlaubt, wenn keine Git Repositories existieren.",
|
||||
"gcExpression": {
|
||||
"label": "GC Cron Ausdruck",
|
||||
"descriptionText": "Benutze Quartz Cron Ausdrücke (SECOND MINUTE HOUR DAYOFMONTH MONTH DAYOFWEEK), um git GC regelmäßig auszuführen."
|
||||
},
|
||||
"nonFastForwardDisallowed": {
|
||||
"label": "Deaktiviere \"Non Fast-Forward\"",
|
||||
"descriptionText": "Git Pushes ablehnen, die nicht \"fast-forward\" sind, wie \"--force\"."
|
||||
},
|
||||
"defaultBranch": {
|
||||
"label": "Default Branch für neu initialisierte Repositorys"
|
||||
},
|
||||
"lfsWriteAuthorizationExpirationInMinutes": {
|
||||
"label": "Ablaufzeit für LFS Autorisierung",
|
||||
"descriptionText": "Ablaufzeit für den Autorisierungstoken in Minuten, der für LFS Speicheranfragen ausgestellt wird. Wenn der SCM-Manager hinter einem Reverse-Proxy mit Zwischenspeicherung (z. B. Nginx) betrieben wird, sollte dieser Wert auf die Zeit gesetzt werden, die ein LFS-Upload maximal benötigen kann."
|
||||
},
|
||||
"disabled": {
|
||||
"label": "Deaktiviere das Git Plugin. Nur erlaubt, wenn keine Git Repositories existieren."
|
||||
},
|
||||
"submit": "Speichern"
|
||||
},
|
||||
"repoConfig": {
|
||||
|
||||
@@ -21,18 +21,24 @@
|
||||
"config": {
|
||||
"link": "Git",
|
||||
"title": "Git Configuration",
|
||||
"gcExpression": "GC Cron Expression",
|
||||
"gcExpressionHelpText": "Use Quartz Cron Expressions (SECOND MINUTE HOUR DAYOFMONTH MONTH DAYOFWEEK) to run git gc in intervals.",
|
||||
"nonFastForwardDisallowed": "Disallow Non Fast-Forward",
|
||||
"nonFastForwardDisallowedHelpText": "Reject git pushes which are non fast-forward such as --force.",
|
||||
"defaultBranch": "Default Branch",
|
||||
"defaultBranchHelpText": "This name will be used for the initialization of new git repositories. It has no effect otherwise (especially this cannot change the initial branch name for empty repositories).",
|
||||
"defaultBranchValidationError": "This is not a valid branch name",
|
||||
"lfsWriteAuthorizationExpirationInMinutes": "LFS authorization expiration",
|
||||
"lfsWriteAuthorizationExpirationInMinutesHelpText": "Expiration time of the authorization token generated for LFS put requests in minutes. If SCM-Manager is run behind a reverse proxy that buffers http requests (eg. Nginx), this should set up to the time, an LFS upload may take at maximum.",
|
||||
"lfsWriteAuthorizationExpirationInMinutesValidationError": "Has to be at least 1 minute",
|
||||
"disabled": "Disabled",
|
||||
"disabledHelpText": "Enable or disable the Git plugin. Only allowed if no Git Repositories exist.",
|
||||
"gcExpression": {
|
||||
"label": "GC Cron Expression",
|
||||
"descriptionText": "Use Quartz Cron Expressions (SECOND MINUTE HOUR DAYOFMONTH MONTH DAYOFWEEK) to run git gc in intervals."
|
||||
},
|
||||
"nonFastForwardDisallowed": {
|
||||
"label": "Disallow Non Fast-Forward",
|
||||
"descriptionText": "Reject git pushes which are non fast-forward such as --force."
|
||||
},
|
||||
"defaultBranch": {
|
||||
"label": "Default branch for newly initialized repositories"
|
||||
},
|
||||
"lfsWriteAuthorizationExpirationInMinutes": {
|
||||
"label": "LFS authorization expiration",
|
||||
"descriptionText": "Expiration time of the authorization token generated for LFS put requests in minutes. If SCM-Manager is run behind a reverse proxy that buffers http requests (eg. Nginx), this should set up to the time, an LFS upload may take at maximum."
|
||||
},
|
||||
"disabled": {
|
||||
"label": "Disable the Git plugin. Only allowed if no Git Repositories exist."
|
||||
},
|
||||
"submit": "Submit"
|
||||
},
|
||||
"repoConfig": {
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
"typecheck": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@scm-manager/ui-plugins": "3.7.2-SNAPSHOT"
|
||||
"@scm-manager/ui-plugins": "3.7.2-SNAPSHOT",
|
||||
"react-query": "^3.25.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@scm-manager/babel-preset": "^2.13.1",
|
||||
|
||||
@@ -152,7 +152,7 @@ public class HgConfigResource {
|
||||
HgGlobalConfig config = dtoToConfigMapper.map(configDto);
|
||||
ConfigurationPermissions.write(config).check();
|
||||
|
||||
if (config.getHgBinary() != null) {
|
||||
if (!config.isDisabled() && config.getHgBinary() != null) {
|
||||
HgVerifier.HgVerifyStatus verifyStatus = new HgVerifier().verify(config.getHgBinary());
|
||||
doThrow()
|
||||
.violation(verifyStatus.getDescription())
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - present Cloudogu GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
import React, { FC, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link, Links } from "@scm-manager/ui-types";
|
||||
import { apiClient, Button, Checkbox, InputField } from "@scm-manager/ui-components";
|
||||
|
||||
type Configuration = {
|
||||
disabled: boolean;
|
||||
allowDisable: boolean;
|
||||
hgBinary: string;
|
||||
encoding: string;
|
||||
showRevisionInId: boolean;
|
||||
enableHttpPostArgs: boolean;
|
||||
_links: Links;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
initialConfiguration: Configuration;
|
||||
readOnly: boolean;
|
||||
onConfigurationChange: (p1: Configuration, p2: boolean) => void;
|
||||
};
|
||||
|
||||
const HgConfigurationForm: FC<Props> = ({ initialConfiguration, onConfigurationChange, readOnly }) => {
|
||||
const [validationErrors, setValidationErrors] = useState<string[]>([]);
|
||||
const [configuration, setConfiguration] = useState(initialConfiguration);
|
||||
const [t] = useTranslation("plugins");
|
||||
|
||||
useEffect(() => setConfiguration(initialConfiguration), [initialConfiguration]);
|
||||
useEffect(() => onConfigurationChange(configuration, updateValidationStatus()), [configuration]);
|
||||
|
||||
const updateValidationStatus = () => {
|
||||
const errors = [];
|
||||
if (!configuration.hgBinary) {
|
||||
errors.push("hgBinary");
|
||||
}
|
||||
if (!configuration.encoding) {
|
||||
errors.push("encoding");
|
||||
}
|
||||
|
||||
setValidationErrors(errors);
|
||||
return errors.length === 0;
|
||||
};
|
||||
|
||||
const hasValidationError = (name: string) => {
|
||||
return validationErrors.indexOf(name) >= 0;
|
||||
};
|
||||
|
||||
const triggerAutoConfigure = () => {
|
||||
apiClient
|
||||
.put(
|
||||
(initialConfiguration._links.autoConfiguration as Link).href,
|
||||
{ ...initialConfiguration, hgBinary: configuration.hgBinary },
|
||||
"application/vnd.scmm-hgConfig+json;v=2"
|
||||
)
|
||||
.then(() =>
|
||||
apiClient
|
||||
.get((initialConfiguration._links.self as Link).href)
|
||||
.then(r => r.json())
|
||||
.then((config: Configuration) => setConfiguration({ ...configuration, hgBinary: config.hgBinary }))
|
||||
)
|
||||
.then(() => onConfigurationChange(configuration, updateValidationStatus()));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="is-flex is-flex-direction-column">
|
||||
<InputField
|
||||
name="hgBinary"
|
||||
label={t("scm-hg-plugin.config.hgBinary")}
|
||||
helpText={t("scm-hg-plugin.config.hgBinaryHelpText")}
|
||||
value={configuration.hgBinary}
|
||||
onChange={value => setConfiguration({ ...configuration, hgBinary: value })}
|
||||
validationError={hasValidationError("hgBinary")}
|
||||
errorMessage={t("scm-hg-plugin.config.required")}
|
||||
disabled={readOnly}
|
||||
/>
|
||||
<InputField
|
||||
name="encoding"
|
||||
label={t("scm-hg-plugin.config.encoding")}
|
||||
helpText={t("scm-hg-plugin.config.encodingHelpText")}
|
||||
value={configuration.encoding}
|
||||
onChange={value => setConfiguration({ ...configuration, encoding: value })}
|
||||
validationError={hasValidationError("encoding")}
|
||||
errorMessage={t("scm-hg-plugin.config.required")}
|
||||
disabled={readOnly}
|
||||
/>
|
||||
<Checkbox
|
||||
name="showRevisionInId"
|
||||
label={t("scm-hg-plugin.config.showRevisionInId")}
|
||||
helpText={t("scm-hg-plugin.config.showRevisionInIdHelpText")}
|
||||
checked={configuration.showRevisionInId}
|
||||
onChange={value => setConfiguration({ ...configuration, showRevisionInId: value })}
|
||||
disabled={readOnly}
|
||||
/>
|
||||
<Checkbox
|
||||
name="enableHttpPostArgs"
|
||||
label={t("scm-hg-plugin.config.enableHttpPostArgs")}
|
||||
helpText={t("scm-hg-plugin.config.enableHttpPostArgsHelpText")}
|
||||
checked={configuration.enableHttpPostArgs}
|
||||
onChange={value => setConfiguration({ ...configuration, enableHttpPostArgs: value })}
|
||||
disabled={readOnly}
|
||||
/>
|
||||
<Checkbox
|
||||
name="disabled"
|
||||
label={t("scm-hg-plugin.config.disabled")}
|
||||
helpText={t("scm-hg-plugin.config.disabledHelpText")}
|
||||
checked={configuration.disabled}
|
||||
onChange={value => {
|
||||
setConfiguration({ ...configuration, disabled: value });
|
||||
}}
|
||||
disabled={readOnly || !configuration.allowDisable}
|
||||
/>
|
||||
<Button
|
||||
className="is-align-self-flex-end"
|
||||
disabled={!initialConfiguration?._links?.autoConfiguration}
|
||||
action={() => triggerAutoConfigure()}
|
||||
>
|
||||
{t("scm-hg-plugin.config.autoConfigure")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default HgConfigurationForm;
|
||||
@@ -16,23 +16,55 @@
|
||||
|
||||
import React, { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Configuration } from "@scm-manager/ui-components";
|
||||
import { Title, useDocumentTitle } from "@scm-manager/ui-core";
|
||||
import HgConfigurationForm from "./HgConfigurationForm";
|
||||
import { Button, ConfigurationForm, Form, Title, useDocumentTitle } from "@scm-manager/ui-core";
|
||||
import { SmallLoadingSpinner, validation } from "@scm-manager/ui-components";
|
||||
import { HgGlobalConfigurationDto, useHgAutoConfiguration } from "./hooks";
|
||||
|
||||
type Props = {
|
||||
link: string;
|
||||
};
|
||||
|
||||
const HgGlobalConfiguration: FC<Props> = ({ link }) => {
|
||||
const { mutate: triggerAutoConfiguration, isLoading: isAutoConfigLoading } = useHgAutoConfiguration(link);
|
||||
const [t] = useTranslation("plugins");
|
||||
useDocumentTitle(t("scm-hg-plugin.config.title"));
|
||||
|
||||
const isHgBinaryValid = (hgBinaryPath: string | undefined | null) => {
|
||||
return !hgBinaryPath || validation.isPathValid(hgBinaryPath);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ConfigurationForm<HgGlobalConfigurationDto> link={link} translationPath={["plugins", "scm-hg-plugin.config"]}>
|
||||
{({ watch, getValues }) => (
|
||||
<>
|
||||
<Title>{t("scm-hg-plugin.config.title")}</Title>
|
||||
<Configuration link={link} render={(props: any) => <HgConfigurationForm {...props} />} />
|
||||
</div>
|
||||
<Form.Row>
|
||||
<Form.Checkbox name="disabled" readOnly={!watch("allowDisable")} />
|
||||
</Form.Row>
|
||||
{!watch("disabled") ? (
|
||||
<>
|
||||
<Form.Row>
|
||||
<Form.Input name="hgBinary" rules={{ validate: isHgBinaryValid }} />
|
||||
</Form.Row>
|
||||
<Form.Row>
|
||||
<Form.Input name="encoding" />
|
||||
</Form.Row>
|
||||
<Form.Row>
|
||||
<Form.Checkbox name="showRevisionInId" />
|
||||
</Form.Row>
|
||||
<Form.Row>
|
||||
<Form.Checkbox name="enableHttpPostArgs" />
|
||||
</Form.Row>
|
||||
<Form.Row className="is-justify-content-flex-end">
|
||||
<Button className="mr-2" onClick={() => triggerAutoConfiguration(getValues())}>
|
||||
{isAutoConfigLoading ? <SmallLoadingSpinner /> : t("scm-hg-plugin.config.autoConfigure")}
|
||||
</Button>
|
||||
</Form.Row>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</ConfigurationForm>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -62,8 +62,7 @@ const HgRepositoryConfigurationForm: FC<Props> = ({ repository }) => {
|
||||
{updated ? <Notification type="info">{t("scm-hg-plugin.config.success")}</Notification> : null}
|
||||
<InputField
|
||||
name="encoding"
|
||||
label={t("scm-hg-plugin.config.encoding")}
|
||||
helpText={t("scm-hg-plugin.config.encodingHelpText")}
|
||||
label={t("scm-hg-plugin.config.encoding.label")}
|
||||
value={configuration.encoding || ""}
|
||||
onChange={encodingChanged}
|
||||
disabled={readOnly}
|
||||
|
||||
@@ -17,11 +17,41 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { apiClient } from "@scm-manager/ui-components";
|
||||
import { HalRepresentation, Link, Repository } from "@scm-manager/ui-types";
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
|
||||
export type HgRepositoryConfiguration = HalRepresentation & {
|
||||
encoding?: string;
|
||||
};
|
||||
|
||||
export type HgGlobalConfigurationDto = HalRepresentation & {
|
||||
disabled: boolean;
|
||||
allowDisable: boolean;
|
||||
encoding: string;
|
||||
hgBinary?: string | null;
|
||||
showRevisionInId: boolean;
|
||||
enableHttpPostArgs: boolean;
|
||||
};
|
||||
|
||||
export const useHgAutoConfiguration = (configLink: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
const { mutate, isLoading } = useMutation<unknown, Error, HgGlobalConfigurationDto>(
|
||||
(config) => apiClient.put(requiredLink(config, "autoConfiguration"), config),
|
||||
{
|
||||
onSuccess: () => {
|
||||
return queryClient.invalidateQueries(["configLink", configLink]);
|
||||
},
|
||||
}
|
||||
);
|
||||
return { mutate, isLoading };
|
||||
};
|
||||
|
||||
const requiredLink = (halObject: HalRepresentation, linkName: string): string => {
|
||||
if (!halObject._links[linkName]) {
|
||||
throw new Error("Could not find link: " + linkName);
|
||||
}
|
||||
return (halObject._links[linkName] as Link).href;
|
||||
};
|
||||
|
||||
export const useHgRepositoryConfiguration = (repository: Repository) => {
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
const [data, setData] = useState<HgRepositoryConfiguration | null>(null);
|
||||
|
||||
@@ -11,17 +11,22 @@
|
||||
"config": {
|
||||
"link": "Mercurial",
|
||||
"title": "Mercurial Konfiguration",
|
||||
"hgBinary": "HG Binary",
|
||||
"hgBinaryHelpText": "Pfad des Mercurial Binary",
|
||||
"encoding": "Encoding",
|
||||
"encodingHelpText": "Repository Encoding",
|
||||
"showRevisionInId": "Revision anzeigen",
|
||||
"showRevisionInIdHelpText": "Die Revision als Teil der Node ID anzeigen",
|
||||
"enableHttpPostArgs": "HttpPostArgs Protocol aktivieren",
|
||||
"enableHttpPostArgsHelpText": "Aktiviert das experimentelle HttpPostArgs Protokoll von Mercurial. Das HttpPostArgs Protokoll verwendet den Post Request Body anstatt des HTTP Headers um Meta Informationen zu versenden. Dieses Vorgehen reduziert die Header Größe der Mercurial Requests. HttpPostArgs wird seit Mercurial 3.8 unterstützt.",
|
||||
"disabled": "Deaktiviert",
|
||||
"disabledHelpText": "Aktiviert oder deaktiviert das Mercurial Plugin. Nur erlaubt, wenn keine Mercurial Repositories existieren.",
|
||||
"required": "Dieser Konfigurationswert wird benötigt",
|
||||
"disabled": {
|
||||
"label": "Deaktiviert das Mercurial Plugin. Nur erlaubt, wenn keine Mercurial Repositories existieren."
|
||||
},
|
||||
"hgBinary": {
|
||||
"label": "Pfad des Mercurial Binary"
|
||||
},
|
||||
"encoding": {
|
||||
"label": "Repository Encoding"
|
||||
},
|
||||
"showRevisionInId": {
|
||||
"label": "Die Revision als Teil der Node ID anzeigen"
|
||||
},
|
||||
"enableHttpPostArgs": {
|
||||
"label": "HttpPostArgs Protocol aktivieren",
|
||||
"descriptionText": "Aktiviert das experimentelle HttpPostArgs Protokoll von Mercurial. Das HttpPostArgs Protokoll verwendet den Post Request Body anstatt des HTTP Headers um Meta Informationen zu versenden. Dieses Vorgehen reduziert die Header Größe der Mercurial Requests. HttpPostArgs wird seit Mercurial 3.8 unterstützt."
|
||||
},
|
||||
"submit": "Speichern",
|
||||
"success": "Einstellungen wurden erfolgreich geändert",
|
||||
"autoConfigure": "Mercurial automatisch konfigurieren"
|
||||
|
||||
@@ -11,17 +11,22 @@
|
||||
"config": {
|
||||
"link": "Mercurial",
|
||||
"title": "Mercurial Configuration",
|
||||
"hgBinary": "HG Binary",
|
||||
"hgBinaryHelpText": "Location of Mercurial binary",
|
||||
"encoding": "Encoding",
|
||||
"encodingHelpText": "Repository Encoding",
|
||||
"showRevisionInId": "Show Revision",
|
||||
"showRevisionInIdHelpText": "Show revision as part of the node id",
|
||||
"enableHttpPostArgs": "Enable HttpPostArgs Protocol",
|
||||
"enableHttpPostArgsHelpText": "Enables the experimental HttpPostArgs Protocol of mercurial. The HttpPostArgs Protocol uses the body of post requests to send the meta information instead of http headers. This helps to reduce the header size of mercurial requests. HttpPostArgs is supported since mercurial 3.8.",
|
||||
"disabled": "Disabled",
|
||||
"disabledHelpText": "Enable or disable the Mercurial plugin. Only allowed if no Mercurial repositories exist.",
|
||||
"required": "This configuration value is required",
|
||||
"disabled": {
|
||||
"label": "Disable the Mercurial plugin. Only allowed if no Mercurial repositories exist."
|
||||
},
|
||||
"hgBinary": {
|
||||
"label": "Path to the mercurial binary"
|
||||
},
|
||||
"encoding": {
|
||||
"label": "Repository encoding"
|
||||
},
|
||||
"showRevisionInId": {
|
||||
"label": "Show revision as part of the node id"
|
||||
},
|
||||
"enableHttpPostArgs": {
|
||||
"label": "Enable HttpPostArgs Protocol",
|
||||
"descriptionText": "Enables the experimental HttpPostArgs Protocol of mercurial. The HttpPostArgs Protocol uses the body of post requests to send the meta information instead of http headers. This helps to reduce the header size of mercurial requests. HttpPostArgs is supported since mercurial 3.8."
|
||||
},
|
||||
"submit": "Submit",
|
||||
"success": "Configuration changed successfully",
|
||||
"autoConfigure": "Configure Mercurial Automatically"
|
||||
|
||||
@@ -161,6 +161,13 @@ public class HgConfigResourceTest {
|
||||
assertEquals(400, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "writeOnly")
|
||||
public void shouldUpdateInvalidBinaryIfConfigIsDisabled() throws URISyntaxException {
|
||||
MockHttpResponse response = put("{\"disabled\": true, \"hgBinary\":\"3.2.1\"}");
|
||||
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readOnly")
|
||||
public void shouldNotUpdateConfigWhenNotAuthorized() throws URISyntaxException, UnsupportedEncodingException {
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - present Cloudogu GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
import React, { FC, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Links } from "@scm-manager/ui-types";
|
||||
import { Checkbox, Select } from "@scm-manager/ui-components";
|
||||
|
||||
type Configuration = {
|
||||
disabled: boolean;
|
||||
allowDisable: boolean;
|
||||
compatibility: string;
|
||||
enabledGZip: boolean;
|
||||
_links: Links;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
initialConfiguration: Configuration;
|
||||
readOnly: boolean;
|
||||
onConfigurationChange: (p1: Configuration, p2: boolean) => void;
|
||||
};
|
||||
|
||||
const SvnConfigurationForm: FC<Props> = ({ initialConfiguration, readOnly, onConfigurationChange }) => {
|
||||
const [t] = useTranslation("plugins");
|
||||
const [configuration, setConfiguration] = useState(initialConfiguration);
|
||||
|
||||
useEffect(() => setConfiguration(initialConfiguration), [initialConfiguration]);
|
||||
useEffect(() => onConfigurationChange(configuration, true), [configuration]);
|
||||
|
||||
const options = ["NONE", "PRE14", "PRE15", "PRE16", "PRE17", "WITH17"].map((option: string) => ({
|
||||
value: option,
|
||||
label: t("scm-svn-plugin.config.compatibility-values." + option.toLowerCase())
|
||||
}));
|
||||
|
||||
return (
|
||||
<>
|
||||
<Select
|
||||
name="compatibility"
|
||||
label={t("scm-svn-plugin.config.compatibility")}
|
||||
helpText={t("scm-svn-plugin.config.compatibilityHelpText")}
|
||||
value={configuration.compatibility}
|
||||
options={options}
|
||||
onChange={option => setConfiguration({ ...configuration, compatibility: option })}
|
||||
/>
|
||||
<Checkbox
|
||||
name="enabledGZip"
|
||||
label={t("scm-svn-plugin.config.enabledGZip")}
|
||||
helpText={t("scm-svn-plugin.config.enabledGZipHelpText")}
|
||||
checked={configuration.enabledGZip}
|
||||
onChange={value => setConfiguration({ ...configuration, enabledGZip: value })}
|
||||
disabled={readOnly}
|
||||
/>
|
||||
<Checkbox
|
||||
name="disabled"
|
||||
label={t("scm-svn-plugin.config.disabled")}
|
||||
helpText={t("scm-svn-plugin.config.disabledHelpText")}
|
||||
checked={configuration.disabled}
|
||||
onChange={value => setConfiguration({ ...configuration, disabled: value })}
|
||||
disabled={readOnly || !configuration.allowDisable}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SvnConfigurationForm;
|
||||
@@ -17,22 +17,51 @@
|
||||
import React, { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Configuration } from "@scm-manager/ui-components";
|
||||
import { Title, useDocumentTitle } from "@scm-manager/ui-core";
|
||||
import SvnConfigurationForm from "./SvnConfigurationForm";
|
||||
import { ConfigurationForm, Title, useDocumentTitle, Form } from "@scm-manager/ui-core";
|
||||
import { HalRepresentation } from "@scm-manager/ui-types";
|
||||
|
||||
type Props = {
|
||||
link: string;
|
||||
};
|
||||
|
||||
type Configuration = {
|
||||
disabled: boolean;
|
||||
allowDisable: boolean;
|
||||
compatibility: string;
|
||||
enabledGZip: boolean;
|
||||
} & HalRepresentation;
|
||||
|
||||
const SvnGlobalConfiguration: FC<Props> = ({ link }) => {
|
||||
const [t] = useTranslation("plugins");
|
||||
useDocumentTitle(t("scm-svn-plugin.config.title"));
|
||||
|
||||
const compatibilityOptions = ["NONE", "PRE14", "PRE15", "PRE16", "PRE17", "WITH17"].map((option: string) => (
|
||||
<option value={option} key={`compatibility-${option}`}>
|
||||
{t("scm-svn-plugin.config.compatibility-values." + option.toLowerCase())}
|
||||
</option>
|
||||
));
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ConfigurationForm<Configuration> link={link} translationPath={["plugins", "scm-svn-plugin.config"]}>
|
||||
{({ watch }) => (
|
||||
<>
|
||||
<Title>{t("scm-svn-plugin.config.title")}</Title>
|
||||
<Configuration link={link} render={(props: any) => <SvnConfigurationForm {...props} />} />
|
||||
</div>
|
||||
<Form.Row>
|
||||
<Form.Checkbox name="disabled" readOnly={!watch("allowDisable")} />
|
||||
</Form.Row>
|
||||
{!watch("disabled") ? (
|
||||
<>
|
||||
<Form.Row>
|
||||
<Form.Select name="compatibility">{compatibilityOptions}</Form.Select>
|
||||
</Form.Row>
|
||||
<Form.Row>
|
||||
<Form.Checkbox name="enabledGZip" />
|
||||
</Form.Row>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</ConfigurationForm>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
"config": {
|
||||
"link": "Subversion",
|
||||
"title": "Subversion Konfiguration",
|
||||
"compatibility": "Version Kompatibilität",
|
||||
"compatibilityHelpText": "Gibt an, mit welcher Subversion Version die Repositories kompatibel sind.",
|
||||
"compatibility": {
|
||||
"label": "Versionskompatibilität für jedes Subversion Repository"
|
||||
},
|
||||
"compatibility-values": {
|
||||
"none": "Keine Kompatibilität",
|
||||
"pre14": "Vor 1.4 kompatibel",
|
||||
@@ -16,11 +17,12 @@
|
||||
"pre17": "Vor 1.7 kompatibel",
|
||||
"with17": "Mit 1.7 kompatibel"
|
||||
},
|
||||
"enabledGZip": "GZip Compression aktivieren",
|
||||
"enabledGZipHelpText": "Aktiviert GZip Kompression für SVN Responses",
|
||||
"disabled": "Deaktiviert",
|
||||
"disabledHelpText": "Aktiviert oder deaktiviert das SVN Plugin. Nur erlaubt, wenn keine Subversion Repositories existieren.",
|
||||
"required": "Dieser Konfigurationswert wird benötigt"
|
||||
"enabledGZip": {
|
||||
"label": "Aktiviert GZip Kompression für Subversion Responses"
|
||||
},
|
||||
"disabled": {
|
||||
"label": "Deaktiviert das SVN Plugin. Nur erlaubt, wenn keine Subversion Repositories existieren."
|
||||
}
|
||||
}
|
||||
},
|
||||
"permissions": {
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
"config": {
|
||||
"link": "Subversion",
|
||||
"title": "Subversion Configuration",
|
||||
"compatibility": "Version Compatibility",
|
||||
"compatibilityHelpText": "Specifies with which Subversion version repositories are compatible.",
|
||||
"compatibility": {
|
||||
"label": "Version compatibility for each Subversion repository"
|
||||
},
|
||||
"compatibility-values": {
|
||||
"none": "No compatibility",
|
||||
"pre14": "Pre 1.4 Compatible",
|
||||
@@ -16,11 +17,12 @@
|
||||
"pre17": "Pre 1.7 Compatible",
|
||||
"with17": "With 1.7 Compatible"
|
||||
},
|
||||
"enabledGZip": "Enable GZip Compression",
|
||||
"enabledGZipHelpText": "Enable GZip compression for SVN responses.",
|
||||
"disabled": "Disabled",
|
||||
"disabledHelpText": "Enable or disable the SVN plugin. Only allowed if no Subversion repositories exist.",
|
||||
"required": "This configuration value is required"
|
||||
"enabledGZip": {
|
||||
"label": "Enable GZip Compression for Subversion responses"
|
||||
},
|
||||
"disabled": {
|
||||
"label": "Disable the SVN plugin. Only allowed if no Subversion repositories exist."
|
||||
}
|
||||
}
|
||||
},
|
||||
"permissions": {
|
||||
|
||||
@@ -135,10 +135,10 @@ function Form<FormType extends Record<string, unknown>, DefaultValues extends Fo
|
||||
|
||||
// See https://react-hook-form.com/api/useform/reset/
|
||||
useEffect(() => {
|
||||
if (isSubmitSuccessful) {
|
||||
if (isSubmitSuccessful && !error) {
|
||||
setShowSuccessNotification(true);
|
||||
}
|
||||
}, [isSubmitSuccessful]);
|
||||
}, [isSubmitSuccessful, error]);
|
||||
|
||||
useEffect(() => reset(defaultValues as never), [defaultValues, reset]);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ const StyledLabel = styled.label`
|
||||
type InputFieldProps = {
|
||||
label: string;
|
||||
helpText?: string;
|
||||
descriptionText?: string;
|
||||
testId?: string;
|
||||
labelClassName?: string;
|
||||
} & Omit<InputHTMLAttributes<HTMLInputElement>, "type">;
|
||||
@@ -45,6 +46,7 @@ const Checkbox = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
||||
{
|
||||
readOnly,
|
||||
label,
|
||||
descriptionText,
|
||||
className,
|
||||
labelClassName,
|
||||
value,
|
||||
@@ -57,7 +59,11 @@ const Checkbox = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
||||
...props
|
||||
},
|
||||
ref
|
||||
) => (
|
||||
) => {
|
||||
const descriptionId = descriptionText ? `checkbox-description-${name}` : undefined;
|
||||
return (
|
||||
<>
|
||||
{descriptionText ? <p id={descriptionId}>{descriptionText}</p> : null}
|
||||
<StyledLabel
|
||||
className={classNames("checkbox is-align-items-center", labelClassName)}
|
||||
// @ts-ignore bulma uses the disabled attribute on labels, although it is not part of the html spec
|
||||
@@ -72,6 +78,7 @@ const Checkbox = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
||||
defaultValue={defaultValue}
|
||||
checked={checked}
|
||||
defaultChecked={defaultChecked}
|
||||
aria-describedby={descriptionId}
|
||||
readOnly
|
||||
/>
|
||||
<StyledInput
|
||||
@@ -82,6 +89,7 @@ const Checkbox = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
||||
defaultValue={defaultValue}
|
||||
checked={checked}
|
||||
defaultChecked={defaultChecked}
|
||||
aria-describedby={descriptionId}
|
||||
{...props}
|
||||
{...createAttributesForTesting(testId)}
|
||||
disabled
|
||||
@@ -97,6 +105,7 @@ const Checkbox = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
||||
defaultValue={defaultValue}
|
||||
checked={checked}
|
||||
defaultChecked={defaultChecked}
|
||||
aria-describedby={descriptionId}
|
||||
{...props}
|
||||
{...createAttributesForTesting(testId)}
|
||||
/>
|
||||
@@ -105,6 +114,8 @@ const Checkbox = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
||||
{label}
|
||||
{helpText ? <Help className="ml-1" text={helpText} /> : null}
|
||||
</StyledLabel>
|
||||
)
|
||||
</>
|
||||
);
|
||||
}
|
||||
);
|
||||
export default Checkbox;
|
||||
|
||||
@@ -35,6 +35,7 @@ function ControlledInputField<T extends Record<string, unknown>>({
|
||||
name,
|
||||
label,
|
||||
helpText,
|
||||
descriptionText,
|
||||
rules,
|
||||
testId,
|
||||
defaultChecked,
|
||||
@@ -48,6 +49,8 @@ function ControlledInputField<T extends Record<string, unknown>>({
|
||||
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
||||
const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
|
||||
const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
|
||||
const descriptionTextTranslation = descriptionText || t(`${prefixedNameWithoutIndices}.descriptionText`);
|
||||
|
||||
return (
|
||||
<Controller
|
||||
control={control}
|
||||
@@ -64,6 +67,7 @@ function ControlledInputField<T extends Record<string, unknown>>({
|
||||
{...field}
|
||||
label={labelTranslation}
|
||||
helpText={helpTextTranslation}
|
||||
descriptionText={descriptionTextTranslation}
|
||||
testId={testId ?? `checkbox-${nameWithPrefix}`}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -35,6 +35,7 @@ function ControlledInputField<T extends Record<string, unknown>>({
|
||||
name,
|
||||
label,
|
||||
helpText,
|
||||
descriptionText,
|
||||
rules,
|
||||
testId,
|
||||
defaultValue,
|
||||
@@ -48,6 +49,8 @@ function ControlledInputField<T extends Record<string, unknown>>({
|
||||
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
||||
const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
|
||||
const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
|
||||
const descriptionTextTranslation = descriptionText || t(`${prefixedNameWithoutIndices}.descriptionText`);
|
||||
|
||||
return (
|
||||
<Controller
|
||||
control={control}
|
||||
@@ -64,6 +67,7 @@ function ControlledInputField<T extends Record<string, unknown>>({
|
||||
form={formId}
|
||||
label={labelTranslation}
|
||||
helpText={helpTextTranslation}
|
||||
descriptionText={descriptionTextTranslation}
|
||||
error={
|
||||
fieldState.error
|
||||
? fieldState.error.message || t(`${prefixedNameWithoutIndices}.error.${fieldState.error.type}`)
|
||||
|
||||
@@ -26,6 +26,7 @@ import { useAriaId } from "../../helpers";
|
||||
type InputFieldProps = {
|
||||
label: string;
|
||||
helpText?: string;
|
||||
descriptionText?: string;
|
||||
error?: string;
|
||||
} & React.ComponentProps<typeof Input>;
|
||||
|
||||
@@ -33,8 +34,9 @@ type InputFieldProps = {
|
||||
* @see https://bulma.io/documentation/form/input/
|
||||
*/
|
||||
const InputField = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
||||
({ label, helpText, error, className, id, ...props }, ref) => {
|
||||
({ name, label, helpText, descriptionText, error, className, id, ...props }, ref) => {
|
||||
const inputId = useAriaId(id ?? props.testId);
|
||||
const descriptionId = descriptionText ? `input-description-${name}` : undefined;
|
||||
const variant = error ? "danger" : undefined;
|
||||
return (
|
||||
<Field className={className}>
|
||||
@@ -42,8 +44,13 @@ const InputField = React.forwardRef<HTMLInputElement, InputFieldProps>(
|
||||
{label}
|
||||
{helpText ? <Help className="ml-1" text={helpText} /> : null}
|
||||
</Label>
|
||||
{descriptionText ? (
|
||||
<p className="mb-2" id={descriptionId}>
|
||||
{descriptionText}
|
||||
</p>
|
||||
) : null}
|
||||
<Control>
|
||||
<Input variant={variant} ref={ref} id={inputId} {...props}></Input>
|
||||
<Input variant={variant} ref={ref} id={inputId} aria-describedby={descriptionId} {...props}></Input>
|
||||
</Control>
|
||||
{error ? <FieldMessage variant={variant}>{error}</FieldMessage> : null}
|
||||
</Field>
|
||||
|
||||
@@ -16351,7 +16351,7 @@ react-popper@^1.3.7:
|
||||
typed-styles "^0.0.7"
|
||||
warning "^4.0.2"
|
||||
|
||||
react-query@^3.39.2:
|
||||
react-query@^3.25.1, react-query@^3.39.2:
|
||||
version "3.39.3"
|
||||
resolved "https://registry.yarnpkg.com/react-query/-/react-query-3.39.3.tgz#4cea7127c6c26bdea2de5fb63e51044330b03f35"
|
||||
integrity sha512-nLfLz7GiohKTJDuT4us4X3h/8unOh+00MLb2yJoGTPjxKs2bc1iDhkNx2bd5MKklXnOD3NrVZ+J2UXujA5In4g==
|
||||
|
||||
Reference in New Issue
Block a user