Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,14 @@ class DatabaseController {
}

Future<FlowyResult<void, FlowyError>> moveGroupRow({
required RowMetaPB fromRow,
required List<RowMetaPB> fromRow,
required String fromGroupId,
required String toGroupId,
RowMetaPB? toRow,
}) {
final fromRowIds = fromRow.map((element) => element.id).toList();
return _databaseViewBackendSvc.moveGroupRow(
fromRowId: fromRow.id,
fromRowIds: fromRowIds,
fromGroupId: fromGroupId,
toGroupId: toGroupId,
toRowId: toRow?.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ class RowCache {
return _rowList.get(rowId);
}

List<RowInfo> getRows(List<RowId> rowIds) {
final rowInfos = <RowInfo>[];
for (final rowId in rowIds) {
final rowInfo = _rowList.get(rowId);
if (rowInfo != null) {
rowInfos.add(rowInfo);
}
}
return rowInfos;
}

void setInitialRows(List<RowMetaPB> rows) {
for (final row in rows) {
final rowInfo = buildGridRow(row);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
final toRow = groupControllers[groupId]?.rowAtIndex(toIndex);
if (fromRow != null) {
databaseController.moveGroupRow(
fromRow: fromRow,
fromRow: [fromRow],
toRow: toRow,
fromGroupId: groupId,
toGroupId: groupId,
Expand All @@ -85,7 +85,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
final toRow = groupControllers[toGroupId]?.rowAtIndex(toIndex);
if (fromRow != null) {
databaseController.moveGroupRow(
fromRow: fromRow,
fromRow: [fromRow],
toRow: toRow,
fromGroupId: fromGroupId,
toGroupId: toGroupId,
Expand Down Expand Up @@ -242,20 +242,49 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
final rowIds = groupedRowIds.map((e) => e.rowId).toList();
await RowBackendService.deleteRows(viewId, rowIds);
},
moveGroupToAdjacentGroup: (groupedRowId, toPrevious) async {
final fromRow =
databaseController.rowCache.getRow(groupedRowId.rowId)?.rowMeta;
final currentGroupIndex =
boardController.groupIds.indexOf(groupedRowId.groupId);
final toGroupIndex =
toPrevious ? currentGroupIndex - 1 : currentGroupIndex + 1;
if (fromRow != null &&
moveGroupToAdjacentGroup: (groupedRowIds, toPrevious) async {
final checkedGroupIndexs = groupedRowIds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (typo): Typo in variable name 'checkedGroupIndexs'

Rename to checkedGroupIndices or checkedGroupIndexes for correct pluralization and clarity.

.map(
(element) =>
boardController.groupIds.indexOf(element.groupId),
)
.toSet();

late final int currentGroupIndex;
late final int toGroupIndex;
if (checkedGroupIndexs.length == 1) {
currentGroupIndex = checkedGroupIndexs.first;
toGroupIndex =
toPrevious ? currentGroupIndex - 1 : currentGroupIndex + 1;
} else {
final sortedGroupIndex =
checkedGroupIndexs.sorted((a, b) => a - b);
currentGroupIndex =
toPrevious ? sortedGroupIndex.last : sortedGroupIndex.first;
toGroupIndex =
toPrevious ? sortedGroupIndex.first : sortedGroupIndex.last;
}

final toGroupId = boardController.groupDatas[toGroupIndex].id;
final rowIds = groupedRowIds
.where((element) => element.groupId != toGroupId)
.map((element) => element.rowId)
.toList();

final fromRows = databaseController.rowCache
.getRows(rowIds)
.map((element) => element.rowMeta)
.toList();

if (fromRows.isNotEmpty &&
toGroupIndex > -1 &&
toGroupIndex < boardController.groupIds.length) {
final toGroupId = boardController.groupDatas[toGroupIndex].id;
final fromGroupId =
boardController.groupDatas[currentGroupIndex].id;

final result = await databaseController.moveGroupRow(
fromRow: fromRow,
fromGroupId: groupedRowId.groupId,
fromRow: fromRows,
fromGroupId: fromGroupId,
toGroupId: toGroupId,
);
result.fold(
Expand All @@ -264,9 +293,11 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
emit(
BoardState.setFocus(
groupedRowIds: [
GroupedRowId(
groupId: toGroupId,
rowId: groupedRowId.rowId,
...rowIds.map(
(element) => GroupedRowId(
groupId: toGroupId,
rowId: element,
),
),
],
),
Expand Down Expand Up @@ -608,7 +639,7 @@ class BoardEvent with _$BoardEvent {
const factory BoardEvent.deleteCards(List<GroupedRowId> groupedRowIds) =
_DeleteCards;
const factory BoardEvent.moveGroupToAdjacentGroup(
GroupedRowId groupedRowId,
List<GroupedRowId> groupedRowIds,
bool toPrevious,
) = _MoveGroupToAdjacentGroup;
const factory BoardEvent.openRowDetail(RowMetaPB rowMeta) = _OpenRowDetail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class _DesktopBoardPageState extends State<DesktopBoardPage> {
final toRow = groupControllers[groupId]?.rowAtIndex(toIndex);
if (fromRow != null) {
widget.databaseController.moveGroupRow(
fromRow: fromRow,
fromRow: [fromRow],
toRow: toRow,
fromGroupId: groupId,
toGroupId: groupId,
Expand All @@ -142,7 +142,7 @@ class _DesktopBoardPageState extends State<DesktopBoardPage> {
final toRow = groupControllers[toGroupId]?.rowAtIndex(toIndex);
if (fromRow != null) {
widget.databaseController.moveGroupRow(
fromRow: fromRow,
fromRow: [fromRow],
toRow: toRow,
fromGroupId: fromGroupId,
toGroupId: toGroupId,
Expand Down Expand Up @@ -304,6 +304,9 @@ class _BoardContentState extends State<_BoardContent> {
rowMeta: value.rowMeta,
);
},
setFocus: (value) {
widget.focusScope.focusedGroupedRows = value.groupedRowIds;
},
orElse: () {},
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,9 @@ class BoardShortcutContainer extends StatelessWidget {
}

bool _moveGroupToAdjacentGroup(BuildContext context, bool toPrevious) {
if (focusScope.value.length != 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): _moveGroupToAdjacentGroup no longer returns a bool consistently

Add an explicit return true after dispatching, and ensure return false is used for invalid cases, to match the method's bool return type.

return false;
}
context.read<BoardBloc>().add(
BoardEvent.moveGroupToAdjacentGroup(
focusScope.value.first,
focusScope.value,
toPrevious,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ class DatabaseViewBackendService {
}

Future<FlowyResult<void, FlowyError>> moveGroupRow({
required RowId fromRowId,
required List<RowId> fromRowIds,
required String fromGroupId,
required String toGroupId,
RowId? toRowId,
}) {
final payload = MoveGroupRowPayloadPB.create()
..viewId = viewId
..fromRowId = fromRowId
..fromGroupId = fromGroupId
..toGroupId = toGroupId;
final payload = MoveGroupRowPayloadPB(
viewId: viewId,
fromRowIds: fromRowIds,
fromGroupId: fromGroupId,
toGroupId: toGroupId,
);

if (toRowId != null) {
payload.toRowId = toRowId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub struct MoveGroupRowPayloadPB {
pub view_id: String,

#[pb(index = 2)]
pub from_row_id: String,
pub from_row_ids: Vec<String>,

#[pb(index = 3)]
pub to_group_id: String,
Expand All @@ -174,7 +174,7 @@ pub struct MoveGroupRowPayloadPB {

pub struct MoveGroupRowParams {
pub view_id: String,
pub from_row_id: RowId,
pub from_row_ids: Vec<RowId>,
pub from_group_id: String,
pub to_group_id: String,
pub to_row_id: Option<RowId>,
Expand All @@ -189,12 +189,12 @@ impl TryInto<MoveGroupRowParams> for MoveGroupRowPayloadPB {
NotEmptyStr::parse(self.from_group_id).map_err(|_| ErrorCode::GroupIdIsEmpty)?;
let to_group_id =
NotEmptyStr::parse(self.to_group_id).map_err(|_| ErrorCode::GroupIdIsEmpty)?;

let from_row_ids = self.from_row_ids.iter().map(|e| RowId::from(e.clone())).collect();
Ok(MoveGroupRowParams {
view_id: view_id.0,
to_group_id: to_group_id.0,
from_group_id: from_group_id.0,
from_row_id: RowId::from(self.from_row_id),
from_row_ids: from_row_ids,
to_row_id: self.to_row_id.map(RowId::from),
})
}
Expand Down
20 changes: 11 additions & 9 deletions frontend/rust-lib/flowy-database2/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,15 +822,17 @@ pub(crate) async fn move_group_row_handler(
let database_editor = manager
.get_database_editor_with_view_id(&params.view_id)
.await?;
database_editor
.move_group_row(
&params.view_id,
&params.from_group_id,
&params.to_group_id,
params.from_row_id,
params.to_row_id,
)
.await?;
for from_row_id in params.from_row_ids {
database_editor
.move_group_row(
&params.view_id,
&params.from_group_id,
&params.to_group_id,
from_row_id,
params.to_row_id.clone(),
)
.await?;
}
Ok(())
}

Expand Down
Loading