Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 searchForm 刷新后恢复默认值的问题 #320

Merged
merged 6 commits into from
Sep 12, 2020

Conversation

shoyuf
Copy link
Member

@shoyuf shoyuf commented Sep 9, 2020

Why

fix #319

How

Describe your steps:

  1. 当搜索表单中搜索字段有默认值时,进入页面,搜索时传入默认值,url同步数据
  2. 当搜索字段的默认值被清空时,url同步数据,并且刷新页面搜索时不会被默认值覆盖(搜索时不传入数据)

Test

原来的数据为空的逻辑判断,认为空数组,空字符为isFalsey,现改为not false

  • before
import isFalsey from '../src/utils/is-falsey'

describe('test isFalsey', () => {
  test('判断为 "",undefined或者 null', () => {
    expect(isFalsey(undefined)).toBe(true)
    expect(isFalsey(null)).toBe(true)
    expect(isFalsey('')).toBe(true)
    expect(isFalsey()).toBe(true)
    expect(isFalsey(0)).toBe(false)
    expect(isFalsey({})).toBe(false)
    expect(isFalsey([])).toBe(true)
  })
})
  • after
import {isFalsey, dealQuery} from '../src/utils/is-falsey'

describe('test isFalsey', () => {
  test('判断为 "",undefined或者 null', () => {
    expect(isFalsey(undefined)).toBe(true)
    expect(isFalsey(null)).toBe(true)
    expect(isFalsey('')).toBe(false)
    expect(isFalsey()).toBe(true)
    expect(isFalsey(0)).toBe(false)
    expect(isFalsey({})).toBe(false)
    expect(isFalsey([])).toBe(false)
  })
})

describe('test dealQuery', () => {
  test('判断 "", undefined, null, 空数组', () => {
    expect(
      dealQuery({
        a: 1,
        b: '',
        c: undefined,
        d: null,
        e: [],
        f: [2]
      })
    ).toStrictEqual({a: 1, f: [2]})
  })
})

@auto-add-label auto-add-label bot added the bug Something isn't working label Sep 9, 2020
@netlify
Copy link

netlify bot commented Sep 9, 2020

Deploy preview for el-data-table ready!

Built with commit 9c3631b

https://deploy-preview-320--el-data-table.netlify.app

@shoyuf shoyuf marked this pull request as draft September 9, 2020 06:05
@shoyuf shoyuf marked this pull request as ready for review September 9, 2020 07:33
['', undefined, null].indexOf(value) > -1 ||
(Array.isArray(value) && value.length === 0)

export const dealQuery = query =>
Copy link
Member

Choose a reason for hiding this comment

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

为什么要写在一起
即使写到一起,文件名是否应该改改

['', undefined, null].indexOf(value) > -1 ||
(Array.isArray(value) && value.length === 0)

export const dealQuery = query =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

removeKeyIsFalsey

@levy9527
Copy link
Contributor

pr上的描述,太技术性了,缺少业务场景的语言,需要回答:解决了什么场景问题;实现了用户价值

@snowlocked snowlocked self-requested a review September 11, 2020 06:15
@levy9527 levy9527 merged commit 82768b8 into FEMessage:dev Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

searchForm 修改input后刷新页面,已修改又被默认值覆盖了
4 participants