8000 fix(sort): make custom sort work as a single, consistent ordering by ahmet-cetinkaya · Pull Request #300 · ahmet-cetinkaya/whph · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
94bfb2c
fix(reorder): make drag-and-drop land exactly where dropped
ahmet-cetinkaya Jul 19, 2026
5c1237c
refactor(reorder): apply code-review fixes to custom-order logic
ahmet-cetinkaya Jul 19, 2026
3e86fb9
chore(zed): add Nix dev-shell debug/run config for Zed editor
ahmet-cetinkaya Aug 2, 2026
c9c25f6
chore(acore): bump submodule to string-rank OrderRank
ahmet-cetinkaya Aug 23, 2026
1faba69
refactor(domain)!: convert entity order fields to String ranks
ahmet-cetinkaya Aug 23, 2026
9a98cc4
feat(db): migrate order columns to TEXT with schema v36
ahmet-cetinkaya Aug 23, 2026
e4ad667
fix(reorder): align sibling scope and resolve drops by identity
ahmet-cetinkaya Aug 23, 2026
ed9cfee
fix(query): stop grouping from overriding custom sort order
ahmet-cetinkaya Aug 23, 2026
07109ad
refactor(application): adopt string ranks in remaining order consumers
ahmet-cetinkaya Aug 23, 2026
21d86f1
fix(import): normalize entity ranks when restoring legacy backups
ahmet-cetinkaya Aug 23, 2026
c10353f
fix(ui): make custom sort the single control for reordering
ahmet-cetinkaya Aug 23, 2026
52f461d
refactor(ui): adopt string ranks in task status and task data
ahmet-cetinkaya Aug 23, 2026
3667583
fix(tags): keep selected tag labels when tag is off the current page
ahmet-cetinkaya Aug 23, 2026
c3f5090
chore(scripts): silence shellcheck on intentional nested-bash expansion
ahmet-cetinkaya Aug 23, 2026
b01d58d
test(order-rank): cover string rank grammar and sibling placement
ahmet-cetinkaya Aug 23, 2026
88b05f3
test(db): verify v35 to v36 preserves order, partitions and children
ahmet-cetinkaya Aug 23, 2026
87ef0d1
test(ordering): cover reorder commands and custom sort query paths
ahmet-cetinkaya Aug 23, 2026
4e6c173
test(import): cover legacy backup rank normalization boundaries
ahmet-cetinkaya Aug 23, 2026
7b4e78b
test(ui): cover single custom sort control and grouping suppression
ahmet-cetinkaya Aug 23, 2026
22bce1f
test(db): cover v35 to v36 at real-world scale and hostile order values
ahmet-cetinkaya Aug 23, 2026
e1f0b60
fix(reorder): scope task reorder to the task's own parent, not the ca…
ahmet-cetinkaya Aug 23, 2026
336a780
fix(migration): abort migration when the pre-migration backup fails
ahmet-cetinkaya Aug 23, 2026
e1912d0
test(db): prove v35 to v36 rolls back entirely on transaction failure
ahmet-cetinkaya Aug 23, 2026
62e3790
perf(migration): make task partition grouping linear, not quadratic
ahmet-cetinkaya Aug 23, 2026
fb99bd1
fix(import): normalize note ranks after import like habits and tasks
ahmet-cetinkaya Aug 23, 2026
c2b2433
fix(migration): detect partial v35 to v36 conversion instead of skipp…
ahmet-cetinkaya Aug 23, 2026
8c623e7
refactor(reorder): make computePlacement a pure function
ahmet-cetinkaya Aug 23, 2026
2502333
perf(reorder): drop the redundant Dart re-sort after SQL ORDER BY
ahmet-cetinkaya Aug 23, 2026
097c021
perf(import): normalize imported task ranks in one pass, not N round-…
ahmet-cetinkaya Aug 23, 2026
2fc1f9a
fix(habits): stabilize reorder tie-breakers
ahmet-cetinkaya Aug 30, 2026
243e0cf
fix(query): ignore stale task grouping when disabled
ahmet-cetinkaya Aug 30, 2026
ecd5a8d
feat(sort): persist drag indicator visibility
ahmet-cetinkaya Aug 30, 2026
60f2271
feat(sort): add drag indicator visibility control
ahmet-cetinkaya Aug 30, 2026
84450a4
fix(ui): keep grouping and view controls available
ahmet-cetinkaya Aug 30, 2026
2130a3b
fix(habits): support grouped custom reorder layouts
ahmet-cetinkaya Aug 30, 2026
80e7016
fix(tasks): support grouped custom reorder layouts
ahmet-cetinkaya Aug 30, 2026
deb1991
fix(tasks): make schedule tooltip reorder-safe
ahmet-cetinkaya Aug 30, 2026
d4d32b6
chore(git): ignore local agent artifacts
ahmet-cetinkaya Aug 30, 2026
7b14e3e
style: apply formatter and lint cleanup
ahmet-cetinkaya Aug 30, 2026
2515cdd
fix(tasks): scope automatic rank normalization
ahmet-cetinkaya Aug 30, 2026
6bcc9e5
fix(habits): avoid grouped rank normalization churn
ahmet-cetinkaya Aug 30, 2026
2bafdd3
fix(tasks): stabilize reorder tie-breakers
ahmet-cetinkaya Aug 30, 2026
9586fa0
fix(tasks): stabilize rank normalization order
ahmet-cetinkaya Aug 30, 2026
893c5a9
fix(import): stabilize imported task rank order
ahmet-cetinkaya Aug 30, 2026
604abc1
fix(tags): preserve off-page selected labels
ahmet-cetinkaya Aug 30, 2026
becb2e9
chore(merge): sync origin/main into reorder fix
ahmet-cetinkaya Aug 30, 2026
471b5d2
style(sync): apply formatter after main merge
ahmet-cetinkaya Aug 30, 2026
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
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
#.vscode/

# AI Agent files
*AGENTS.md
*CLAUDE.md
*GEMINI.md
*QWEN.md
.claude/
.gemini/
.kilo/
.omo/
.opencode/
.qwen/
.serena/
.sisyphus/
.specify/
*AGENTS.md
*CLAUDE.md
*GEMINI.md
*QWEN.md
docs/.tasks/
graphify-out/
PROJECT_INDEX.json
PROJECT_INDEX.md
graphify-out/

# FVM Version Cache
.fvm/
Expand All @@ -46,4 +47,4 @@ repo/
.venv/

# Node
node_modules/
node_modules/
26 changes: 26 additions & 0 deletions .zed/debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Zed debug configuration for WHPH (Flutter).
// The Flutter project lives in `src/`, so cwd points there.
// Flutter is launched inside the Nix dev shell (scripts/zed_nix_flutter.sh) so
// the session gets the SDK + native runtime deps (ninja, CMake, GTK/X11/Wayland)
// that `nix develop` provides.
// `deviceId` pins the target device because multiple devices (Linux desktop +
// Chrome) are usually connected and Flutter otherwise aborts with "More than
// one device connected". A `-d` CLI flag on the wrapper does NOT work here:
// the debug adapter launches the real `flutter run` itself over DAP, not via
// the argv this script receives, so device selection must go through the
// launch config's `deviceId` field instead.
// The Dart extension requires the `type` field ("flutter" here).
// See: https://zed.dev/docs/debugger
[
{
"label": "whph",
"adapter": "Dart",
"type": "flutter",
"request": "launch",
"program": "lib/main.dart",
"cwd": "$ZED_WORKTREE_ROOT/src",
"deviceId": "linux",
"customTool": "$ZED_WORKTREE_ROOT/scripts/zed_nix_flutter.sh",
"customToolReplacesArgs": 0
}
]
60 changes: 60 additions & 0 deletions .zed/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Zed run tasks for WHPH (Flutter). Open with `task: spawn` from the palette.
//
// Every task runs inside the Nix dev shell via scripts/zed_nix_run.sh, because
// the Linux desktop build needs native tooling (ninja, CMake, GTK/X11/Wayland
// libs) that only `nix develop` provides. Without it, `fvm flutter run` fails
// on NixOS with "CMake Error ... ninja ... No such file or directory".
//
// NOTE: after editing this file, reload Zed's task cache — run
// `task: spawn` (not `task: rerun`) and pick the task, or reopen the project.
// See: https://zed.dev/docs/tasks
[
{
"label": "whph: run (Linux)",
"command": "$ZED_WORKTREE_ROOT/scripts/zed_nix_run.sh src fvm flutter run -d linux",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "whph: run (demo mode)",
"command": "$ZED_WORKTREE_ROOT/scripts/zed_nix_run.sh src fvm flutter run -d linux --dart-define DEMO_MODE=true",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "whph: test",
"command": "$ZED_WORKTREE_ROOT/scripts/zed_nix_run.sh src fvm flutter test",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "whph: pub get",
"command": "$ZED_WORKTREE_ROOT/scripts/zed_nix_run.sh src fvm flutter pub get",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "whph: codegen (build_runner + drift)",
"command": "$ZED_WORKTREE_ROOT/scripts/zed_nix_run.sh . rps gen",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
},
{
"label": "whph: check (format + lint + test)",
"command": "$ZED_WORKTREE_ROOT/scripts/zed_nix_run.sh . rps check",
"cwd": "$ZED_WORKTREE_ROOT",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always"
}
]
2 changes: 1 addition & 1 deletion packages/acore-flutter
20 changes: 20 additions & 0 deletions scripts/zed_nix_flutter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Wrapper used by Zed's Dart debug adapter (customTool) to launch Flutter
# inside the Nix dev shell, so the debug/run session has the same SDK and
# native runtime dependencies (X11/Wayland, CMake libs) that `nix develop`
# provides. Zed passes the full `flutter <args...>` invocation as arguments
# (typically `flutter debug_adapter ...`).
#
# Device selection (avoiding "More than one device connected" when both the
# Linux desktop and Chrome are attached) is NOT done here: the debug adapter
# launches the actual `flutter run` itself over DAP, not via the argv this
# script receives, so a `-d` flag injected into this argv never reaches it.
# Set the target device via the launch config's `deviceId` field instead
# (see .zed/debug.json).
set -euo pipefail

# Resolve the repo root (this script lives in <root>/scripts/).
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

# Run inside the flake dev shell (puts fvm's pinned Flutter SDK on PATH).
exec nix develop "$REPO_ROOT" --command "$@"
25 changes: 25 additions & 0 deletions scripts/zed_nix_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Wrapper used by Zed run tasks to execute a command inside the Nix dev shell,
# so the Linux desktop build gets the native tooling it needs (ninja, CMake,
# GTK/X11/Wayland libs). Without this, `fvm flutter run` fails on NixOS with
# "CMake Error ... ninja ... No such file or directory".
#
# Usage: zed_nix_run.sh <subdir> <command...>
# <subdir> directory (relative to repo root) to run the command in,
# e.g. "src" for the Flutter project, "." for the repo root.
# <command...> the command and args to run inside the dev shell.
set -euo pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

SUBDIR="${1:?usage: zed_nix_run.sh <subdir> <command...>}"
shift

# Enter the flake dev shell (finds flake.nix via REPO_ROOT), cd into the target
# subdirectory, then exec the requested command with its arguments intact.
# shellcheck disable=SC2016 # The inner Bash must expand these positional parameters.
exec nix develop "$REPO_ROOT" --command bash -c '
cd "$1/$2" || exit 1
shift 2
exec "$@"
' bash "$REPO_ROOT" "$SUBDIR" "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,70 @@ class DemoNotes {
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteMeetingTitle),
content: translate(DemoTranslationKeys.noteMeetingContent),
order: 1.0,
order: '1',
createdDate: DateTime.now().subtract(const Duration(days: 2)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteBookTitle),
content: translate(DemoTranslationKeys.noteBookContent),
order: 2.0,
order: '2',
createdDate: DateTime.now().subtract(const Duration(days: 5)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteRecipeTitle),
content: translate(DemoTranslationKeys.noteRecipeContent),
order: 3.0,
order: '3',
createdDate: DateTime.now().subtract(const Duration(days: 8)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteTravelTitle),
content: translate(DemoTranslationKeys.noteTravelContent),
order: 4.0,
order: '4',
createdDate: DateTime.now().subtract(const Duration(days: 12)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteWeeklyGoalsTitle),
content: translate(DemoTranslationKeys.noteWeeklyGoalsContent),
order: 5.0,
order: '5',
createdDate: DateTime.now().subtract(const Duration(days: 3)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteProjectIdeasTitle),
content: translate(DemoTranslationKeys.noteProjectIdeasContent),
order: 6.0,
order: '6',
createdDate: DateTime.now().subtract(const Duration(days: 6)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteInvestmentTitle),
content: translate(DemoTranslationKeys.noteInvestmentContent),
order: 7.0,
order: '7',
createdDate: DateTime.now().subtract(const Duration(days: 9)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteWorkoutTitle),
content: translate(DemoTranslationKeys.noteWorkoutContent),
order: 8.0,
order: '8',
createdDate: DateTime.now().subtract(const Duration(days: 4)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteLearningTitle),
content: translate(DemoTranslationKeys.noteLearningContent),
order: 9.0,
order: '9',
createdDate: DateTime.now().subtract(const Duration(days: 7)),
),
Note(
id: KeyHelper.generateStringId(),
title: translate(DemoTranslationKeys.noteBudgetTitle),
content: translate(DemoTranslationKeys.noteBudgetContent),
order: 10.0,
order: 'A',
createdDate: DateTime.now().subtract(const Duration(days: 15)),
),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,34 @@ class NormalizeHabitOrdersCommandHandler

@override
Future<NormalizeHabitOrdersResponse> call(NormalizeHabitOrdersCommand request) async {
// Get all non-deleted habits
// Match the visible list's tie-breakers so normalization preserves its order.
final allHabits = await _habitRepository.getAll(
customWhereFilter: CustomWhereFilter('deleted_date IS NULL', []),
customOrder: [CustomOrder(field: "order")],
customOrder: [
CustomOrder(field: "order", direction: SortDirection.asc),
CustomOrder(field: "created_date", direction: SortDirection.asc),
CustomOrder(field: "id", direction: SortDirection.asc),
],
);

if (allHabits.isEmpty) {
return NormalizeHabitOrdersResponse(0);
}

// Sort by current order to maintain relative positions
allHabits.sort((a, b) => a.order.compareTo(b.order));
allHabits.sort((a, b) {
final orderComparison = a.order.compareTo(b.order);
if (orderComparison != 0) return orderComparison;

// Use single timestamp for all updates in the batch
final now = DateTime.now().toUtc();
final createdDateComparison = a.createdDate.compareTo(b.createdDate);
if (createdDateComparison != 0) return createdDateComparison;

// Assign new normalized orders
double orderStep = OrderRank.initialStep;
final habitsToUpdate = <Habit>[];
return a.id.compareTo(b.id);
});

for (var habit in allHabits) {
habit.order = orderStep;
habit.modifiedDate = now;
habitsToUpdate.add(habit);
orderStep += OrderRank.initialStep;
}

// Batch update all habits
await _habitRepository.updateAll(habitsToUpdate);
// Assign clean, evenly spaced orders and batch update in one transaction.
OrderRank.assignSequential<Habit>(allHabits, setOrder: (habit, order) => habit.order = order);
await _habitRepository.updateMultiple(allHabits);

return NormalizeHabitOrdersResponse(habitsToUpdate.length);
return NormalizeHabitOrdersResponse(allHabits.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class SaveHabitCommandHandler implements IRequestHandler<SaveHabitCommand, SaveH
customOrder: [CustomOrder(field: "order", direction: SortDirection.desc)],
);

final lastOrder = lastHabits.items.isNotEmpty ? lastHabits.items.first.order : 0;
final newOrder = (lastOrder + OrderRank.initialStep).toDouble();
final lastOrder = lastHabits.items.isNotEmpty ? lastHabits.items.first.order : null;
final newOrder = OrderRank.neighborRank(beforeOrder: lastOrder, afterOrder: null);

// Create habit with default values
habit = Habit(
Expand All @@ -126,7 +126,7 @@ class SaveHabitCommandHandler implements IRequestHandler<SaveHabitCommand, SaveH
periodDays: request.periodDays ?? 1,
dailyTarget: request.dailyTarget ?? 1,
archivedDate: request.archivedDate,
order: newOrder, // Set the calculated order
order: newOrder,
);

// Set reminder days using the helper method
Expand Down
Loading
Loading
0