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

refactor(console): evalution list/compare/results by only datastore api #1676

Merged
merged 4 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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