Skip to content

Commit

Permalink
fix(database): string group name update
Browse files Browse the repository at this point in the history
  • Loading branch information
zzj3720 committed Dec 19, 2024
1 parent 2213c04 commit d997242
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/affine/data-view/src/core/group-by/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const groupByMatchers = [
return [
{
key: `${value}`,
value,
value: value.toString(),
},
];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class StringGroupView extends BaseGroup<NonNullable<unknown>, string> {
items: [
menu.input({
initialValue: this.value ?? '',
onChange: text => {
onComplete: text => {
this.updateValue?.(text);
},
}),
Expand Down
7 changes: 4 additions & 3 deletions packages/affine/data-view/src/core/group-by/trait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { computed, type ReadonlySignal } from '@preact/signals-core';

import type { GroupBy, GroupProperty } from '../common/types.js';
import type { TypeInstance } from '../logical/type.js';
import type { DVJSON } from '../property/types.js';
import type { Property } from '../view-manager/property.js';
import type { SingleView } from '../view-manager/single-view.js';

Expand All @@ -19,7 +20,7 @@ export type GroupData = {
key: string;
name: string;
type: TypeInstance;
value: unknown;
value: DVJSON;
rows: string[];
};

Expand Down Expand Up @@ -281,13 +282,13 @@ export class GroupTrait {
this.view.cellValueSet(rowId, propertyId, newValue);
}

updateValue(rows: string[], value: unknown) {
updateValue(rows: string[], value: DVJSON) {
const propertyId = this.propertyId;
if (!propertyId) {
return;
}
rows.forEach(id => {
this.view.cellValueSet(id, propertyId, value);
this.view.cellJsonValueSet(id, propertyId, value);
});
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/affine/data-view/src/core/group-by/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { TypeInstance } from '../logical/type.js';
import type { DVJSON } from '../property/types.js';
import type { UniComponent } from '../utils/index.js';

export interface GroupRenderProps<
Data extends NonNullable<unknown> = NonNullable<unknown>,
Value = unknown,
Value = DVJSON,
> {
data: Data;
updateData?: (data: Data) => void;
Expand All @@ -17,14 +18,14 @@ export type GroupByConfig = {
groupName: (type: TypeInstance, value: unknown) => string;
defaultKeys: (type: TypeInstance) => {
key: string;
value: unknown;
value: DVJSON;
}[];
valuesGroup: (
value: unknown,
type: TypeInstance
) => {
key: string;
value: unknown;
value: DVJSON;
}[];
addToGroup?: (value: unknown, oldValue: unknown) => unknown;
removeFromGroup?: (value: unknown, oldValue: unknown) => unknown;
Expand Down
20 changes: 20 additions & 0 deletions packages/affine/data-view/src/core/view-manager/single-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { computed, type ReadonlySignal, signal } from '@preact/signals-core';

import type { DataViewContextKey } from '../data-source/context.js';
import type { Variable } from '../expression/types.js';
import type { DVJSON } from '../index.js';
import type { TypeInstance } from '../logical/type.js';
import type { PropertyMetaConfig } from '../property/property-config.js';
import type { TraitKey } from '../traits/key.js';
Expand Down Expand Up @@ -53,6 +54,8 @@ export interface SingleView {

cellJsonValueGet(rowId: string, propertyId: string): unknown;

cellJsonValueSet(rowId: string, propertyId: string, value: DVJSON): void;

cellStringValueGet(rowId: string, propertyId: string): string | undefined;

cellGet(rowId: string, propertyId: string): Cell;
Expand Down Expand Up @@ -259,6 +262,23 @@ export abstract class SingleViewBase<
});
}

cellJsonValueSet(rowId: string, propertyId: string, value: DVJSON): void {
const type = this.propertyTypeGet(propertyId);
if (!type) {
return;
}
const fromJson = this.dataSource.propertyMetaGet(type).config.cellFromJson;
this.dataSource.cellValueChange(
rowId,
propertyId,
fromJson({
value,
data: this.propertyDataGet(propertyId),
dataSource: this.dataSource,
})
);
}

cellStringValueGet(rowId: string, propertyId: string): string | undefined {
const type = this.propertyTypeGet(propertyId);
if (!type) {
Expand Down

0 comments on commit d997242

Please sign in to comment.