Skip to content

Commit

Permalink
fix(console): eval result compare title & pinkey missing (#2518)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynelwz authored Jul 18, 2023
1 parent 8f983e2 commit 2ab2bf8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
20 changes: 9 additions & 11 deletions console/packages/starwhale-ui/src/GridTable/GridCompareTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,24 @@ export function BaseGridCompareTable({
React.useEffect(() => {
if (records.length === 0) return

const row = records.find((r) => val(getId(r)) === comparePinnedKey)
// const pinKey = row ? store.compare?.comparePinnedKey : val(records[0].id)

// console.log(row, pinKey, store.compare?.comparePinnedKey, val(records[0].id))
const row = records.find((r) => val(getId(r)) === comparePinnedKey && comparePinnedKey)

onCompareUpdate({
comparePinnedKey: row ? comparePinnedKey : val(records[0].id),
comparePinnedKey: row ? comparePinnedKey : val(getId(records[0])),
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [records, onCompareUpdate])

const comparePinnedRow: any = useMemo(() => {
return records.find((r) => val(r.id) === comparePinnedKey) ?? records[0]
}, [records, comparePinnedKey])
return records.find((r) => val(getId(r)) === comparePinnedKey) ?? records[0]
}, [records, comparePinnedKey, getId])

const comparePinnedRowIndex = useMemo(() => {
return Math.max(
records.findIndex((r) => val(r.id) === comparePinnedKey),
records.findIndex((r) => val(getId(r)) === comparePinnedKey),
0
)
}, [records, comparePinnedKey])
}, [records, comparePinnedKey, getId])

const $rowWithAttrs = useMemo(() => {
const rowWithAttrs: RowT[] = []
Expand All @@ -217,7 +214,7 @@ export function BaseGridCompareTable({
title: attr.name,
name: attr.name,
values,
renderValue: (v: any) => (_.isNumber(val(v)) ? durationToStr(val(v)) : '-'),
renderValue: (v: any) => (!_.isNaN(Number(val(v))) ? durationToStr(val(v)) : '-'),
})
return
}
Expand Down Expand Up @@ -256,7 +253,8 @@ export function BaseGridCompareTable({
CustomColumn({
minWidth: 200,
key: val(getId(row)),
title: [val(row['sys/model_name']), val(row['sys/id'])].join('-'),
title:
(row['sys/id'] ? [val(row['sys/model_name']), val(row['sys/id'])].join('-') : getId(row)) || '',
fillWidth: false,
// @ts-ignore
renderCell: (props: any) => {
Expand Down
12 changes: 7 additions & 5 deletions console/src/pages/Evaluation/EvaluationListResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { useEvaluationDetailStore } from '@starwhale/ui/GridTable/store'
import useTranslation from '@/hooks/useTranslation'
import useDatastorePage from '@starwhale/core/datastore/hooks/useDatastorePage'

function prefixColumn(row: any, prefix: string | number) {
return `${[row?.['sys/model_name']?.value, prefix].filter((v) => v !== undefined).join('/')}@`
function prefixColumn(row: any) {
return `${[row?.['sys/model_name']?.value, row?.['sys/id']?.value].filter((v) => v !== undefined).join('-')}@`
}

function getPrefixId(row: any, prefix: string | number) {
Expand All @@ -29,17 +29,18 @@ export default function DatastoreDiffTables({ rows }: { rows: ITableProps['recor

const tables = React.useMemo(
() =>
rows?.map((row, i) => {
rows?.map((row) => {
return {
tableName: tableNameOfResult(projectId, val(row.id)),
columnPrefix: prefixColumn(row, i),
columnPrefix: prefixColumn(row),
}
}) ?? [],
[rows, projectId]
)

const getId = useCallback(
(row) => {
return rows?.map((v, i) => getPrefixId(row, prefixColumn(rows[i], i))).filter((v) => !!v)[0]
return rows?.map((v, i) => getPrefixId(row, prefixColumn(rows[i]))).filter((v) => !!v)[0]
},
[rows]
)
Expand All @@ -63,6 +64,7 @@ export default function DatastoreDiffTables({ rows }: { rows: ITableProps['recor
isLoading={recordInfo.isLoading}
store={useEvaluationDetailStore}
columnable
compareable
title={t('evaluation.detail.title')}
titleOfCompare={t('evaluation.detail.compare')}
selectable
Expand Down

0 comments on commit 2ab2bf8

Please sign in to comment.