Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: table header & i18n missing key

observedobserverae9eaec57853
diff --git a/packages/graphic-walker/src/dataSource/table.tsx b/packages/graphic-walker/src/dataSource/table.tsx
index 2ccc3b6b..47f55faa 100644
--- a/packages/graphic-walker/src/dataSource/table.tsx
+++ b/packages/graphic-walker/src/dataSource/table.tsx
@@ -1,8 +1,9 @@
-import React from 'react';
+import React, { useMemo } from 'react';
import styled from 'styled-components';
import { observer } from 'mobx-react-lite';
import { IMutField } from '../interfaces';
import { useGlobalStore } from '../store';
+import { useTranslation } from 'react-i18next';
interface TableProps {
size?: number;
@@ -69,6 +70,14 @@ const Table: React.FC<TableProps> = props => {
const { size = 10 } = props;
const { commonStore } = useGlobalStore();
const { tmpDSRawFields, tmpDataSource } = commonStore;
+ const { t } = useTranslation();
+
+ const analyticTypeList = useMemo<{value: string; label: string}[]>(() => {
+ return TYPE_LIST.map(at => ({
+ value: at.value,
+ label: t(`constant.analytic_type.${at.value}`)
+ }))
+ }, [])
return (
<Container>
@@ -77,7 +86,7 @@ const Table: React.FC<TableProps> = props => {
<tr>
{tmpDSRawFields.map((field, fIndex) => (
<th key={field.fid} className={getHeaderType(field)}>
- {/* <DataTypeIcon dataType={field.dataType} /> <b>{field.key}</b> */}
+ <b>{field.name || field.fid}</b>
<div>
<select
className="border-b border-gray-300 hover:bg-gray-100 hover:border-gray-600"
@@ -85,7 +94,7 @@ const Table: React.FC<TableProps> = props => {
commonStore.updateTempFieldAnalyticType(field.fid, e.target.value as IMutField['analyticType'])
}}>
{
- TYPE_LIST.map(type => <option key={type.value} value={type.value}>{type.label}</option>)
+ analyticTypeList.map(type => <option key={type.value} value={type.value}>{type.label}</option>)
}
</select>
</div>
diff --git a/packages/graphic-walker/src/locales/en-US.json b/packages/graphic-walker/src/locales/en-US.json
index f8aa993b..2fbe7f4c 100644
--- a/packages/graphic-walker/src/locales/en-US.json
+++ b/packages/graphic-walker/src/locales/en-US.json
@@ -1,5 +1,10 @@
{
"constant": {
+ "row_count": "Row count",
+ "analytic_type": {
+ "dimension": "dimension",
+ "measure": "measure"
+ },
"mark_type": {
"__enum__": "Mark Type",
"auto": "Auto",
diff --git a/packages/graphic-walker/src/locales/zh-CN.json b/packages/graphic-walker/src/locales/zh-CN.json
index 821d2927..01297a8c 100644
--- a/packages/graphic-walker/src/locales/zh-CN.json
+++ b/packages/graphic-walker/src/locales/zh-CN.json
@@ -1,5 +1,10 @@
{
"constant": {
+ "row_count": "行数",
+ "analytic_type": {
+ "dimension": "维度",
+ "measure": "度量"
+ },
"mark_type": {
"__enum__": "标记类型",
"auto": "自动",
diff --git a/packages/graphic-walker/src/utils/index.ts b/packages/graphic-walker/src/utils/index.ts
index 30f2b5b7..017b9bdc 100644
--- a/packages/graphic-walker/src/utils/index.ts
+++ b/packages/graphic-walker/src/utils/index.ts
@@ -1,3 +1,4 @@
+import i18next from 'i18next';
import { COUNT_FIELD_ID } from '../constants';
import { IRow, Filters, IMutField } from '../interfaces';
interface NRReturns {
@@ -239,7 +240,7 @@ export function extendCountField (dataSource: IRow[], fields: IMutField[]): {
}))
const nextFields = fields.concat({
fid: COUNT_FIELD_ID,
- name: '记录数',
+ name: i18next.t('constant.row_count'),
analyticType: 'measure',
semanticType: 'quantitative'
})