1
0
mirror of https://github.com/SomboChea/ui synced 2024-11-24 15:04:27 +07:00

fix: remove any types and added additional component state interfaces

This commit is contained in:
Griffithtp 2019-06-23 20:50:30 +01:00
parent 3c54b116c9
commit 116055c5d1
11 changed files with 22 additions and 21 deletions

View File

@ -39,8 +39,9 @@ const register = (url, method = 'get', options = {}) => {
* Bind API methods * Bind API methods
*/ */
class API { class API {
request() { public request() {
return register.call(null, ...arguments); const rest = arguments;
return register.call(null, ...rest);
} }
} }

View File

@ -2,6 +2,6 @@
* Mock response for logo api * Mock response for logo api
* @returns {promise} * @returns {promise}
*/ */
export default function() { export default function<T>(): Promise<T> {
return Promise.resolve('http://localhost/-/static/logo.png'); return Promise.resolve('http://localhost/-/static/logo.png');
} }

View File

@ -7,7 +7,7 @@ import { generateTokenWithTimeRange } from '../../jest/unit/components/__mocks__
jest.mock('../utils/storage', () => { jest.mock('../utils/storage', () => {
class LocalStorageMock { class LocalStorageMock {
store: object; private store: object;
public constructor() { public constructor() {
this.store = {}; this.store = {};
} }

View File

@ -19,7 +19,7 @@ export const AppContext = React.createContext<null>(null);
export const AppContextProvider = AppContext.Provider; export const AppContextProvider = AppContext.Provider;
export const AppContextConsumer = AppContext.Consumer; export const AppContextConsumer = AppContext.Consumer;
export default class App extends Component<any, any> { export default class App extends Component {
public state = { public state = {
error: {}, error: {},
// @ts-ignore // @ts-ignore

View File

@ -14,7 +14,7 @@ interface DetailContainerState {
tabPosition: number; tabPosition: number;
} }
class DetailContainer extends Component<any, DetailContainerState> { class DetailContainer<P> extends Component<P, DetailContainerState> {
public state = { public state = {
tabPosition: 0, tabPosition: 0,
}; };
@ -29,7 +29,7 @@ class DetailContainer extends Component<any, DetailContainerState> {
); );
} }
private handleChange = (event: any, tabPosition: number) => { private handleChange = (event: React.ChangeEvent<{}>, tabPosition: number) => {
event.preventDefault(); event.preventDefault();
this.setState({ tabPosition }); this.setState({ tabPosition });
}; };

View File

@ -8,7 +8,7 @@ import { Props } from './types';
const LABEL = 'CLOSE'; const LABEL = 'CLOSE';
const RegistryInfoDialog: React.FC<Props> = ({ open = false, children, onClose }): any => ( const RegistryInfoDialog: React.FC<Props> = ({ open = false, children, onClose }) => (
<Dialog id="registryInfo--dialog-container" onClose={onClose} open={open}> <Dialog id="registryInfo--dialog-container" onClose={onClose} open={open}>
<Title disableTypography={true}>{'Register Info'}</Title> <Title disableTypography={true}>{'Register Info'}</Title>
<Content>{children}</Content> <Content>{children}</Content>

View File

@ -154,7 +154,7 @@ describe('<Search /> component test', () => {
beforeEach(() => { beforeEach(() => {
jest.resetModules(); jest.resetModules();
jest.doMock('lodash/debounce', () => { jest.doMock('lodash/debounce', () => {
return function debounceMock(fn, delay) { return function debounceMock(fn) {
return fn; return fn;
}; };
}); });

View File

@ -39,7 +39,7 @@ interface StateInterface {
notFound: boolean; notFound: boolean;
} }
class VersionPage extends Component<PropsInterface, StateInterface> { class VersionPage extends Component<PropsInterface, Partial<StateInterface>> {
constructor(props) { constructor(props) {
super(props); super(props);
@ -81,7 +81,7 @@ class VersionPage extends Component<PropsInterface, StateInterface> {
public async componentDidUpdate(nextProps, prevState: StateInterface): Promise<void> { public async componentDidUpdate(nextProps, prevState: StateInterface): Promise<void> {
const { packageName } = this.state; const { packageName } = this.state;
if (packageName !== prevState.packageName) { if (packageName !== prevState.packageName) {
const { readMe, packageMeta } = await callDetailPage(packageName); const { readMe, packageMeta } = (await callDetailPage(packageName)) as Partial<StateInterface>;
this.setState({ this.setState({
readMe, readMe,
packageMeta, packageMeta,
@ -125,7 +125,7 @@ class VersionPage extends Component<PropsInterface, StateInterface> {
}); });
try { try {
const { readMe, packageMeta } = await callDetailPage(packageName); const { readMe, packageMeta } = (await callDetailPage(packageName)) as Partial<StateInterface>;
this.setState({ this.setState({
readMe, readMe,
packageMeta, packageMeta,

View File

@ -25,16 +25,16 @@ function handleResponseType(response: Response): Promise<[boolean, Blob | string
} }
class API { class API {
public request(url: string, method = 'GET', options: any = {}): Promise<any> { public request<T>(url: string, method = 'GET', options?: RequestInit): Promise<T> {
if (!window.VERDACCIO_API_URL) { if (!window.VERDACCIO_API_URL) {
throw new Error('VERDACCIO_API_URL is not defined!'); throw new Error('VERDACCIO_API_URL is not defined!');
} }
const token = storage.getItem('token'); const token = storage.getItem('token');
if (token) { const headers = new Headers(options && options.headers);
if (!options.headers) options.headers = {}; if (token && options && options.headers) {
headers.set('Authorization', `Bearer ${token}`);
options.headers.authorization = `Bearer ${token}`; options.headers = Object.assign(options.headers, headers);
} }
if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) { if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) {
@ -42,7 +42,7 @@ class API {
url = window.VERDACCIO_API_URL + url; url = window.VERDACCIO_API_URL + url;
} }
return new Promise<any>((resolve, reject) => { return new Promise((resolve, reject) => {
fetch(url, { fetch(url, {
method, method,
credentials: 'same-origin', credentials: 'same-origin',

View File

@ -2,8 +2,8 @@ import API from './api';
import { PackageMetaInterface } from 'types/packageMeta'; import { PackageMetaInterface } from 'types/packageMeta';
export interface DetailPage { export interface DetailPage {
readMe: string; readMe: string | {};
packageMeta: PackageMetaInterface; packageMeta: PackageMetaInterface | {};
} }
export async function callDetailPage(packageName): Promise<DetailPage> { export async function callDetailPage(packageName): Promise<DetailPage> {

View File

@ -1,4 +1,4 @@
/* tslint:disable */ /* @ts-ignore */
export default function fileSizeSI(a?: any, b?: any, c?: any, d?: any, e?: any) { export default function fileSizeSI(a?: any, b?: any, c?: any, d?: any, e?: any) {
return ((b = Math), (c = b.log), (d = 1e3), (e = (c(a) / c(d)) | 0), a / b.pow(d, e)).toFixed(2) + ' ' + (e ? 'kMGTPEZY'[--e] + 'B' : 'Bytes'); return ((b = Math), (c = b.log), (d = 1e3), (e = (c(a) / c(d)) | 0), a / b.pow(d, e)).toFixed(2) + ' ' + (e ? 'kMGTPEZY'[--e] + 'B' : 'Bytes');
} }