Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/controller/src/edit_action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ pub struct BindFormSchema {
// It is used to customize the fields' render behaviors.
// The length of this vector should be the same as `fields`.
pub render_ids: Vec<String>,
pub keys: Vec<String>,
pub row: bool,
}

Expand Down
7 changes: 7 additions & 0 deletions packages/web/src/api/workbook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
batch_get_cell_coordinate_with_sheet_by_id,
batch_get_cell_info_by_id,
bind_form_schema,
block_input,
block_line_name_field_update,
block_line_num_fmt_update,
Expand Down Expand Up @@ -890,6 +891,12 @@ export class Workbook {
null,
p.value.wrapText
)
if (p.type === 'bindFormSchema') {
return bind_form_schema(this._id, p.value)
}
if (p.type === 'upsertFieldRenderInfo') {
return upsert_field_render_info(this._id, p.value)
}
// eslint-disable-next-line no-console
console.log(`Unimplemented!: ${p.type}`)
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/block-composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const BlockComposerComponent = (props: BlockComposerProps) => {
type: 'string',
description: 'Current status of the customer',
required: true,
primary: false,
},
])
const [selectedFieldId, setSelectedFieldId] = useState<string | null>(
Expand Down Expand Up @@ -158,6 +159,7 @@ export const BlockComposerComponent = (props: BlockComposerProps) => {
.build(),
}
payloads.push(createBlockPayload)
const keyIdx = fields.findIndex((f) => f.primary)

const bindFormSchemaPayload: Payload = {
type: 'bindFormSchema',
Expand All @@ -167,6 +169,7 @@ export const BlockComposerComponent = (props: BlockComposerProps) => {
.blockId(blockId)
.fieldFrom(0)
.row(true)
.keyIdx(keyIdx < 0 ? 0 : keyIdx)
.fields(fs.map((f) => f[1].name))
.renderIds(fs.map((f) => f[0]))
.build(),
Expand Down
2 changes: 1 addition & 1 deletion src/components/block-composer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface FieldSetting {
type: FieldTypeEnum
description?: string
required: boolean
primary?: boolean
primary: boolean
enumId?: string
defaultValue?: string
format?: string // for datetime
Expand Down
4 changes: 2 additions & 2 deletions src/components/block-interface/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export const BlockInterfaceComponent = (props: BlockInterfaceProps) => {
.sort((a, b) => a.idx - b.idx)
.map((fieldEntry, _idx) => {
const result = BLOCK_MANAGER.fieldManager.get(
fieldEntry.field
fieldEntry.renderId
)

if (!result) {
throw new Error(
`Field ${fieldEntry.field} not found in block ${info.blockId}`
`Field ${fieldEntry.renderId} not found in block ${info.blockId}`
)
}

Expand Down
35 changes: 35 additions & 0 deletions tests/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use logisheets_controller::edit_action::{BindFormSchema, EditPayload, PayloadsAction};

use crate::load_script;

use super::test_script;

#[test]
Expand All @@ -19,3 +23,34 @@ fn test_resize_block() {
fn test_convert_block() {
test_script("tests/block/convert_block.script");
}

#[test]
fn test_bind_block_schema() {
let mut workbook = load_script("tests/block/create_block.script");
let _ = workbook.handle_action(logisheets::EditAction::Payloads(PayloadsAction {
payloads: vec![EditPayload::BindFormSchema(BindFormSchema {
sheet_idx: 0,
block_id: 1,
ref_name: "test".to_string(),
field_from: 0,
key_idx: 0,
fields: vec!["name".to_string(), "age".to_string(), "address".to_string()],
render_ids: vec![
"test1".to_string(),
"test2".to_string(),
"test3".to_string(),
],
row: true,
})],
undoable: true,
init: false,
}));

let ws = workbook.get_sheet_by_idx(0).unwrap();
let window = ws.get_display_window(0, 0, 5, 5).unwrap();
let blocks = window.blocks;
assert_eq!(blocks.len(), 1);
let block = &blocks[0];
println!("{:?}", &block.info.schema);
assert!(block.info.schema.is_some());
}