mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-10-31 10:03:18 +00:00 
			
		
		
		
	fix: duplicate view with setting (#2252)
This commit is contained in:
		
							parent
							
								
									5d542394d8
								
							
						
					
					
						commit
						92f980347f
					
				| @ -411,14 +411,20 @@ pub async fn create_new_database( | |||||||
| 
 | 
 | ||||||
|   // Create database view
 |   // Create database view
 | ||||||
|   tracing::trace!("Create new database view: {}", view_id); |   tracing::trace!("Create new database view: {}", view_id); | ||||||
|   let mut database_view_rev = if database_view_data.is_empty() { |   let database_view = if database_view_data.is_empty() { | ||||||
|     DatabaseViewRevision::new(database_id, view_id.to_owned(), true, name, layout.into()) |     let mut database_view = | ||||||
|  |       DatabaseViewRevision::new(database_id, view_id.to_owned(), true, name, layout.into()); | ||||||
|  |     database_view.layout_settings = layout_setting; | ||||||
|  |     database_view | ||||||
|   } else { |   } else { | ||||||
|     DatabaseViewRevision::from_json(database_view_data)? |     let mut database_view = DatabaseViewRevision::from_json(database_view_data)?; | ||||||
|  |     database_view.database_id = database_id; | ||||||
|  |     // Replace the view id with the new one. This logic will be removed in the future.
 | ||||||
|  |     database_view.view_id = view_id.to_owned(); | ||||||
|  |     database_view | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   database_view_rev.layout_settings = layout_setting; |   let database_view_ops = make_database_view_operations(&database_view); | ||||||
|   let database_view_ops = make_database_view_operations(&database_view_rev); |  | ||||||
|   let database_view_bytes = database_view_ops.json_bytes(); |   let database_view_bytes = database_view_ops.json_bytes(); | ||||||
|   let revision = Revision::initial_revision(view_id, database_view_bytes); |   let revision = Revision::initial_revision(view_id, database_view_bytes); | ||||||
|   database_manager |   database_manager | ||||||
|  | |||||||
| @ -888,12 +888,10 @@ impl DatabaseEditor { | |||||||
|     Ok(()) |     Ok(()) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   pub async fn duplicate_database(&self, _view_id: &str) -> FlowyResult<BuildDatabaseContext> { |   pub async fn duplicate_database(&self, view_id: &str) -> FlowyResult<BuildDatabaseContext> { | ||||||
|     let database_pad = self.database_pad.read().await; |     let database_pad = self.database_pad.read().await; | ||||||
|     // let database_view_data = self
 |     let database_view_data = self.database_views.duplicate_database_view(view_id).await?; | ||||||
|     //   .database_views
 | 
 | ||||||
|     //   .duplicate_database_view_setting(view_id)
 |  | ||||||
|     //   .await?;
 |  | ||||||
|     let original_blocks = database_pad.get_block_meta_revs(); |     let original_blocks = database_pad.get_block_meta_revs(); | ||||||
|     let (duplicated_fields, duplicated_blocks) = database_pad.duplicate_database_block_meta().await; |     let (duplicated_fields, duplicated_blocks) = database_pad.duplicate_database_block_meta().await; | ||||||
| 
 | 
 | ||||||
| @ -922,7 +920,7 @@ impl DatabaseEditor { | |||||||
|       block_metas: duplicated_blocks, |       block_metas: duplicated_blocks, | ||||||
|       blocks: blocks_meta_data, |       blocks: blocks_meta_data, | ||||||
|       layout_setting: Default::default(), |       layout_setting: Default::default(), | ||||||
|       database_view_data: "".to_string(), |       database_view_data, | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -238,7 +238,7 @@ impl DatabaseViewEditor { | |||||||
|     self.filter_controller.filter_row_revs(rows).await; |     self.filter_controller.filter_row_revs(rows).await; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   pub async fn v_duplicate_view_setting(&self) -> FlowyResult<String> { |   pub async fn v_duplicate_database_view(&self) -> FlowyResult<String> { | ||||||
|     let json_str = self.pad.read().await.json_str()?; |     let json_str = self.pad.read().await.json_str()?; | ||||||
|     Ok(json_str) |     Ok(json_str) | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -101,9 +101,9 @@ impl DatabaseViews { | |||||||
|     Ok(row_revs) |     Ok(row_revs) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   pub async fn duplicate_database_view_setting(&self, view_id: &str) -> FlowyResult<String> { |   pub async fn duplicate_database_view(&self, view_id: &str) -> FlowyResult<String> { | ||||||
|     let editor = self.get_view_editor(view_id).await?; |     let editor = self.get_view_editor(view_id).await?; | ||||||
|     let view_data = editor.v_duplicate_view_setting().await?; |     let view_data = editor.v_duplicate_database_view().await?; | ||||||
|     Ok(view_data) |     Ok(view_data) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -20,10 +20,10 @@ use lib_infra::util::md5; | |||||||
| use revision_model::Revision; | use revision_model::Revision; | ||||||
| use std::sync::Arc; | use std::sync::Arc; | ||||||
| 
 | 
 | ||||||
| const DATABASE_VIEW_MIGRATE: &str = "database_view_migrate"; | const DATABASE_VIEW_MIGRATE_1: &str = "database_view_migrate_v1"; | ||||||
| 
 | 
 | ||||||
| pub fn is_database_view_migrated(user_id: &str) -> bool { | pub fn is_database_view_migrated(user_id: &str) -> bool { | ||||||
|   let key = md5(format!("{}{}", user_id, DATABASE_VIEW_MIGRATE)); |   let key = md5(format!("{}{}", user_id, DATABASE_VIEW_MIGRATE_1)); | ||||||
|   KV::get_bool(&key) |   KV::get_bool(&key) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -107,7 +107,7 @@ pub(crate) async fn migrate_database_view( | |||||||
|     let _ = database_refs.bind(&database_id, &database_view_id, true, &database.name); |     let _ = database_refs.bind(&database_id, &database_view_id, true, &database.name); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   let key = md5(format!("{}{}", user_id, DATABASE_VIEW_MIGRATE)); |   let key = md5(format!("{}{}", user_id, DATABASE_VIEW_MIGRATE_1)); | ||||||
|   KV::set_bool(&key, true); |   KV::set_bool(&key, true); | ||||||
|   Ok(()) |   Ok(()) | ||||||
| } | } | ||||||
|  | |||||||
| @ -37,7 +37,6 @@ pub struct DatabaseViewRevision { | |||||||
|   #[serde(rename = "grid_id")] |   #[serde(rename = "grid_id")] | ||||||
|   pub database_id: String, |   pub database_id: String, | ||||||
| 
 | 
 | ||||||
|   #[serde(skip_serializing_if = "String::is_empty")] |  | ||||||
|   #[serde(default)] |   #[serde(default)] | ||||||
|   pub name: String, |   pub name: String, | ||||||
| 
 | 
 | ||||||
| @ -47,7 +46,6 @@ pub struct DatabaseViewRevision { | |||||||
|   pub layout: LayoutRevision, |   pub layout: LayoutRevision, | ||||||
| 
 | 
 | ||||||
|   #[serde(default)] |   #[serde(default)] | ||||||
|   #[serde(skip_serializing_if = "LayoutSetting::is_empty")] |  | ||||||
|   pub layout_settings: LayoutSetting, |   pub layout_settings: LayoutSetting, | ||||||
| 
 | 
 | ||||||
|   #[serde(default)] |   #[serde(default)] | ||||||
| @ -124,28 +122,3 @@ impl std::ops::DerefMut for LayoutSetting { | |||||||
| pub struct RowOrderRevision { | pub struct RowOrderRevision { | ||||||
|   pub row_id: String, |   pub row_id: String, | ||||||
| } | } | ||||||
| 
 |  | ||||||
| #[cfg(test)] |  | ||||||
| mod tests { |  | ||||||
|   use crate::DatabaseViewRevision; |  | ||||||
| 
 |  | ||||||
|   #[test] |  | ||||||
|   fn grid_view_revision_serde_test() { |  | ||||||
|     let grid_view_revision = DatabaseViewRevision { |  | ||||||
|       view_id: "1".to_string(), |  | ||||||
|       database_id: "1".to_string(), |  | ||||||
|       name: "".to_string(), |  | ||||||
|       is_base: true, |  | ||||||
|       layout: Default::default(), |  | ||||||
|       layout_settings: Default::default(), |  | ||||||
|       filters: Default::default(), |  | ||||||
|       groups: Default::default(), |  | ||||||
|       sorts: Default::default(), |  | ||||||
|     }; |  | ||||||
|     let s = serde_json::to_string(&grid_view_revision).unwrap(); |  | ||||||
|     assert_eq!( |  | ||||||
|       s, |  | ||||||
|       r#"{"view_id":"1","grid_id":"1","is_base":true,"layout":0,"filters":[],"groups":[],"sorts":[]}"# |  | ||||||
|     ); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Nathan.fooo
						Nathan.fooo