Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1. eva operator error
2. summary decimal optimize
  • Loading branch information
waynelwz committed Sep 15, 2022
1 parent 6497e25 commit cb8bcf4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 61 deletions.
34 changes: 2 additions & 32 deletions console/src/components/data-table/filter-operate-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const Operators: Record<string, OperatorT> = {
// @ts-ignore
buildFilter: () => {
return (data: string, row: any, column: any) => {
return column.key in row || row?.attributes.map((attr: any) => attr.name).includes(column.key)
return column.key in row || column.key in row?.attributes
}
},
},
Expand All @@ -98,7 +98,7 @@ export const Operators: Record<string, OperatorT> = {
op: 'not exists',
buildFilter: () => {
return (data: string, row: any, column: any) => {
return !(column.key in row || row?.attributes.map((attr: any) => attr.name).includes(column.key))
return !(column.key in row) && !(column.key in row?.attributes)
}
},
},
Expand Down Expand Up @@ -155,10 +155,6 @@ export default function FilterOperateSelector({
disabled,
columns,
}: IFilterOperateSelectorProps) {
// const [key, setKey] = useState<string | undefined>(raw?.key)
// const [value, setValue] = useState<string | undefined>(raw?.value)
// const [operator, setOperator] = useState<string | undefined>(raw?.op || '=')

const { key = '', value = '', op = Operators.equal } = raw

const $keys = React.useMemo(() => {
Expand Down Expand Up @@ -235,32 +231,6 @@ export default function FilterOperateSelector({
value={value}
/>
)}
{/* <Select
size='compact'
disabled={disabled}
overrides={overrides}
options={options}
placeholder='-'
clearable={false}
onChange={({ value }) => {
// @ts-ignore
setValue(value)
}}
mountNode={document.body}
onInputChange={(e) => {
const target = e.target as HTMLInputElement
}}
onBlurResetsInput={false}
value={
value
? [
{
id: value,
},
]
: []
}
/> */}
</div>
)
}
34 changes: 6 additions & 28 deletions console/src/pages/Evaluation/EvaluationListCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import { useFetchViewConfig } from '@/domain/evaluation/hooks/useFetchViewConfig
import { setEvaluationViewConfig } from '@/domain/evaluation/services/evaluation'
import { useQueryDatasetList } from '@/domain/datastore/hooks/useFetchDatastore'
import { tableNameOfSummary } from '@/domain/datastore/utils'
import { unhexlify } from '@/domain/datastore/sdk'
import { useProject } from '@/domain/project/hooks/useProject'
import { TextLink } from '@/components/Link'
import { parseDecimal } from '@/utils'
import EvaluationListCompare from './EvaluationListCompare'

const gridLayout = [
Expand Down Expand Up @@ -64,7 +64,7 @@ export default function EvaluationListCard() {
if (!project?.name) return ''
return tableNameOfSummary(project?.name as string)
}, [project])
const summaryTable = useQueryDatasetList(summaryTableName, page)
const summaryTable = useQueryDatasetList(summaryTableName, page, true)

// TODO
// 1. column key should be equal with eva attr field
Expand Down Expand Up @@ -174,9 +174,9 @@ export default function EvaluationListCard() {
},
// @ts-ignore
renderCell: (props: any) => {
return <p title={props?.value}>{props?.value}</p>
return <p title={props?.value}>{parseDecimal(props?.value, 4)}</p>
},
mapDataToValue: (data: any): string => data.attributes?.[name] ?? '-',
mapDataToValue: (data: any): string => data.attributes?.[name] ?? 0,
})
)
break
Expand All @@ -188,28 +188,8 @@ export default function EvaluationListCard() {

const $summaryAttrs = useMemo(() => {
if (!summaryTable?.data) return {}

const { columnTypes = {}, records = [] } = summaryTable?.data || {}

const $records = records?.map((attrs) => {
const $newAttributes: Record<string, any> = {}
Object.keys(attrs).forEach((key) => {
switch (columnTypes[key]) {
case 'UNKNOWN':
case 'BYTES':
$newAttributes[key] = ''
break
case 'STRING':
$newAttributes[key] = attrs[key]
break
default:
$newAttributes[key] = unhexlify(attrs[key])
}
})
return $newAttributes
})

const $recordsMap = _.keyBy($records, 'id')
const { records = [] } = summaryTable?.data || {}
const $recordsMap = _.keyBy(records, 'id')
return $recordsMap
}, [summaryTable.data])

Expand Down Expand Up @@ -241,8 +221,6 @@ export default function EvaluationListCard() {
[evaluationsInfo.data, $summaryAttrs]
)

// console.log($summaryAttrs, $data)

const [gridMode, setGridMode] = useState(1)
const resizeRef = React.useRef<HTMLDivElement>(null)
const gridRef = React.useRef<HTMLDivElement>(null)
Expand Down
2 changes: 1 addition & 1 deletion console/src/pages/Evaluation/EvaluationListCompare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function EvaluationListCompare({
if (!store.isInit) {
store.onCompareUpdate({
compareShowCellChanges: true,
compareShowDiffOnly: true,
compareShowDiffOnly: false,
})
}
if (pinKey !== store.compare?.comparePinnedKey) {
Expand Down
6 changes: 6 additions & 0 deletions console/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,9 @@ export function longestCommonSubstring(string1: string, string2: string) {
}
return longestSubstring
}

export function parseDecimal(v: number, decimal: number): string {
if (v === 0) return String(v)
if (v.toString().indexOf('.') === -1) return String(v)
return Number(v).toFixed(decimal)
}

0 comments on commit cb8bcf4

Please sign in to comment.