Skip to content

Commit

Permalink
feat: improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
50l3r committed Apr 23, 2024
1 parent 5b23024 commit ebe1e80
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kodama-ui",
"version": "0.30.0",
"version": "0.31.1",
"description": "Kodama UI is a Vue 3 component library that provides a set of components & funcionality to build your application.",
"homepage": "https://50l3r.github.io/kodama-ui",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/components/data-display/k-table/filters/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
const tooltip = ref()
const filter = (
operator: QueryFilterOperator,
operator: string,
value: KTableColumnFilter['value']
) => {
ctx.emit('filter', { [operator]: value })
Expand Down
4 changes: 2 additions & 2 deletions src/components/data-display/k-table/k-table.types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ExtractPropTypes, SetupContext } from 'vue'
import { QueryFilterFields, QueryParams } from '../../../store/modules/query'
import { QueryParams } from '../../../store/modules/query'
import Props from './k-table.props'

export type KTableParams = {
page: number
order: QueryParams['order']
filter: QueryFilterFields | null
filter: QueryParams['filter']
limit: QueryParams['limit']
reset: boolean
strict: QueryParams['strict']
Expand Down
1 change: 0 additions & 1 deletion src/components/data-display/k-table/k-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@
ctx.emit('fetch', query.value)
emitter.on(`ktable_${props.store}_fetch`, () => {
console.log('emite')
ctx.emit('fetch', query.value)
})
})
Expand Down
11 changes: 4 additions & 7 deletions src/components/data-display/k-table/lib/filter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { computed, reactive } from 'vue'
import { useQuery } from '../../../../store'
import {
QueryFilterField,
QueryFilterFields
} from '../../../../store/modules/query'
import { QueryFilter } from '../../../../store/modules/query'
import { KTableContext, KTableParams, KTableProps } from '../k-table.types'
// import cloneDeep from 'lodash.clonedeep'

Expand Down Expand Up @@ -59,7 +56,7 @@ export default function (ctx: KTableContext, props: KTableProps): any {
ctx.emit('fetch', query.value)
}

const filter = (field: string, filter: QueryFilterField | null) => {
const filter = (field: string, filter: QueryFilter | null) => {
const queryStore = useQuery()

if (props.store) {
Expand Down Expand Up @@ -184,7 +181,7 @@ export default function (ctx: KTableContext, props: KTableProps): any {

const mergeFilters = (
required: any = null,
custom: QueryFilterFields | null = null,
custom: QueryFilter | null = null,
strict = true
) => {
if (!required && !custom) return null
Expand All @@ -200,7 +197,7 @@ export default function (ctx: KTableContext, props: KTableProps): any {

const requiredFields = getFieldFilters(required)

const customFilters: QueryFilterFields[] = []
const customFilters: QueryFilter[] = []

Object.keys(custom).forEach((field) => {
const find = requiredFields.find((f) => f.field === field)
Expand Down
2 changes: 1 addition & 1 deletion src/components/data-entry/k-checkbox/k-checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
const hasSlot = (name: string) => !!ctx.slots[name]
const classes = computed(() => {
let classes = []
let classes: string[] = []
if (props.color === 'white' || props.color === 'black') {
classes.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
})
const inputClasses = computed(() => {
const classes = []
const classes: string[] = []
if (props.size === 'sm') classes.push('text-sm')
if (props.size === 'md') classes.push('text-base')
Expand Down
2 changes: 1 addition & 1 deletion src/components/data-entry/k-radio/k-radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
const hasSlot = (name: string) => !!ctx.slots[name]
const classes = computed(() => {
let classes = []
let classes: string[] = []
if (props.color === 'white' || props.color === 'black') {
classes.push(
Expand Down
4 changes: 2 additions & 2 deletions src/components/feedback/k-modal/k-modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
})
const defaultBackdropClasses = computed(() => {
const classes = [
const classes: string[] = [
'bg-gray-900 bg-opacity-50 dark:bg-opacity-80 fixed inset-0'
]
Expand All @@ -234,7 +234,7 @@
})
const contentClasses = computed(() => {
const classes = []
const classes: string[] = []
if (props.size === 'xs') {
classes.push('max-w-md')
Expand Down
2 changes: 2 additions & 0 deletions src/config/_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface CustomConfig extends Partial<Config> {
profile: RouteLocationRaw
configuration: RouteLocationRaw
}

[x: string | number]: unknown
}

export enum AvatarType {
Expand Down
60 changes: 24 additions & 36 deletions src/store/modules/query.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
import { defineStore } from 'pinia'

export type QueryFilterOperator =
| '$eq'
| '$neq'
| '$gt'
| '$lt'
| '$gte'
| '$lte'
| '$in'
| '$nin'
| '$like'
| '$from'
| '$to'

type QueryCondition = '$and' | '$or'

export type QueryFilterCondition = Partial<
Record<
QueryCondition,
Array<
| QueryFilterFields[]
| Partial<
Record<
QueryCondition,
QueryFilterFields[] | QueryFilterCondition[]
>
>
>
>
>
export type QueryFilterFields = Record<string, QueryFilterField>
export type QueryFilterField = Partial<Record<QueryFilterOperator, any>>

export type QueryFilter = Partial<
Record<QueryCondition, Array<QueryFilterFields | QueryFilterCondition>>
>
export type QueryFilterOperator = {
$eq?: string | number
$neq?: string | number
$gt?: number
$lt?: number
$gte?: number
$lte?: number
$in?: (string | number)[]
$nin?: (string | number)[]
$like?: string
$from?: string | Date
$to?: string | Date
}

export type QueryCondition = {
[key: string]: QueryFilterOperator
}

export type QueryLogicalOperator = {
$and?: QueryFilter[]
$or?: QueryFilter[]
}

export type QueryFilter = QueryCondition | QueryLogicalOperator
export type QueryOrder = Record<string, 'asc' | 'desc'>

export type QueryParams = {
order: QueryOrder | null
filter: QueryFilterFields | null
filter: QueryFilter | null
limit: number
strict: boolean
}
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"noImplicitAny": false,
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
Expand Down

0 comments on commit ebe1e80

Please sign in to comment.