Skip to content

Commit 1139042

Browse files
committed
chore: update chart type definition
1 parent 9591360 commit 1139042

File tree

7 files changed

+27
-24
lines changed

7 files changed

+27
-24
lines changed

apps/nestjs-backend/src/features/dashboard/chart.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { PrismaService } from '@teable/db-main-prisma';
3-
import { ChartType, DataSource, THEMES_KEYS } from '@teable/openapi';
3+
import { ChartType, DataSource, THEMES_KEYS, DEFAULT_SERIES_ARRAY } from '@teable/openapi';
44

55
@Injectable()
66
export class ChartService {
@@ -64,12 +64,12 @@ export class ChartService {
6464
xAxis: defaultFieldId,
6565
filter: null,
6666
groupBy: null,
67-
seriesArray: 'COUNTA',
67+
seriesArray: DEFAULT_SERIES_ARRAY,
6868
},
6969
appearance: {
7070
theme: THEMES_KEYS.BLUE,
7171
legendVisible: true,
72-
labelVisible: true,
72+
labelVisible: false,
7373
},
7474
};
7575
}

apps/nextjs-app/src/features/app/blocks/chart-v2/components/form/AxisConfig.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CellValueType, FieldType } from '@teable/core';
2+
import { DEFAULT_SERIES_ARRAY } from '@teable/openapi';
23
import type { ITableQuery, IStatisticFieldItem } from '@teable/openapi';
34
import {
45
Label,
@@ -26,7 +27,7 @@ export const AxisConfig = () => {
2627
const { xAxis, seriesArray, orderBy, groupBy } = (query || {}) as ITableQuery;
2728

2829
const pieChartType = [ChartType.Pie, ChartType.DonutChart].includes(chartType);
29-
const countAll = seriesArray === 'COUNTA';
30+
const countAll = seriesArray === DEFAULT_SERIES_ARRAY;
3031

3132
const displayGroupBy = useMemo(() => {
3233
if (pieChartType) {
@@ -128,7 +129,7 @@ export const AxisConfig = () => {
128129
value="totalRecords"
129130
className="w-full"
130131
onClick={() => {
131-
updateStorageByPath(`query.seriesArray`, 'COUNTA');
132+
updateStorageByPath(`query.seriesArray`, DEFAULT_SERIES_ARRAY);
132133
}}
133134
>
134135
{t('chartV2.form.axisConfig.totalRecords')}

apps/nextjs-app/src/features/app/blocks/chart-v2/components/form/DataSource.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMutation } from '@tanstack/react-query';
22
import type { ITableQuery } from '@teable/openapi';
3-
import { DataSource, getFields } from '@teable/openapi';
3+
import { DataSource, getFields, DEFAULT_SERIES_ARRAY } from '@teable/openapi';
44
import { useTables } from '@teable/sdk/hooks';
55
import { Separator, Tabs, TabsContent, TabsList, TabsTrigger } from '@teable/ui-lib/shadcn';
66
import { useTranslation } from 'next-i18next';
@@ -62,7 +62,7 @@ export const DataSourceSelect = () => {
6262
},
6363
{
6464
path: 'query.seriesArray',
65-
value: 'COUNTA',
65+
value: DEFAULT_SERIES_ARRAY,
6666
},
6767
{
6868
path: 'query.filter',
@@ -130,7 +130,7 @@ export const DataSourceSelect = () => {
130130
},
131131
{
132132
path: 'query.seriesArray',
133-
value: 'COUNTA',
133+
value: DEFAULT_SERIES_ARRAY,
134134
},
135135
{
136136
path: 'query.xAxis',

apps/nextjs-app/src/features/app/blocks/chart-v2/core/adapters/TableAdapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IFieldVo } from '@teable/core';
22
import type { IChartStorage, ITableQuery } from '@teable/openapi';
3-
import { AGGREGATE_COUNT_KEY } from '@teable/openapi';
3+
import { AGGREGATE_COUNT_KEY, DEFAULT_SERIES_ARRAY } from '@teable/openapi';
44
import { groupBy } from 'lodash';
55
import type { ISeriesConfig } from '../types';
66
import { getGroupUniqueKey, getGroupKeyName } from '../utils';
@@ -72,7 +72,7 @@ export class TableAdapter extends BaseAdapter<ITableQuery> {
7272
private buildLegendData(): string[] {
7373
const { query } = this.storage;
7474
const { seriesArray } = query;
75-
const countAll = seriesArray === 'COUNTA';
75+
const countAll = seriesArray === DEFAULT_SERIES_ARRAY;
7676

7777
// no need legend data
7878
if (countAll) {
@@ -106,7 +106,7 @@ export class TableAdapter extends BaseAdapter<ITableQuery> {
106106
getSeries(xData: string[], legendData: string[]): ISeriesConfig[] {
107107
const { query } = this.storage;
108108
const { seriesArray } = query;
109-
const countAll = seriesArray === 'COUNTA';
109+
const countAll = seriesArray === DEFAULT_SERIES_ARRAY;
110110

111111
if (countAll) {
112112
return this.getSeriesByCountAll(xData, legendData);

apps/nextjs-app/src/features/app/blocks/chart-v2/core/charts/PieChart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ITableQuery } from '@teable/openapi';
2-
import { AGGREGATE_COUNT_KEY, DataSource } from '@teable/openapi';
2+
import { AGGREGATE_COUNT_KEY, DataSource, DEFAULT_SERIES_ARRAY } from '@teable/openapi';
33
import type { ISeriesConfig } from '../types';
44
import { getGroupKeyName } from '../utils';
55
import { BaseChart, type IChartOptions } from './BaseChart';
@@ -90,7 +90,7 @@ export class PieChart extends BaseChart {
9090
if (dataSource === DataSource.Table) {
9191
const { seriesArray } = this.storage.query as ITableQuery;
9292
const fieldMap = this.getFieldMap();
93-
return seriesArray === 'COUNTA'
93+
return seriesArray === DEFAULT_SERIES_ARRAY
9494
? AGGREGATE_COUNT_KEY
9595
: `${fieldMap?.[(seriesArray as { fieldId: string }[])?.at(0)?.fieldId ?? '']}_${(seriesArray as { rollup: string }[])?.at(0)?.rollup ?? ''}`;
9696
}

packages/openapi/src/plugin/chart/dashboard-query-v2.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ export const baseQuerySchemaVoV2 = z.object({
1717
),
1818
});
1919

20+
export const DEFAULT_SERIES_ARRAY = 'COUNTA';
21+
2022
export type IBaseQueryVoV2 = z.infer<typeof baseQuerySchemaVoV2>;
2123

24+
export enum THEMES_KEYS {
25+
BLUE = 'blue',
26+
GREEN = 'green',
27+
NEUTRAL = 'neutral',
28+
ORANGE = 'orange',
29+
RED = 'red',
30+
ROSE = 'rose',
31+
VIOLET = 'violet',
32+
YELLOW = 'yellow',
33+
}
34+
2235
export enum ChartType {
2336
Bar = 'bar',
2437
Pie = 'pie',

packages/openapi/src/plugin/types.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,3 @@ export const pluginConfigSchema = z
8181
}
8282
});
8383
export type IPluginConfig = z.infer<typeof pluginConfigSchema>;
84-
85-
export enum THEMES_KEYS {
86-
BLUE = 'blue',
87-
GREEN = 'green',
88-
NEUTRAL = 'neutral',
89-
ORANGE = 'orange',
90-
RED = 'red',
91-
ROSE = 'rose',
92-
VIOLET = 'violet',
93-
YELLOW = 'yellow',
94-
}

0 commit comments

Comments
 (0)