migrate ui-components from flow to typescript

This commit is contained in:
Sebastian Sdorra
2019-10-20 16:59:02 +02:00
parent c41efbdc4f
commit f49e17a3a7
151 changed files with 2039 additions and 25265 deletions

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React from "react";
type Props = {
icon?: string;
@@ -14,7 +14,7 @@ class NavAction extends React.Component<Props> {
if (icon) {
showIcon = (
<>
<i className={icon}></i>{' '}
<i className={icon}></i>{" "}
</>
);
}

View File

@@ -1,6 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import { Link, Route } from 'react-router-dom';
import * as React from "react";
import classNames from "classnames";
import { Link, Route } from "react-router-dom";
// TODO mostly copy of PrimaryNavigationLink
@@ -14,7 +14,7 @@ type Props = {
class NavLink extends React.Component<Props> {
static defaultProps = {
activeOnlyWhenExact: true,
activeOnlyWhenExact: true
};
isActive(route: any) {
@@ -29,14 +29,14 @@ class NavLink extends React.Component<Props> {
if (icon) {
showIcon = (
<>
<i className={classNames(icon, 'fa-fw')} />{' '}
<i className={classNames(icon, "fa-fw")} />{" "}
</>
);
}
return (
<li>
<Link className={this.isActive(route) ? 'is-active' : ''} to={to}>
<Link className={this.isActive(route) ? "is-active" : ""} to={to}>
{showIcon}
{label}
</Link>

View File

@@ -1,7 +1,7 @@
import * as React from 'react';
import React, { ReactNode } from "react";
type Props = {
children?: React.Node;
children?: ReactNode;
};
class Navigation extends React.Component<Props> {

View File

@@ -1,16 +1,18 @@
import React from 'react';
import { translate } from 'react-i18next';
import PrimaryNavigationLink from './PrimaryNavigationLink';
import { Links } from '@scm-manager/ui-types';
import { binder, ExtensionPoint } from '@scm-manager/ui-extensions';
import React, {ReactNode} from "react";
import { translate } from "react-i18next";
import PrimaryNavigationLink from "./PrimaryNavigationLink";
import { Links } from "@scm-manager/ui-types";
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
type Props = {
t: (p: string) => string;
links: Links;
};
type Appender = (to: string, match: string, label: string, linkName: string) => void;
class PrimaryNavigation extends React.Component<Props> {
createNavigationAppender = navigationItems => {
createNavigationAppender = (navigationItems: ReactNode[]): Appender => {
const { t, links } = this.props;
return (to: string, match: string, label: string, linkName: string) => {
@@ -29,60 +31,60 @@ class PrimaryNavigation extends React.Component<Props> {
};
};
appendLogout = (navigationItems, append) => {
appendLogout = (navigationItems: ReactNode[], append: Appender) => {
const { t, links } = this.props;
const props = {
links,
label: t('primary-navigation.logout'),
label: t("primary-navigation.logout")
};
if (binder.hasExtension('primary-navigation.logout', props)) {
if (binder.hasExtension("primary-navigation.logout", props)) {
navigationItems.push(
<ExtensionPoint
key="primary-navigation.logout"
name="primary-navigation.logout"
props={props}
/>,
/>
);
} else {
append('/logout', '/logout', 'primary-navigation.logout', 'logout');
append("/logout", "/logout", "primary-navigation.logout", "logout");
}
};
createNavigationItems = () => {
const navigationItems = [];
const navigationItems: ReactNode[] = [];
const { t, links } = this.props;
const props = {
links,
label: t('primary-navigation.first-menu'),
label: t("primary-navigation.first-menu")
};
const append = this.createNavigationAppender(navigationItems);
if (binder.hasExtension('primary-navigation.first-menu', props)) {
if (binder.hasExtension("primary-navigation.first-menu", props)) {
navigationItems.push(
<ExtensionPoint
key="primary-navigation.first-menu"
name="primary-navigation.first-menu"
props={props}
/>,
/>
);
}
append(
'/repos/',
'/(repo|repos)',
'primary-navigation.repositories',
'repositories',
"/repos/",
"/(repo|repos)",
"primary-navigation.repositories",
"repositories"
);
append('/users/', '/(user|users)', 'primary-navigation.users', 'users');
append("/users/", "/(user|users)", "primary-navigation.users", "users");
append(
'/groups/',
'/(group|groups)',
'primary-navigation.groups',
'groups',
"/groups/",
"/(group|groups)",
"primary-navigation.groups",
"groups"
);
append('/admin', '/admin', 'primary-navigation.admin', 'config');
append("/admin", "/admin", "primary-navigation.admin", "config");
navigationItems.push(
<ExtensionPoint
@@ -90,9 +92,9 @@ class PrimaryNavigation extends React.Component<Props> {
name="primary-navigation"
renderAll={true}
props={{
links: this.props.links,
links: this.props.links
}}
/>,
/>
);
this.appendLogout(navigationItems, append);
@@ -111,4 +113,4 @@ class PrimaryNavigation extends React.Component<Props> {
}
}
export default translate('commons')(PrimaryNavigation);
export default translate("commons")(PrimaryNavigation);

View File

@@ -1,5 +1,5 @@
import * as React from 'react';
import { Route, Link } from 'react-router-dom';
import * as React from "react";
import { Route, Link } from "react-router-dom";
type Props = {
to: string;
@@ -12,7 +12,7 @@ class PrimaryNavigationLink extends React.Component<Props> {
renderLink = (route: any) => {
const { to, label } = this.props;
return (
<li className={route.match ? 'is-active' : ''}>
<li className={route.match ? "is-active" : ""}>
<Link to={to}>{label}</Link>
</li>
);

View File

@@ -1,8 +1,8 @@
import * as React from 'react';
import React, { ReactNode } from "react";
type Props = {
label: string;
children?: React.Node;
children?: ReactNode;
};
class Section extends React.Component<Props> {

View File

@@ -1,6 +1,6 @@
import * as React from 'react';
import { Link, Route } from 'react-router-dom';
import classNames from 'classnames';
import React, { ReactNode } from "react";
import { Link, Route } from "react-router-dom";
import classNames from "classnames";
type Props = {
to: string;
@@ -8,12 +8,12 @@ type Props = {
label: string;
activeOnlyWhenExact?: boolean;
activeWhenMatch?: (route: any) => boolean;
children?: React.Node;
children?: ReactNode;
};
class SubNavigation extends React.Component<Props> {
static defaultProps = {
activeOnlyWhenExact: false,
activeOnlyWhenExact: false
};
isActive(route: any) {
@@ -24,7 +24,7 @@ class SubNavigation extends React.Component<Props> {
renderLink = (route: any) => {
const { to, icon, label } = this.props;
let defaultIcon = 'fas fa-cog';
let defaultIcon = "fas fa-cog";
if (icon) {
defaultIcon = icon;
}
@@ -36,8 +36,8 @@ class SubNavigation extends React.Component<Props> {
return (
<li>
<Link className={this.isActive(route) ? 'is-active' : ''} to={to}>
<i className={classNames(defaultIcon, 'fa-fw')} /> {label}
<Link className={this.isActive(route) ? "is-active" : ""} to={to}>
<i className={classNames(defaultIcon, "fa-fw")} /> {label}
</Link>
{children}
</li>
@@ -48,9 +48,9 @@ class SubNavigation extends React.Component<Props> {
const { to, activeOnlyWhenExact } = this.props;
// removes last part of url
let parents = to.split('/');
let parents = to.split("/");
parents.splice(-1, 1);
let parent = parents.join('/');
let parent = parents.join("/");
return (
<Route

View File

@@ -1,9 +1,9 @@
// @create-index
export { default as NavAction } from './NavAction';
export { default as NavLink } from './NavLink';
export { default as Navigation } from './Navigation';
export { default as SubNavigation } from './SubNavigation';
export { default as PrimaryNavigation } from './PrimaryNavigation';
export { default as PrimaryNavigationLink } from './PrimaryNavigationLink';
export { default as Section } from './Section';
export { default as NavAction } from "./NavAction";
export { default as NavLink } from "./NavLink";
export { default as Navigation } from "./Navigation";
export { default as SubNavigation } from "./SubNavigation";
export { default as PrimaryNavigation } from "./PrimaryNavigation";
export { default as PrimaryNavigationLink } from "./PrimaryNavigationLink";
export { default as Section } from "./Section";