From 17a9c34f0053d5a369168ab3025f819427dd4cf7 Mon Sep 17 00:00:00 2001
From: huanhuanwa <2323666215@qq.com>
Date: Thu, 8 Aug 2024 13:57:18 +0800
Subject: [PATCH 1/2] fix: set multiple member deafult value to []
---
packages/grid/src/core/utils/field.ts | 7 +++++--
packages/grid/src/core/utils/record.ts | 2 +-
packages/grid/src/grid.component.html | 2 +-
src/app/share/apply-to-yjs/add-field.ts | 2 +-
4 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/packages/grid/src/core/utils/field.ts b/packages/grid/src/core/utils/field.ts
index a88f28c4..64576932 100644
--- a/packages/grid/src/core/utils/field.ts
+++ b/packages/grid/src/core/utils/field.ts
@@ -1,8 +1,11 @@
import { FieldsMap } from '../constants/field';
-import { AITable, AITableFieldType } from '../types';
+import { AITable, AITableField, AITableFieldType } from '../types';
import { idCreator } from './id-creator';
-export function getDefaultFieldValue(type: AITableFieldType) {
+export function getDefaultFieldValue(field: AITableField) {
+ if (AITableFieldType.member === field.type && field.isMultiple) {
+ return [];
+ }
return '';
}
diff --git a/packages/grid/src/core/utils/record.ts b/packages/grid/src/core/utils/record.ts
index b8e8e9dd..0e650131 100644
--- a/packages/grid/src/core/utils/record.ts
+++ b/packages/grid/src/core/utils/record.ts
@@ -8,7 +8,7 @@ export function getDefaultRecord(fields: AITableFields) {
values: {}
};
fields.map((item) => {
- newRow.values[item._id] = getDefaultFieldValue(item.type);
+ newRow.values[item._id] = getDefaultFieldValue(item);
});
return newRow;
}
diff --git a/packages/grid/src/grid.component.html b/packages/grid/src/grid.component.html
index 66a0a844..6e463f1f 100644
--- a/packages/grid/src/grid.component.html
+++ b/packages/grid/src/grid.component.html
@@ -64,7 +64,7 @@
@switch (field.type) {
@case (AITableFieldType.select) {
@if (!field.isMultiple && record.values[field._id] | selectOption: field['options']; as selectedOption) {
- {{ selectedOption.text }}
+ {{ selectedOption.text }}
}
}
@case (AITableFieldType.date) {
diff --git a/src/app/share/apply-to-yjs/add-field.ts b/src/app/share/apply-to-yjs/add-field.ts
index 2072f839..aad478ca 100644
--- a/src/app/share/apply-to-yjs/add-field.ts
+++ b/src/app/share/apply-to-yjs/add-field.ts
@@ -10,7 +10,7 @@ export default function addField(sharedType: SharedType, action: AddFieldAction)
const records = sharedType.get('records') as SyncArrayElement;
if (records) {
for (let value of records) {
- const newRecord = getDefaultFieldValue(action.field.type);
+ const newRecord = getDefaultFieldValue(action.field);
const customField = value.get(1);
customField.insert(path, [newRecord]);
}
From abcfbd327a78a823c181a70e947404f71ec089bc Mon Sep 17 00:00:00 2001
From: huanhuanwa <2323666215@qq.com>
Date: Thu, 8 Aug 2024 14:10:40 +0800
Subject: [PATCH 2/2] fix: set member value to array
---
packages/grid/src/core/utils/field.ts | 2 +-
packages/grid/src/grid.component.html | 48 ++++++++++++++++-----------
packages/grid/src/utils/build.ts | 12 ++-----
src/app/utils/utils.ts | 12 +++----
4 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/packages/grid/src/core/utils/field.ts b/packages/grid/src/core/utils/field.ts
index 64576932..c19edbe1 100644
--- a/packages/grid/src/core/utils/field.ts
+++ b/packages/grid/src/core/utils/field.ts
@@ -3,7 +3,7 @@ import { AITable, AITableField, AITableFieldType } from '../types';
import { idCreator } from './id-creator';
export function getDefaultFieldValue(field: AITableField) {
- if (AITableFieldType.member === field.type && field.isMultiple) {
+ if ([AITableFieldType.member, AITableFieldType.createdBy, AITableFieldType.updatedBy].includes(field.type)) {
return [];
}
return '';
diff --git a/packages/grid/src/grid.component.html b/packages/grid/src/grid.component.html
index 6e463f1f..5194a39d 100644
--- a/packages/grid/src/grid.component.html
+++ b/packages/grid/src/grid.component.html
@@ -64,7 +64,9 @@
@switch (field.type) {
@case (AITableFieldType.select) {
@if (!field.isMultiple && record.values[field._id] | selectOption: field['options']; as selectedOption) {
- {{ selectedOption.text }}
+ {{
+ selectedOption.text
+ }}
}
}
@case (AITableFieldType.date) {
@@ -112,12 +114,14 @@
}
@case (AITableFieldType.member) {
@if (!field.isMultiple) {
-
+ @if (record.values[field._id][0]; as recordValue) {
+
+ }
} @else {
@for (item of record.values[field._id]; track $index) {
@@ -127,20 +131,24 @@
}
}
@case (AITableFieldType.createdBy) {
-
+ @if (record.values[field._id][0]; as recordValue) {
+
+ }
}
@case (AITableFieldType.updatedBy) {
-
+ @if (record.values[field._id][0]; as recordValue) {
+
+ }
}
@default {
{{ record.values[field._id] }}
@@ -157,4 +165,4 @@
-
\ No newline at end of file
+
diff --git a/packages/grid/src/utils/build.ts b/packages/grid/src/utils/build.ts
index 09f3ac39..85448a2a 100644
--- a/packages/grid/src/utils/build.ts
+++ b/packages/grid/src/utils/build.ts
@@ -2,11 +2,7 @@ import { createDraft, finishDraft } from 'immer';
import { AITableFields, AITableFieldType, AITableRecords, FieldsMap } from '../core';
import { AITableGridData, AITableReferences, AITableSelection, AITableUserInfo } from '../types';
-export const buildGridData = (
- recordValue: AITableRecords,
- fieldsValue: AITableFields,
- references?: AITableReferences
-): AITableGridData => {
+export const buildGridData = (recordValue: AITableRecords, fieldsValue: AITableFields, references?: AITableReferences): AITableGridData => {
const fields = fieldsValue.map((item) => {
return {
...item,
@@ -41,11 +37,7 @@ export function buildRecordsByReferences(records: AITableRecords, fields: AITabl
draftRecords.forEach((record) => {
memberFields.forEach((field) => {
const value = record.values[field._id];
- if (field.isMultiple) {
- record.values[field._id] = value.map((uid: string) => uidToMember[uid]).filter(Boolean);
- } else {
- record.values[field._id] = uidToMember[value] || {};
- }
+ record.values[field._id] = value.map((uid: string) => uidToMember[uid]).filter(Boolean);
});
});
records = finishDraft(draftRecords);
diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts
index 2baca48b..1af8e191 100644
--- a/src/app/utils/utils.ts
+++ b/src/app/utils/utils.ts
@@ -42,9 +42,9 @@ export function getDefaultValue() {
url: 'https://www.baidu.com',
text: '百度链接'
},
- 'column-9': 'member_01',
+ 'column-9': ['member_01'],
'column-10': 1682235946,
- 'column-11': 'member_02',
+ 'column-11': ['member_02'],
'column-12': 1720490727
}
},
@@ -63,9 +63,9 @@ export function getDefaultValue() {
'column-6': 50,
'column-7': 1,
'column-8': {},
- 'column-9': 'member_01',
+ 'column-9': ['member_01'],
'column-10': 1682235946,
- 'column-11': 'member_02',
+ 'column-11': ['member_02'],
'column-12': 1720490727
}
},
@@ -84,9 +84,9 @@ export function getDefaultValue() {
'column-6': 100,
'column-7': 1,
'column-8': {},
- 'column-9': '',
+ 'column-9': [],
'column-10': 1682235946,
- 'column-11': 'member_02',
+ 'column-11': ['member_02'],
'column-12': 1720490727
}
}