Skip to content

Commit

Permalink
fix: merge fields filter function to storeStateLib
Browse files Browse the repository at this point in the history
  • Loading branch information
islxyqwe committed Jun 19, 2024
1 parent 97c3655 commit 0cb1a70
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
9 changes: 5 additions & 4 deletions packages/graphic-walker/src/components/pivotTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import { useCompututaion, useVizStore } from '../../store';
import { fold2 } from '../../lib/op/fold';
import { getFieldIdentifier, getSort, getSortedEncoding } from '../../utils';
import { GWGlobalConfig } from '@/vis/theme';
import { getAllFields, getViewEncodingFields } from '@/store/storeStateLib';

interface PivotTableProps {
vizThemeConfig?: IThemeKey | GWGlobalConfig;
data: IRow[];
draggableFieldState: DeepReadonly<DraggableFieldState>;
draggableFieldState: DraggableFieldState;
visualConfig: IVisualConfigNew;
layout: IVisualLayout;
disableCollapse?: boolean;
Expand Down Expand Up @@ -183,9 +184,9 @@ const PivotTable: React.FC<PivotTableProps> = function PivotTableComponent(props
setIsLoading(true);
appRef.current?.updateRenderStatus('computing');
const groupbyPromises: Promise<IRow[]>[] = groupbyCombList.map((dimComb) => {
const viewFilters = draggableFieldState.filters.map((x) => ({ ...x }));
const allFields = [...draggableFieldState.dimensions, ...draggableFieldState.measures];
const viewFields = [...draggableFieldState.columns, ...draggableFieldState.rows];
const viewFilters = draggableFieldState.filters;
const allFields = getAllFields(draggableFieldState);
const viewFields = getViewEncodingFields(draggableFieldState, 'table');
const viewMeasures = viewFields.filter((f) => f.analyticType === 'measure');
const sort = getSort(draggableFieldState);
const { limit } = visualConfig;
Expand Down
4 changes: 3 additions & 1 deletion packages/graphic-walker/src/models/visSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const viewEncodingKeys = (geom: string) => {
import { DraggableFieldState } from '..';

export const viewEncodingKeys = (geom: string): Exclude<keyof DraggableFieldState, 'filters'>[] => {
switch (geom) {
case 'choropleth':
return ['geoId', 'color', 'opacity', 'text', 'details'];
Expand Down
10 changes: 10 additions & 0 deletions packages/graphic-walker/src/store/storeStateLib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { viewEncodingKeys } from '@/models/visSpec';
import { DraggableFieldState, IViewField } from '../interfaces';

export function getAllFields(encodings: { dimensions: IViewField[]; measures: IViewField[] }) {
return [...encodings.dimensions, ...encodings.measures];
}

export function getViewEncodingFields(encodings: Partial<Omit<DraggableFieldState, 'filters'>>, geom: string) {
return viewEncodingKeys(geom).flatMap((k) => encodings[k] ?? []);
}
7 changes: 4 additions & 3 deletions packages/graphic-walker/src/store/visualSpecStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { getSQLItemAnalyticType, parseSQLExpr } from '../lib/sql';
import { IPaintMapAdapter } from '../lib/paint';
import { toChatMessage } from '@/models/chat';
import { viewEncodingKeys } from '@/models/visSpec';
import { getAllFields, getViewEncodingFields } from './storeStateLib';

const encodingKeys = (Object.keys(emptyEncodings) as (keyof DraggableFieldState)[]).filter((dkey) => !GLOBAL_CONFIG.META_FIELD_KEYS.includes(dkey));
export class VizSpecStore {
Expand Down Expand Up @@ -153,7 +154,7 @@ export class VizSpecStore {
}

get allFields() {
return [...this.dimensions, ...this.measures];
return getAllFields(this);
}

get config() {
Expand All @@ -179,7 +180,7 @@ export class VizSpecStore {
return result;
}

get viewEncodings() {
get viewEncodings(): Partial<Omit<DraggableFieldState, 'filters'>> {
const result: Record<string, IViewField[]> = {};
viewEncodingKeys(this.config.geoms[0]).forEach((k) => {
result[k] = this.currentEncodings[k];
Expand All @@ -188,7 +189,7 @@ export class VizSpecStore {
}

get viewEncodingFields() {
return viewEncodingKeys(this.config.geoms[0]).flatMap((k) => this.viewEncodings[k]);
return getViewEncodingFields(this.viewEncodings, this.config.geoms[0]);
}

get viewDimensions() {
Expand Down

0 comments on commit 0cb1a70

Please sign in to comment.