Complete workbench P0 resource tab cutover
This commit is contained in:
@@ -151,6 +151,18 @@ pub enum FileTreeOpenTarget {
|
||||
Asset {
|
||||
document_id: String,
|
||||
asset_id: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
resource_kind: Option<String>,
|
||||
},
|
||||
LocalFile {
|
||||
root_uri: String,
|
||||
path: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
resource_kind: Option<String>,
|
||||
},
|
||||
Directory {
|
||||
root_uri: String,
|
||||
path: String,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -455,10 +467,27 @@ fn resolve_open_target(
|
||||
document_id: row.document_id.clone()?,
|
||||
asset_id: row.asset_id.clone()?,
|
||||
}),
|
||||
"local-file" | "local_file" => Some(FileTreeOpenTarget::LocalFile {
|
||||
root_uri: String::new(),
|
||||
path: row.asset_id.clone().unwrap_or_default(),
|
||||
resource_kind: None,
|
||||
}),
|
||||
"directory" => Some(FileTreeOpenTarget::Directory {
|
||||
root_uri: String::new(),
|
||||
path: row.asset_id.clone().unwrap_or_default(),
|
||||
}),
|
||||
"asset" => Some(FileTreeOpenTarget::Asset {
|
||||
document_id: row.document_id.clone()?,
|
||||
asset_id: row.asset_id.clone()?,
|
||||
resource_kind: None,
|
||||
}),
|
||||
"office" | "image" | "pdf" | "code" | "text" | "mindmap" | "table" => {
|
||||
Some(FileTreeOpenTarget::Asset {
|
||||
document_id: row.document_id.clone()?,
|
||||
asset_id: row.asset_id.clone()?,
|
||||
resource_kind: Some(row.row_kind.clone()),
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -647,6 +676,7 @@ mod tests {
|
||||
target: FileTreeOpenTarget::Asset {
|
||||
document_id: "root".into(),
|
||||
asset_id: "image".into(),
|
||||
resource_kind: None,
|
||||
},
|
||||
},
|
||||
)));
|
||||
@@ -786,4 +816,53 @@ mod tests {
|
||||
assert_eq!(escaped.state.drag_effect, None);
|
||||
assert_eq!(escaped.state.drop_target_row_id, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filetree_open_target_serializes_resource_identity_variants() {
|
||||
let asset = serde_json::to_value(FileTreeOpenTarget::Asset {
|
||||
document_id: "doc:page".into(),
|
||||
asset_id: "local-file:Page/report.docx".into(),
|
||||
resource_kind: Some("office".into()),
|
||||
})
|
||||
.expect("serialize asset target");
|
||||
assert_eq!(
|
||||
asset,
|
||||
serde_json::json!({
|
||||
"kind": "asset",
|
||||
"documentId": "doc:page",
|
||||
"assetId": "local-file:Page/report.docx",
|
||||
"resourceKind": "office"
|
||||
})
|
||||
);
|
||||
|
||||
let local_file = serde_json::to_value(FileTreeOpenTarget::LocalFile {
|
||||
root_uri: "file:///tmp/mnote".into(),
|
||||
path: "Page/资源.ext".into(),
|
||||
resource_kind: Some("local_file".into()),
|
||||
})
|
||||
.expect("serialize local file target");
|
||||
assert_eq!(
|
||||
local_file,
|
||||
serde_json::json!({
|
||||
"kind": "localFile",
|
||||
"rootUri": "file:///tmp/mnote",
|
||||
"path": "Page/资源.ext",
|
||||
"resourceKind": "local_file"
|
||||
})
|
||||
);
|
||||
|
||||
let directory = serde_json::to_value(FileTreeOpenTarget::Directory {
|
||||
root_uri: "file:///tmp/mnote".into(),
|
||||
path: "Page/assets".into(),
|
||||
})
|
||||
.expect("serialize directory target");
|
||||
assert_eq!(
|
||||
directory,
|
||||
serde_json::json!({
|
||||
"kind": "directory",
|
||||
"rootUri": "file:///tmp/mnote",
|
||||
"path": "Page/assets"
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user