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(console): add model viewer #1627

Merged
merged 3 commits into from
Dec 19, 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
3 changes: 2 additions & 1 deletion console/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dist/
node_modules/
*.min.js
BaseTable/
stories/
stories/
packages/starwhale-ui/src/base/
3 changes: 2 additions & 1 deletion console/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ module.exports = {
// @FIXME check
'import/no-extraneous-dependencies': 'off',
'import/no-restricted-imports': 'off',
'no-restricted-imports': 'off',
},
settings: {
'react': {
Expand All @@ -133,5 +134,5 @@ module.exports = {
},
},
],
ignorePatterns: ['.eslintrc.js', 'craco.config.js', '__generated__'],
ignorePatterns: ['.eslintrc.js', 'craco.config.js', '__generated__', 'vite.config.ts'],
}
6 changes: 3 additions & 3 deletions console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
},
"scripts": {
"typecheck": "tsc --noEmit -p ./tsconfig.json",
"lint": "eslint -c .eslintrc.js './src/**/*.{ts,tsx}'",
"lint:fix": "eslint --fix -c .eslintrc.js './src/**/*.{ts,tsx}'",
"lint": "eslint -c .eslintrc.js './{src,packages}/**/*.{ts,tsx}'",
"lint:fix": "eslint --fix -c .eslintrc.js './{src,packages}/**/*.{ts,tsx}'",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"start": "vite --host 0.0.0.0",
Expand Down Expand Up @@ -252,4 +252,4 @@
"framer-motion": "4.1.17",
"react-virtualized": "git+https://git@github.com/remorses/react-virtualized-fixed-import.git#9.22.3"
}
}
}
8 changes: 4 additions & 4 deletions console/packages/starwhale-core/src/datastore/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ColumnFilterModel {
}
]
*/
addQuery(
static getQuery(
columnName: string,
value: string,
operator: OPERATOR,
Expand Down Expand Up @@ -103,8 +103,8 @@ export class ColumnFilterModel {
default:
break
}
let operands = [{ columnName }]
if (!queryType) return
const operands = [{ columnName }]
if (!queryType) return undefined
operands.push({ [queryType]: value } as any)

return {
Expand All @@ -121,7 +121,7 @@ export class ColumnFilterModel {
.filter((item: any) => item?.value && item?.op && item?.property)
.map((item: any) => {
const field = fields.find((f) => f.name === item.property) as any
return this.addQuery(field?.name, item.value, item.op, field?.type as DataTypes)
return ColumnFilterModel.getQuery(field?.name, item.value, item.op, field?.type as DataTypes)
})
if (filters.length === 1) return filters[0]?.filter

Expand Down
9 changes: 7 additions & 2 deletions console/packages/starwhale-core/src/form/WidgetForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ function WidgetForm({ formData, onChange, onSubmit, form }: any, ref: any) {
validator={validator}
onSubmit={onSubmit}
// @ts-ignore
ref={(form) => (ref.current = form)}
onChange={(e) => onChange?.(e.formData)}
ref={(f) => {
// eslint-disable-next-line no-param-reassign
ref.current = f
}}
onChange={(e) => {
onChange?.(e.formData)
}}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class WidgetFormModel implements WidgetFieldConfig {
const { schema, uiSchema = {} } = this.widget?.config?.fieldConfig ?? {}
Object.keys(uiSchema).forEach((property) => {
if (uiSchema[property]?.[UI_DATA_KEY] === UI_DATA.DataTableColumns) {
this.addField(dataTableColumnsField(property, columnTypes, schema, uiSchema))
this.addField(dataTableColumnsField(property, columnTypes, schema))
}
})
return this
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions console/packages/starwhale-core/src/form/schemas/fields.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RJSFSchema, UiSchema } from '@rjsf/utils'
import { RJSFSchema } from '@rjsf/utils'
import { ColumnSchemaDesc } from '@starwhale/core/datastore'
import { WidgetFactory } from '@starwhale/core/widget'

export const UI_DATA_KEY = 'ui:data'
// eslint-disable-next-line @typescript-eslint/naming-convention
export enum UI_DATA {
DataTableColumns = 'DataTableColumns',
}
Expand All @@ -24,7 +25,7 @@ export const chartTypeField = (): RJSFSchema | undefined => {
}
}

export const tableNameField = (tables: any, schema?: RJSFSchema, uiSchema?: UiSchema): RJSFSchema | undefined => {
export const tableNameField = (tables: any, schema?: RJSFSchema): RJSFSchema | undefined => {
if (!tables || tables.length === 0) return undefined
const { type } = schema?.tableName ?? {}

Expand Down Expand Up @@ -68,8 +69,7 @@ export const chartTitleField = (): RJSFSchema | undefined => ({
export const dataTableColumnsField = (
property: string,
columnTypes: ColumnSchemaDesc[],
schema?: RJSFSchema,
uiSchema?: UiSchema
schema?: RJSFSchema
): RJSFSchema | undefined => {
if (!columnTypes || columnTypes.length === 0) return undefined

Expand Down
2 changes: 1 addition & 1 deletion console/packages/starwhale-core/src/utils/path.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function getTreePath(state: any, id: string) {
}

function walk(nodes: WidgetTreeNode[], paths: any) {
return nodes.map((node: WidgetTreeNode, i) => {
nodes.forEach((node: WidgetTreeNode, i) => {
const currPaths = []
if (node.id === id) {
rtn = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useLayoutEffect, useMemo, useRef } from 'react'

type Fn<ARGS extends any[], R> = (...args: ARGS) => R

const useEventCallback = <A extends any[], R>(fn: Fn<A, R>): Fn<A, R> => {
export const useEventCallback = <A extends any[], R>(fn: Fn<A, R>): Fn<A, R> => {
const ref = useRef<Fn<A, R>>(fn)
useLayoutEffect(() => {
ref.current = fn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react'

export default function useForceUpdate() {
const [_, setValue] = useState(0)
const [, setValue] = useState(0)
return () => setValue((prevState) => prevState + 1)
}
9 changes: 4 additions & 5 deletions console/packages/starwhale-core/src/widget/WidgetModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ class WidgetModel implements WidgetConfig {
if (!id) {
this.generateId()
}
// @FIXME check properties
for (const key in properties) {
Object.keys(properties).forEach((key) => {
;(this as any)[key] = properties[key]
}
})
}

setDynamicVars(globalDynamicVars: any) {
Expand Down Expand Up @@ -106,9 +105,9 @@ class WidgetModel implements WidgetConfig {

getPersistProperty(): WidgetConfig {
const properties = {} as WidgetConfig
for (const key in PersistProperty) {
Object.keys(PersistProperty).forEach((key) => {
;(properties as any)[key] = (this as any)[key]
}
})
return properties
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
// eslint-disable-next-line max-classes-per-file
import { WidgetComponent, WidgetConfig, WidgetFieldConfig, WidgetMeta } from '../types'

export type WidgetState = Record<string, unknown>
Expand Down
1 change: 0 additions & 1 deletion console/packages/starwhale-ui/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"rules": {
"no-restricted-imports": ["error", { "patterns": ["@grafana/runtime", "@grafana/data/*", "@grafana/ui/*", "@grafana/e2e/*"] }]
}
}
10 changes: 7 additions & 3 deletions console/packages/starwhale-ui/src/IconFont/fonts/iconfont.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@font-face {
font-family: "iconfont"; /* Project id 3410006 */
src: url('iconfont.woff2?t=1667979623500') format('woff2'),
url('iconfont.woff?t=1667979623500') format('woff'),
url('iconfont.ttf?t=1667979623500') format('truetype');
src: url('iconfont.woff2?t=1671173216154') format('woff2'),
url('iconfont.woff?t=1671173216154') format('woff'),
url('iconfont.ttf?t=1671173216154') format('truetype');
}

.iconfont {
Expand All @@ -13,6 +13,10 @@
-moz-osx-font-smoothing: grayscale;
}

.icon-file2:before {
content: "\e657";
}

.icon-a-Addabove:before {
content: "\e654";
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"css_prefix_text": "icon-",
"description": "",
"glyphs": [
{
"icon_id": "33295022",
"name": "file2",
"font_class": "file2",
"unicode": "e657",
"unicode_decimal": 58967
},
{
"icon_id": "32592454",
"name": "Add above",
Expand Down
4 changes: 2 additions & 2 deletions console/packages/starwhale-ui/src/IconFont/fonts/iconfont.ttf
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 4 additions & 0 deletions console/packages/starwhale-ui/src/IconFont/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import emptySvg from './empty.svg'
import emptyChart from './empty-chart.svg'
import searchEmptySvg from './search-empty.svg'
import googleSvg from './google.svg'
import invalidFile from './invalid-file.svg'

const iconTypes = [
'arrow2_down',
Expand Down Expand Up @@ -70,6 +71,8 @@ const iconTypes = [
'a-Addabove',
'a-Addbelow',
'arrow2',
'file',
'file2',
]

interface IIconFontProps {
Expand All @@ -86,6 +89,7 @@ const hijacked = {
empty: emptySvg,
emptyChart,
searchEmpty: searchEmptySvg,
invalidFile,
}

export default function IconFont({ size = 14, type = 'user', kind = 'inherit', style = {} }: IIconFontProps) {
Expand Down
73 changes: 73 additions & 0 deletions console/packages/starwhale-ui/src/IconFont/invalid-file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading