Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

feat: VirtualSelectBox #65

Merged
merged 7 commits into from
Sep 2, 2019
Merged

feat: VirtualSelectBox #65

merged 7 commits into from
Sep 2, 2019

Conversation

wangkailang
Copy link
Member

@wangkailang wangkailang commented Aug 28, 2019

  • 支持 VirtualSelectBox 组件

@codecov
Copy link

codecov bot commented Aug 28, 2019

Codecov Report

Merging #65 into master will increase coverage by 3.26%.
The diff coverage is 81.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
+ Coverage   78.07%   81.34%   +3.26%     
==========================================
  Files          30       33       +3     
  Lines         967     1131     +164     
  Branches      201      234      +33     
==========================================
+ Hits          755      920     +165     
+ Misses        210      208       -2     
- Partials        2        3       +1
Impacted Files Coverage Δ
src/utils/index.ts 100% <100%> (ø) ⬆️
src/utils/get-mock-datas.ts 100% <100%> (ø)
src/utils/sleep.ts 100% <100%> (ø)
stories/demos/AsyncVirtualList.tsx 82.75% <100%> (ø) ⬆️
src/components/VirtualList/index.tsx 89.44% <100%> (+12.77%) ⬆️
src/components/DropdownButton/index.tsx 60.46% <100%> (ø) ⬆️
src/components/index.tsx 100% <100%> (ø) ⬆️
src/components/VirtualSelectBox/index.tsx 77.77% <77.77%> (ø)
src/utils/elastic-query.ts 82.75% <82.75%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef73e0a...6466fd2. Read the comment docs.

@netlify
Copy link

netlify bot commented Aug 28, 2019

Deploy preview for wizard-ui ready!

Built with commit 6466fd2

https://deploy-preview-65--wizard-ui.netlify.com

src/interface.tsx Outdated Show resolved Hide resolved
'data-action'?: string;
} | string;
export type DropdownButtonMenuItem =
| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块儿是格式化出来的吗?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的

src/interface.tsx Outdated Show resolved Hide resolved
src/interface.tsx Outdated Show resolved Hide resolved
*/
function toStr(arr: ArrType[]) {
if (!(arr instanceof Array)) return '';
const forward: any[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type ValueType = string | number;
type ArrType = {
  type: string;
  value: ValueType;
}
...
const forward: ValueType[] = [];

src/utils/elastic-query.ts Show resolved Hide resolved
src/utils/sleep.ts Outdated Show resolved Hide resolved
src/components/VirtualSelectBox/index.tsx Show resolved Hide resolved
@wangkailang wangkailang added the changes Code Need Change label Aug 29, 2019
@wangkailang wangkailang added the 3-Changed Code has Changed label Aug 30, 2019
import React from 'react';
import { mount } from 'enzyme';
import VirtualSelectBox from './index';
import getMockDatas from '../../../stories/utils/getMockDatas';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里在 components 里引用了 stories 里面的东西,stories 里面也需要引用 components 中的组件,所以类似 mock data 这种 components 和 stories 里面的都需要使用的方法是不是单独出来,让两个模块都引用这个更好些?

query: Query;
}

export interface VirtualSelectBoxProps extends VirtualSelectBoxDefaultProps {
Copy link
Contributor

@lijianxin1202 lijianxin1202 Sep 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以使用泛型来为约束 item 类型

export interface VirtualSelectBoxItem {
  id?: number;
}
export interface VirtualSelectBoxProps<T> extends VirtualSelectBoxDefaultProps {
  fetchData: (isReloading: boolean, query: Query, search?: string) => Promise<{
    query: Query;
    items: T[];
    totalCount: number;
    error?: string;
  }>;
  item?: T;
  className?: string;
  clear?: boolean;
  onSelect?: (i: T) => void;
  formatOption?: (item: T) => T;
}

export interface VirtualSelectBoxState<T> {
  search: string;
  items: T[];
  query: Query;
  isFetching: boolean;
  totalCount: number;
  isOpen: boolean;
  isReloading: boolean;
  error?: string;
}

组件定义

class  VirtualSelectBox<T extends VirtualSelectBoxItem> extends  React.Component<VirtualSelectBoxProps<T>, VirtualSelectBoxState<T>> {}

调用

type Data = { id?: number; name: string };
<VirtualSelectBox<Data>
  item={{ id:  1, name:  `${resName}-1` }}
  fetchData={fetchDatas}
  onSelect={noOp}
  clear
/>

为了解决 clear 时调用 onSelect({}) 报错,我们可以添加一个可选的默认值属性,类型也是 T,在 clear 时将默认值传入,也可以更方便的定制化
VirtualList 也可以这么修改

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

666 呀,这种用法听实用的,也比较灵活,根据这个做个调整:

  1. VirtualList 上补充 VirtualItem 代替 VirtualSelectBoxItem,并支持 string 类型;
  2. VirtualSelectBoxDefaultProps 增加 defaultItem 指定为泛类型,解决 onSelect({}) 的问题。

@lijianxin1202 lijianxin1202 added the 4-Approved Code PR approved label Sep 2, 2019
@wangkailang wangkailang added the good first issue Good for newcomers label Sep 2, 2019
…al-select-box

* 'master' of github.com:xsky-fe/wizard-ui:
  Release 0.2.0
  feat: Add InputDropdown. (#64)

# Conflicts:
#	src/interface.tsx
@wangkailang wangkailang merged commit c1b9940 into master Sep 2, 2019
@wangkailang wangkailang deleted the feat/virtual-select-box branch September 2, 2019 09:02
wangkailang added a commit that referenced this pull request Sep 2, 2019
…odal-props-hideFooter

* 'master' of github.com:xsky-fe/wizard-ui:
  feat: VirtualSelectBox (#65)
  Release 0.2.0
  feat: Add InputDropdown. (#64)

# Conflicts:
#	src/components/VirtualList/index.tsx
#	src/components/index.tsx
#	src/interface.tsx
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1-Review Code review 3-Changed Code has Changed 4-Approved Code PR approved changes Code Need Change good first issue Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants