Skip to content

Commit

Permalink
Tabs tab className, DataTable expose processed entities ids array, ty…
Browse files Browse the repository at this point in the history
…pings update
  • Loading branch information
CyberCookie committed Mar 24, 2024
1 parent d9a7194 commit 3efe2da
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 17 deletions.
2 changes: 2 additions & 0 deletions client_core/router/Router/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//TODO: support url with "//" like delimeters

import React, { Suspense, useState, useLayoutEffect } from 'react'

import isNullable from '../../../common/is/nullable'
Expand Down
4 changes: 2 additions & 2 deletions client_core/store/fetch_module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const actions: Actions = {
state.lastError = res

state.errRes[ID]
? state.errRes[ID].push(res)
? state.errRes[ID]!.push(res)
: state.errRes[ID] = [ res ]

setState(state)
Expand All @@ -61,7 +61,7 @@ const actions: Actions = {
const errorsById = store.state.errRes[ID]

return errorsById && errorsById.length
? errorsById.at(-1).message
? errorsById.at(-1)!.message
: ''
}
}
Expand Down
11 changes: 8 additions & 3 deletions client_core/store/fetch_module/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import type { HookStore } from '../index'


type AnyError = {
date: number
} & Obj


type State = {
requests: Obj<number>
errRes: Obj
lastError: Obj
errRes: Obj<AnyError[]>
lastError: AnyError
}

type Actions = {
Expand All @@ -18,4 +23,4 @@ type Actions = {
type StoreInitialized = HookStore<State, Actions>


export type { State, Actions, StoreInitialized }
export type { State, Actions, StoreInitialized, AnyError }
3 changes: 2 additions & 1 deletion client_core/ui/DataTable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ Configurable and flexible data grid to manage big amount of data, built on top o
- `searchByField` - **Object** Entities filtering params, where key is a column ID and value is a filtering value
- `toggleColumns` - **Set<props.columnsConfig.ID>**. Column IDs to be hidden
- `showPerPage` - **Number**. Number of entities showed per one pagination page
- `currentPage` - **Number**. Current pagination page<br /><br />
- `currentPage` - **Number**. Current pagination page starting from 1
- `__resultIDs` - **string[]**. Readonly inner filtered `props.entities.sorted` array of entities IDs */<br /><br />

- `rootTagAttributes`
- **div** tag attributes<br /><br />
Expand Down
6 changes: 5 additions & 1 deletion client_core/ui/DataTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const getDefaultState: () => State = () => ({
searchByField: {},
toggledColumns: new Set(),
showPerPage: 0,
currentPage: 1
currentPage: 1,
__resultIDs: []
})

const DataTable = component<Props, DefaultProps>(
Expand Down Expand Up @@ -106,6 +107,9 @@ const DataTable = component<Props, DefaultProps>(
dataTableTableProps = resolveTagAttributes(dataTableTableProps, tableAttributes)


state.__resultIDs = resultIDs


return (
<div { ...rootAttributes }>
<Table { ...dataTableTableProps } />
Expand Down
3 changes: 3 additions & 0 deletions client_core/ui/DataTable/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type State<_SearchState = any> = {

/** Current pagination page */
currentPage: number

/** Readonly inner filtered props.entities.sorted array of entities IDs */
__resultIDs: string[]
}


Expand Down
2 changes: 1 addition & 1 deletion client_core/ui/Popup/styles.sass
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
top: 0
width: 100%
height: 100%
z-index: 999
z-index: 200

.close
cursor: pointer
20 changes: 16 additions & 4 deletions client_core/ui/Tabs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//TODO?: no render labels when only one
//TODO: tab content className

import React from 'react'

Expand All @@ -21,10 +20,22 @@ const getContent = (content: Tab['content']) => (
: content
)

const getContentClassName = (
{ content }: MergedProps['theme'],
tabClassName: Tab['className']
) => (
content
? tabClassName
? `${content} ${tabClassName}`
: content
: tabClassName
)

function getTabsVisual(mergedProps: MergedProps) {
const { tabs, activeTab, onChange, theme, showEmpty, renderAll } = mergedProps

const tabsContent: React.ReactNode[] = []
let tabContentClassName
const labels = tabs.map(tab => {
const { label, id, payload, content, className } = tab

Expand All @@ -34,18 +45,18 @@ function getTabsVisual(mergedProps: MergedProps) {
let tabContent = getContent(content)
if (renderAll) {
const wrapperProps: ReactTagAttributes<HTMLDivElement> = {
className,
children: tabContent,
key: id
}
isSelected
? (wrapperProps.className = theme.content)
? (wrapperProps.className = getContentClassName(theme, className))
: (wrapperProps.style = { display: 'none' })

tabContent = <div { ...wrapperProps } />
}

tabsContent.push(tabContent)
isSelected && (tabContentClassName = className)
}


Expand All @@ -65,7 +76,8 @@ function getTabsVisual(mergedProps: MergedProps) {
activeTabContent: (showEmpty || tabsContent.length)
? renderAll
? tabsContent
: <div className={ theme.content } children={ tabsContent[0] } />
: <div className={ getContentClassName(theme, tabContentClassName) }
children={ tabsContent[0] } />
: _undef,
labels: <div className={ theme.labels_wrapper } children={ labels } />
}
Expand Down
6 changes: 3 additions & 3 deletions demo_app/client/main/pages/DemoComponents/components/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useState } from 'react'

import { Tabs } from 'app/components'
import { Tabs, TabsProps } from 'app/components'


const tabsData = ([ 1, 2, 3 ]).map(id => ({
const tabsData: TabsProps['tabs'] = ([ 1, 2, 3 ]).map(id => ({
id: `${id}`,
content: <div>content {id}</div>,
content: `content ${id}`,
label: `label ${id}`
}))

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "siegel",
"version": "0.14.87",
"version": "0.14.88",
"homepage": "https://siegel-qe3q.onrender.com",
"url": "https://github.com/CyberCookie/siegel",
"bugs": "https://github.com/CyberCookie/siegel/issues",
Expand Down

0 comments on commit 3efe2da

Please sign in to comment.