merge + add user/group autocomplete ui-components

This commit is contained in:
Florian Scholdei
2019-06-11 18:10:29 +02:00
39 changed files with 4234 additions and 2922 deletions

View File

@@ -14,7 +14,7 @@
"eslint-fix": "eslint src --fix"
},
"devDependencies": {
"@scm-manager/ui-bundler": "^0.0.28",
"@scm-manager/ui-bundler": "^0.0.29",
"create-index": "^2.3.0",
"enzyme": "^3.5.0",
"enzyme-adapter-react-16": "^1.3.1",

View File

@@ -4,7 +4,6 @@ import { AsyncCreatable, Async } from "react-select";
import type { AutocompleteObject, SelectValue } from "@scm-manager/ui-types";
import LabelWithHelpIcon from "./forms/LabelWithHelpIcon";
type Props = {
loadSuggestions: string => Promise<AutocompleteObject>,
valueSelected: SelectValue => void,

View File

@@ -10,35 +10,33 @@ type Props = {
error?: Error
};
class ErrorNotification extends React.Component<Props> {
render() {
const { t, error } = this.props;
if (error) {
if (error instanceof BackendError) {
return <BackendErrorNotification error={error} />
return <BackendErrorNotification error={error} />;
} else if (error instanceof UnauthorizedError) {
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong>{" "}
{t("error-notification.timeout")}{" "}
<strong>{t("errorNotification.prefix")}:</strong>{" "}
{t("errorNotification.timeout")}{" "}
<a href="javascript:window.location.reload(true)">
{t("error-notification.loginLink")}
{t("errorNotification.loginLink")}
</a>
</Notification>
);
} else if (error instanceof ForbiddenError) {
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong>{" "}
{t("error-notification.forbidden")}
<strong>{t("errorNotification.prefix")}:</strong>{" "}
{t("errorNotification.forbidden")}
</Notification>
)
} else
{
);
} else {
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong> {error.message}
<strong>{t("errorNotification.prefix")}:</strong> {error.message}
</Notification>
);
}
@@ -47,4 +45,4 @@ class ErrorNotification extends React.Component<Props> {
}
}
export default translate("commons")(ErrorNotification);
export default translate("commons")(ErrorNotification);

View File

@@ -0,0 +1,37 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import type { SelectValue } from "@scm-manager/ui-types";
import UserGroupAutocomplete from "./UserGroupAutocomplete";
type Props = {
groupAutocompleteLink: string,
valueSelected: SelectValue => void,
value: string,
// Context props
t: string => string
};
class GroupAutocomplete extends React.Component<Props> {
selectName = (selection: SelectValue) => {
this.props.valueSelected(selection);
};
render() {
const { groupAutocompleteLink, t, value } = this.props;
return (
<UserGroupAutocomplete
autocompleteLink={groupAutocompleteLink}
label={t("autocomplete.group")}
noOptionsMessage={t("autocomplete.noGroupOptions")}
loadingMessage={t("autocomplete.loading")}
placeholder={t("autocomplete.groupPlaceholder")}
valueSelected={this.selectName}
value={value}
/>
);
}
}
export default translate("commons")(GroupAutocomplete);

View File

@@ -0,0 +1,37 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import type { SelectValue } from "@scm-manager/ui-types";
import UserGroupAutocomplete from "./UserGroupAutocomplete";
type Props = {
userAutocompleteLink: string,
valueSelected: SelectValue => void,
value: string,
// Context props
t: string => string
};
class UserAutocomplete extends React.Component<Props> {
selectName = (selection: SelectValue) => {
this.props.valueSelected(selection);
};
render() {
const { userAutocompleteLink, t, value } = this.props;
return (
<UserGroupAutocomplete
autocompleteLink={userAutocompleteLink}
label={t("autocomplete.user")}
noOptionsMessage={t("autocomplete.noUserOptions")}
loadingMessage={t("autocomplete.loading")}
placeholder={t("autocomplete.userPlaceholder")}
valueSelected={this.selectName}
value={value}
/>
);
}
}
export default translate("commons")(UserAutocomplete);

View File

@@ -0,0 +1,51 @@
// @flow
import React from "react";
import type { SelectValue } from "@scm-manager/ui-types";
import Autocomplete from "./Autocomplete";
type Props = {
autocompleteLink: string,
valueSelected: SelectValue => void,
value: string,
label: string
};
class UserGroupAutocomplete extends React.Component<Props> {
loadSuggestions = (inputValue: string) => {
const url = this.props.autocompleteLink;
const link = url + "?q=";
return fetch(link + inputValue)
.then(response => response.json())
.then(json => {
return json.map(element => {
const label = element.displayName
? `${element.displayName} (${element.id})`
: element.id;
return {
value: element,
label
};
});
});
};
selectName = (selection: SelectValue) => {
this.props.valueSelected(selection);
};
render() {
const { value, label } = this.props;
return (
<Autocomplete
loadSuggestions={this.loadSuggestions}
valueSelected={this.selectName}
value={value}
creatable={true}
label={label}
{...this.props}
/>
);
}
}
export default UserGroupAutocomplete;

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,7 @@
"check": "flow check"
},
"devDependencies": {
"@scm-manager/ui-bundler": "^0.0.28"
"@scm-manager/ui-bundler": "^0.0.29"
},
"browserify": {
"transform": [

File diff suppressed because it is too large Load Diff