Skip to content

Commit

Permalink
refactor(console): evalution list/compare/results by only datastore a…
Browse files Browse the repository at this point in the history
…pi (#1676)

* feat: refactor evalution list/compare/results

* fix: store init error

* update:remove log, update deps
  • Loading branch information
waynelwz authored Dec 28, 2022
1 parent fd21946 commit ee7f008
Show file tree
Hide file tree
Showing 14 changed files with 527 additions and 869 deletions.
13 changes: 9 additions & 4 deletions console/packages/starwhale-ui/src/GridTable/GridTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function GridTable({
}, [store])

useEffect(() => {
if (columns.length > 0) {
if (!store.isInit && columns.length > 0) {
api.setState({
isInit: true,
currentView: {
Expand All @@ -91,7 +91,7 @@ function GridTable({
},
})
}
}, [columns, api])
}, [store.isInit, columns, api])

const [, theme] = useStyletron()
const styles = useStyles({ theme })
Expand Down Expand Up @@ -146,9 +146,14 @@ function GridTable({

export const MemoGridTable = React.memo(GridTable, areEqual)

export default function ContextGridTable({ storeKey = 'table', initState = {}, ...rest }: IContextGridTable) {
export default function ContextGridTable({
storeKey = 'table',
initState = {},
store = undefined,
...rest
}: IContextGridTable) {
return (
<StoreProvider initState={initState} storeKey={storeKey}>
<StoreProvider initState={initState} storeKey={storeKey} store={store}>
<MemoGridTable {...rest} />
</StoreProvider>
)
Expand Down
5 changes: 3 additions & 2 deletions console/packages/starwhale-ui/src/GridTable/StoreContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { useStore } from 'zustand'
import { createCustomStore, ITableState, IStore } from '../base/data-table/store'

type IStoreProviderProps = {
store?: IStore
storeKey?: string
initState: Partial<ITableState>
children: React.ReactNode
}

const TableContext = createContext<IStore | null>(null)

export function StoreProvider({ storeKey = 'store', initState, children }: IStoreProviderProps) {
export function StoreProvider({ storeKey = 'store', initState, store, children }: IStoreProviderProps) {
const storeRef = React.useRef<IStore>()
if (!storeRef.current) {
storeRef.current = createCustomStore(storeKey, initState)
storeRef.current = store ?? createCustomStore(storeKey, initState)
}
return <TableContext.Provider value={storeRef.current}>{children}</TableContext.Provider>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { ColumnSchemaDesc, DataTypes } from '@starwhale/core/datastore'
import { BooleanColumn, NumericalColumn, StringColumn } from '../../base/data-table'
import { ColumnT, FilterTypes } from '../../base/data-table/types'

const isPrivateSys = (str: string) => str.startsWith('sys/_')

export function useDatastoreColumns(columnTypes: ColumnSchemaDesc[]): ColumnT[] {
const columns = React.useMemo(() => {
const columnsWithAttrs: ColumnT[] = []

columnTypes?.forEach((column) => {
if (isPrivateSys(column.name)) return

switch (column.type) {
default:
break
Expand Down
3 changes: 2 additions & 1 deletion console/packages/starwhale-ui/src/GridTable/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Types } from '../base/data-table'
import { ITableState } from '../base/data-table/store'
import { IStore, ITableState } from '../base/data-table/store'
import { RowT } from '../base/data-table/types'

export interface ITableProps {
Expand Down Expand Up @@ -28,6 +28,7 @@ export interface IPaginationProps {
}

export type IContextGridTable = {
store?: IStore
storeKey?: string
initState?: Partial<ITableState>
} & ITableProps
Loading

0 comments on commit ee7f008

Please sign in to comment.