Use preselected value with translation key for namespace filter / improve translations

This commit is contained in:
Eduard Heimbuch
2020-11-23 15:48:20 +01:00
committed by René Pfeuffer
parent 237c48356a
commit fd79107468
12 changed files with 39 additions and 21 deletions

View File

@@ -36,7 +36,6 @@ type Props = {
label?: string; label?: string;
testId?: string; testId?: string;
searchPlaceholder?: string; searchPlaceholder?: string;
filterPlaceholder?: string;
}; };
const OverviewPageActions: FC<Props> = ({ const OverviewPageActions: FC<Props> = ({
@@ -47,8 +46,7 @@ const OverviewPageActions: FC<Props> = ({
groupSelected, groupSelected,
label, label,
testId, testId,
searchPlaceholder, searchPlaceholder
filterPlaceholder
}) => { }) => {
const history = useHistory(); const history = useHistory();
const location = useLocation(); const location = useLocation();
@@ -59,7 +57,6 @@ const OverviewPageActions: FC<Props> = ({
options={groups} options={groups}
preselectedOption={currentGroup} preselectedOption={currentGroup}
optionSelected={groupSelected} optionSelected={groupSelected}
placeholder={filterPlaceholder}
/> />
</div> </div>
); );

View File

@@ -32,7 +32,6 @@ type Props = {
preselectedOption?: string; preselectedOption?: string;
className?: string; className?: string;
disabled?: boolean; disabled?: boolean;
placeholder?: string;
}; };
const FullWidthSelect = styled.select` const FullWidthSelect = styled.select`
@@ -41,7 +40,7 @@ const FullWidthSelect = styled.select`
class DropDown extends React.Component<Props> { class DropDown extends React.Component<Props> {
render() { render() {
const { options, optionValues, preselectedOption, className, disabled, placeholder } = this.props; const { options, optionValues, preselectedOption, className, disabled } = this.props;
if (preselectedOption && options.filter(o => o === preselectedOption).length === 0) { if (preselectedOption && options.filter(o => o === preselectedOption).length === 0) {
options.push(preselectedOption); options.push(preselectedOption);
@@ -49,12 +48,7 @@ class DropDown extends React.Component<Props> {
return ( return (
<div className={classNames(className, "select", disabled ? "disabled" : "")}> <div className={classNames(className, "select", disabled ? "disabled" : "")}>
<FullWidthSelect <FullWidthSelect value={preselectedOption ? preselectedOption : ""} onChange={this.change} disabled={disabled}>
value={preselectedOption ? preselectedOption : ""}
onChange={this.change}
disabled={disabled}
placeholder={placeholder}
>
{options.map((option, index) => { {options.map((option, index) => {
const value = optionValues && optionValues[index] ? optionValues[index] : option; const value = optionValues && optionValues[index] ? optionValues[index] : option;
return ( return (

View File

@@ -65,7 +65,7 @@ const FilterInput: FC<Props> = ({ filter, value, testId, placeholder }) => {
<FixedHeightInput <FixedHeightInput
className="input" className="input"
type="search" type="search"
placeholder={placeholder || t("overviewAction.filterEntries")} placeholder={placeholder || t("filterEntries")}
value={stateValue} value={stateValue}
onChange={event => setStateValue(event.target.value)} onChange={event => setStateValue(event.target.value)}
/> />

View File

@@ -25,6 +25,9 @@
"setPermissionsNavLink": "Berechtigungen" "setPermissionsNavLink": "Berechtigungen"
} }
}, },
"overview": {
"searchGroup": "Gruppe suchen"
},
"add-group": { "add-group": {
"title": "Gruppe erstellen", "title": "Gruppe erstellen",
"subtitle": "Erstellen einer neuen Gruppe" "subtitle": "Erstellen einer neuen Gruppe"

View File

@@ -44,7 +44,7 @@
"noRepositories": "Keine Repositories gefunden.", "noRepositories": "Keine Repositories gefunden.",
"createButton": "Repository erstellen", "createButton": "Repository erstellen",
"searchRepository": "Repository suchen", "searchRepository": "Repository suchen",
"filterNamespace": "Namespace filtern" "allNamespaces": "Alle Namespaces"
}, },
"create": { "create": {
"title": "Repository erstellen", "title": "Repository erstellen",

View File

@@ -30,6 +30,9 @@
"noUsers": "Keine Benutzer gefunden.", "noUsers": "Keine Benutzer gefunden.",
"createButton": "Benutzer erstellen" "createButton": "Benutzer erstellen"
}, },
"overview": {
"searchUser": "Benutzer suchen"
},
"singleUser": { "singleUser": {
"errorTitle": "Fehler", "errorTitle": "Fehler",
"errorSubtitle": "Unbekannter Benutzer Fehler", "errorSubtitle": "Unbekannter Benutzer Fehler",

View File

@@ -25,6 +25,9 @@
"setPermissionsNavLink": "Permissions" "setPermissionsNavLink": "Permissions"
} }
}, },
"overview": {
"searchGroup": "Search group"
},
"add-group": { "add-group": {
"title": "Create Group", "title": "Create Group",
"subtitle": "Create a new group" "subtitle": "Create a new group"

View File

@@ -44,7 +44,7 @@
"noRepositories": "No repositories found.", "noRepositories": "No repositories found.",
"createButton": "Create Repository", "createButton": "Create Repository",
"searchRepository": "Search repository", "searchRepository": "Search repository",
"filterNamespace": "Filter by namespace" "allNamespaces": "All namespaces"
}, },
"create": { "create": {
"title": "Create Repository", "title": "Create Repository",

View File

@@ -44,6 +44,9 @@
"setApiKeyNavLink": "API Keys" "setApiKeyNavLink": "API Keys"
} }
}, },
"overview": {
"searchUser": "Search user"
},
"createUser": { "createUser": {
"title": "Create User", "title": "Create User",
"subtitle": "Create a new user" "subtitle": "Create a new user"

View File

@@ -92,7 +92,12 @@ class Groups extends React.Component<Props> {
{this.renderGroupTable()} {this.renderGroupTable()}
{this.renderCreateButton()} {this.renderCreateButton()}
<PageActions> <PageActions>
<OverviewPageActions showCreateButton={canAddGroups} link="groups" label={t("create-group-button.label")} /> <OverviewPageActions
showCreateButton={canAddGroups}
link="groups"
label={t("create-group-button.label")}
searchPlaceholder={t("overview.searchGroup")}
/>
</PageActions> </PageActions>
</Page> </Page>
); );

View File

@@ -101,8 +101,12 @@ class Overview extends React.Component<Props> {
} }
}; };
getNamespaceFilterPlaceholder = () => {
return this.props.t("overview.allNamespaces");
};
namespaceSelected = (newNamespace: string) => { namespaceSelected = (newNamespace: string) => {
if (newNamespace === "") { if (newNamespace === this.getNamespaceFilterPlaceholder()) {
this.props.history.push("/repos/"); this.props.history.push("/repos/");
} else { } else {
this.props.history.push(`/repos/${newNamespace}/`); this.props.history.push(`/repos/${newNamespace}/`);
@@ -111,8 +115,10 @@ class Overview extends React.Component<Props> {
render() { render() {
const { error, loading, showCreateButton, namespace, namespaces, t } = this.props; const { error, loading, showCreateButton, namespace, namespaces, t } = this.props;
const namespaceFilterPlaceholder = this.getNamespaceFilterPlaceholder();
const namespacesToRender = namespaces ? ["", ...namespaces._embedded.namespaces.map(n => n.namespace).sort()] : []; const namespacesToRender = namespaces
? [namespaceFilterPlaceholder, ...namespaces._embedded.namespaces.map(n => n.namespace).sort()]
: [];
return ( return (
<Page title={t("overview.title")} subtitle={t("overview.subtitle")} loading={loading} error={error}> <Page title={t("overview.title")} subtitle={t("overview.subtitle")} loading={loading} error={error}>
@@ -127,7 +133,6 @@ class Overview extends React.Component<Props> {
label={t("overview.createButton")} label={t("overview.createButton")}
testId="repository-overview" testId="repository-overview"
searchPlaceholder={t("overview.searchRepository")} searchPlaceholder={t("overview.searchRepository")}
filterPlaceholder={t("overview.filterNamespace")}
/> />
</PageActions> </PageActions>
</Page> </Page>

View File

@@ -93,7 +93,12 @@ class Users extends React.Component<Props> {
{this.renderUserTable()} {this.renderUserTable()}
{this.renderCreateButton()} {this.renderCreateButton()}
<PageActions> <PageActions>
<OverviewPageActions showCreateButton={canAddUsers} link="users" label={t("users.createButton")} /> <OverviewPageActions
showCreateButton={canAddUsers}
link="users"
label={t("users.createButton")}
searchPlaceholder={t("overview.searchUser")}
/>
</PageActions> </PageActions>
</Page> </Page>
); );