2019-03-11 14:48:48 +01:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { translate, type TFunction } from "react-i18next";
|
|
|
|
|
import { Select } from "@scm-manager/ui-components";
|
|
|
|
|
import type { NamespaceStrategies } from "@scm-manager/ui-types";
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
namespaceStrategies: NamespaceStrategies,
|
|
|
|
|
label: string,
|
|
|
|
|
value?: string,
|
|
|
|
|
disabled?: boolean,
|
|
|
|
|
helpText?: string,
|
|
|
|
|
onChange: (value: string, name?: string) => void,
|
|
|
|
|
// context props
|
|
|
|
|
t: TFunction
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NamespaceStrategySelect extends React.Component<Props> {
|
|
|
|
|
createNamespaceOptions = () => {
|
|
|
|
|
const { namespaceStrategies, t } = this.props;
|
|
|
|
|
let available = [];
|
|
|
|
|
if (namespaceStrategies && namespaceStrategies.available) {
|
|
|
|
|
available = namespaceStrategies.available;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return available.map(ns => {
|
|
|
|
|
const key = "namespaceStrategies." + ns;
|
|
|
|
|
let label = t("namespaceStrategies." + ns);
|
|
|
|
|
if (label === key) {
|
|
|
|
|
label = ns;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
value: ns,
|
|
|
|
|
label: label
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-12 14:35:22 +01:00
|
|
|
findSelected = () => {
|
|
|
|
|
const { namespaceStrategies, value } = this.props;
|
|
|
|
|
if (namespaceStrategies.available.indexOf(value) < 0) {
|
|
|
|
|
return namespaceStrategies.current;
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-11 14:48:48 +01:00
|
|
|
render() {
|
2019-03-12 14:35:22 +01:00
|
|
|
const { label, helpText, disabled, onChange } = this.props;
|
2019-03-11 14:48:48 +01:00
|
|
|
const nsOptions = this.createNamespaceOptions();
|
|
|
|
|
return (
|
|
|
|
|
<Select
|
|
|
|
|
label={label}
|
|
|
|
|
onChange={onChange}
|
2019-03-12 14:35:22 +01:00
|
|
|
value={this.findSelected()}
|
2019-03-11 14:48:48 +01:00
|
|
|
disabled={disabled}
|
|
|
|
|
options={nsOptions}
|
|
|
|
|
helpText={helpText}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default translate("plugins")(NamespaceStrategySelect);
|