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

Feat/table search feature #286

Merged
merged 21 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
de11500
feat: [table] search feature (wip)
mattgoud Dec 21, 2023
d388626
feat: [table-search] wip
mattgoud Jan 4, 2024
556a41e
feat: [table-search] handle searchReset value on submit
mattgoud Jan 7, 2024
80260bb
feat: [table-search] remove tableSearchBar sub-component
mattgoud Jan 7, 2024
833feb3
docs: [table-search] update storybook
mattgoud Jan 8, 2024
5bd45f8
test: [table-search] update tests
mattgoud Jan 8, 2024
e495aa4
feat: [table] install tailwind-scrollbar, update table scrollbar style
mattgoud Jan 8, 2024
b2843ce
feat: [table-search] trigger event submit when enter key is pressed
mattgoud Jan 8, 2024
55dfed6
feat: [table-search] remove inline style (padding in loading cells)
mattgoud Jan 8, 2024
06f14a5
Update packages/components/table/src/table-search-input.vue
mattgoud Jan 16, 2024
ddd6aca
feat: [table-search] change type for minValue & maxValue
mattgoud Jan 16, 2024
ad80b17
fix: [github-checks] fix linter checks
mattgoud Jan 16, 2024
a524480
fix: [chromatic-deployment] try to fix github action
mattgoud Jan 17, 2024
65bfc17
Merge branch 'main' into feat/table-search-feature
mattgoud Jan 17, 2024
c36a6b2
fix: try fix chromatic deployment (2)
mattgoud Jan 17, 2024
2adbb50
Merge branch 'feat/table-search-feature' of github.com:PrestaShopCorp…
mattgoud Jan 17, 2024
e7104b4
fix: try fix chromatic deployment (3)
mattgoud Jan 17, 2024
60f5728
Merge branch 'main' into feat/table-search-feature
mattgoud Jan 18, 2024
338eb52
feat: [table-search] submit event: send a row array of searchOptions …
mattgoud Jan 18, 2024
cf27e69
ci: max-length for commit message from 72 to 100
mattgoud Jan 18, 2024
0d25d32
Merge branch 'main' into feat/table-search-feature
mattgoud Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"cSpell.words": ["Puik", "puik"],
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.fixAll.eslint": false
"source.fixAll": "never",
"source.fixAll.eslint": "explicit"
},
"npm.packageManager": "pnpm",
"eslint.probe": [
Expand Down
24 changes: 11 additions & 13 deletions packages/components/input/src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import { buildProps } from '@puik/utils'
import type { ExtractPropTypes, PropType } from 'vue'
import type Input from './input.vue'

export const inputTypes = [
'text',
'password',
'email',
'number',
'search',
'url',
'tel',
] as const

export type PuikInputType = (typeof inputTypes)[number]
export enum PuikInputTypes {
Text = 'text',
Password = 'password',
Email = 'email',
Number = 'number',
Search = 'search',
Url = 'url',
Phone = 'tel',
}

export const inputProps = buildProps({
modelValue: {
Expand All @@ -21,9 +19,9 @@ export const inputProps = buildProps({
default: '',
},
type: {
type: String as PropType<PuikInputType>,
type: String as PropType<PuikInputTypes>,
required: false,
default: 'text',
default: PuikInputTypes.Text,
},
id: {
type: String,
Expand Down
2 changes: 2 additions & 0 deletions packages/components/table-search-input/style/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@puik/components/base/style/css'
import '@puik/theme/puik-table-search-input.css'
2 changes: 2 additions & 0 deletions packages/components/table-search-input/style/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@puik/components/base/style'
import '@puik/theme/src/table-search-input.scss'
4 changes: 4 additions & 0 deletions packages/components/table/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { withInstall } from '@puik/utils'

import Table from './src/table.vue'
import TableSearchInput from './src/table-search-input.vue'

export const PuikTable = withInstall(Table)
export const PuikTableSearchInput = withInstall(TableSearchInput)

export default PuikTable

export * from './src/table'
export * from './src/table-search-input'
53 changes: 53 additions & 0 deletions packages/components/table/src/table-search-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { buildProps } from '@puik/utils'
import type { ExtractPropTypes, PropType } from 'vue'
import type TableSearchInput from './table-search-input.vue'

export enum PuikTableSearchInputTypes {
Text = 'text',
Range = 'range',
}

export type inputRange = {
min?: number
max?: number
}

export type searchOption = {
searchBy: string
inputText?: string
inputRange?: inputRange
}

export const tableSearchInputProps = buildProps({
name: {
type: String,
required: false,
default: '',
},
column: {
type: String,
required: false,
default: '',
},
searchSubmit: {
type: Boolean,
required: false,
default: false,
},
searchReset: {
type: Boolean,
required: false,
default: false,
},
searchType: {
type: String as PropType<PuikTableSearchInputTypes>,
required: false,
default: PuikTableSearchInputTypes.Text,
},
} as const)

export type TableSearchInputProps = ExtractPropTypes<
typeof tableSearchInputProps
>

export type TableSearchInputInstance = InstanceType<typeof TableSearchInput>
117 changes: 117 additions & 0 deletions packages/components/table/src/table-search-input.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<template>
<div class="puik-table__head__row__item__container">
<div
class="puik-table__head__row__item__content puik-table-search-input__content"
>
<PuikInput
v-if="
!props.searchSubmit &&
props.searchType === PuikTableSearchInputTypes.Text
"
v-model="inputTextValue"
:type="PuikInputTypes.Text"
:placeholder="t('puik.table.search')"
@update:model-value="sendTextValue(props.column, inputTextValue)"
/>
<div
v-if="
!props.searchSubmit &&
props.searchType === PuikTableSearchInputTypes.Range
"
class="puik-table-search-input--range"
>
<PuikInput
v-model="inputMinValue"
:type="PuikInputTypes.Number"
:placeholder="t('puik.table.min')"
@update:model-value="
sendRangeValue(props.column, inputMinValue, inputMaxValue)
"
/>
<PuikInput
v-model="inputMaxValue"
:type="PuikInputTypes.Number"
:placeholder="t('puik.table.max')"
@update:model-value="
sendRangeValue(props.column, inputMinValue, inputMaxValue)
"
/>
</div>
<template v-if="props.searchSubmit">
<div class="puik-table-search-input--submit">
<puik-button left-icon="search" @click="$emit('searchSubmitEvent')">
{{ t('puik.table.search') }}
</puik-button>
<div
v-if="props.searchReset"
class="puik-table-search-input--reset"
@click="$emit('searchResetEvent')"
>
<puik-button left-icon="close" variant="text" size="sm">
{{ t('puik.table.reset') }}
</puik-button>
</div>
</div>
</template>
</div>
</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useLocale } from '@puik/hooks'
import { PuikButton } from '@puik/components/button'
import { PuikInput, PuikInputTypes } from '@puik/components/input'
import {
tableSearchInputProps,
PuikTableSearchInputTypes,
} from './table-search-input'
import type { searchOption, inputRange } from './table-search-input'
defineOptions({
name: 'PuikTableSearchInput',
})

const props = defineProps(tableSearchInputProps)

const emit = defineEmits<{
(e: 'searchTextValue', column: searchOption): void
(e: 'searchRangeValue', column: searchOption): void
(e: 'searchSubmitEvent'): void
(e: 'searchResetEvent'): void
}>()

const { t } = useLocale()

const inputTextValue = ref<string>()
const inputMinValue = ref<number>()
const inputMaxValue = ref<number>()

const sendTextValue = (column: string, textValue?: string) => {
const searchOption: searchOption = {
searchBy: column,
inputText: textValue,
}
emit('searchTextValue', searchOption)
}

const sendRangeValue = (
column: string,
minValue?: number | string,
maxValue?: number | string
mattgoud marked this conversation as resolved.
Show resolved Hide resolved
) => {
minValue === '' || minValue === undefined
? (minValue = Number.NEGATIVE_INFINITY)
: minValue
maxValue === '' || maxValue === undefined
? (maxValue = Number.POSITIVE_INFINITY)
: maxValue
const searchOption: searchOption = {
searchBy: column,
inputRange: {
min: minValue,
max: maxValue,
} as inputRange,
}
mattgoud marked this conversation as resolved.
Show resolved Hide resolved
emit('searchRangeValue', searchOption)
}
</script>
14 changes: 14 additions & 0 deletions packages/components/table/src/table.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { buildProps } from '@puik/utils'
import type { ExtractPropTypes, PropType } from 'vue'
import type Table from './table.vue'
import type { PuikTableSearchInputTypes } from '../src/table-search-input'

export enum PuikTableSortOrder {
Asc = 'ASC',
Expand Down Expand Up @@ -31,6 +32,9 @@ export interface PuikTableHeader {
width?: string
sortable?: boolean
preventExpand?: boolean
searchable?: boolean
searchSubmit?: boolean
searchType?: `${PuikTableSearchInputTypes}`
}

export const tableProps = buildProps({
Expand Down Expand Up @@ -58,6 +62,16 @@ export const tableProps = buildProps({
required: false,
default: () => [],
},
searchBar: {
type: Boolean,
required: false,
default: false,
},
searchFromServer: {
type: Boolean,
required: false,
default: false,
},
sortFromServer: {
type: Boolean,
required: false,
Expand Down
Loading
Loading