added SortBy in query builder
fix in query builder
MODIFY
packages/isar_inspector/lib/collections.dart
packages/isar_inspector/lib/collections.dart
@@ -38,10 +38,11 @@ class CollectionsList extends ConsumerWidget {
collection.name;
ref.read(queryFilterPod.state).state =
- collection.lastFilter == null
+ collection.uiFilter == null
? null
- : QueryBuilderUI.parseQuery(collection.lastFilter!);
+ : QueryBuilderUI.parseQuery(collection.uiFilter!);
+ ref.read(querySortPod.state).state = collection.uiSort;
ref.read(queryPagePod.state).state = 1;
}
},

MODIFY
packages/isar_inspector/lib/common.dart
packages/isar_inspector/lib/common.dart
@@ -61,9 +61,7 @@ class CheckBoxLabel extends StatelessWidget {
child: Row(
children: [
InkWell(
- onTap: onChanged != null
- ? () => onChanged!(!value)
- : null,
+ onTap: onChanged != null ? () => onChanged!(!value) : null,
child: Padding(
padding: const EdgeInsets.all(8),
child: Row(

MODIFY
packages/isar_inspector/lib/filter_field.dart
packages/isar_inspector/lib/filter_field.dart
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
+import 'package:isar/isar.dart';
import 'package:isar_inspector/desktop/download.dart'
if (dart.library.html) 'package:isar_inspector/web/download.dart';
@@ -28,22 +29,28 @@ class _FilterFieldState extends ConsumerState<FilterField> {
ElevatedButton(
onPressed: () async {
final selectedCollection = ref.read(selectedCollectionPod).value!;
- final filter = await showDialog<QueryBuilderUIGroupHelper?>(
+ final result = await showDialog<Map<String, dynamic>>(
context: context,
builder: (context) {
return AlertDialog(
content: QueryBuilderUI(
collection: selectedCollection,
- filter: selectedCollection.lastFilter,
+ filter: selectedCollection.uiFilter,
+ sort: selectedCollection.uiSort,
),
);
},
);
- if (filter != null) {
- selectedCollection.lastFilter = filter;
+ if (result != null) {
+ final filter = result['filter'] as QueryBuilderUIGroupHelper;
+ final sort = result['sort'] as SortProperty?;
+
+ selectedCollection.uiFilter = filter;
+ selectedCollection.uiSort = sort;
ref.read(queryFilterPod.state).state =
QueryBuilderUI.parseQuery(filter);
+ ref.read(querySortPod.state).state = sort;
ref.read(queryPagePod.state).state = 1;
}
},
@@ -53,9 +60,9 @@ class _FilterFieldState extends ConsumerState<FilterField> {
ElevatedButton(
onPressed: () async {
final selectedCollection = ref.read(selectedCollectionPod).value!;
- final filter = selectedCollection.lastFilter == null
+ final filter = selectedCollection.uiFilter == null
? null
- : QueryBuilderUI.parseQuery(selectedCollection.lastFilter!);
+ : QueryBuilderUI.parseQuery(selectedCollection.uiFilter!);
final q = ConnectQuery(
instance: ref.read(selectedInstancePod).value!,
collection: selectedCollection.name,
@@ -71,9 +78,9 @@ class _FilterFieldState extends ConsumerState<FilterField> {
ElevatedButton(
onPressed: () {
final selectedCollection = ref.read(selectedCollectionPod).value!;
- final filter = selectedCollection.lastFilter == null
+ final filter = selectedCollection.uiFilter == null
? null
- : QueryBuilderUI.parseQuery(selectedCollection.lastFilter!);
+ : QueryBuilderUI.parseQuery(selectedCollection.uiFilter!);
final query = ConnectQuery(
instance: ref.read(selectedInstancePod).value!,
collection: selectedCollection.name,

MODIFY
packages/isar_inspector/lib/query_builder.dart
packages/isar_inspector/lib/query_builder.dart
@@ -6,10 +6,16 @@ import 'package:isar_inspector/common.dart';
import 'package:isar_inspector/schema.dart';
class QueryBuilderUI extends StatefulWidget {
- const QueryBuilderUI({super.key, required this.collection, this.filter});
+ const QueryBuilderUI({
+ super.key,
+ required this.collection,
+ this.filter,
+ this.sort,
+ });
final ICollection collection;
- final QueryBuilderUIHelper? filter;
+ final QueryBuilderUIGroupHelper? filter;
+ final SortProperty? sort;
@override
State<QueryBuilderUI> createState() => _QueryBuilderUIState();
@@ -113,14 +119,22 @@ class QueryBuilderUI extends StatefulWidget {
class _QueryBuilderUIState extends State<QueryBuilderUI> {
late final QueryBuilderUIGroupHelper _filter;
+ late SortProperty? _sort = widget.sort;
+ late final List<IProperty> _sortProps;
@override
void initState() {
super.initState();
- _filter = widget.filter == null
- ? QueryBuilderUIGroupHelper(QueryBuilderUIOP.and)
- : widget.filter! as QueryBuilderUIGroupHelper;
+ if (widget.filter != null) {
+ _filter = QueryBuilderUIGroupHelper(widget.filter!.operation)
+ ..children.addAll(widget.filter!.children);
+ } else {
+ _filter = QueryBuilderUIGroupHelper(QueryBuilderUIOP.and);
+ }
+
+ _sortProps =
+ widget.collection.allProperties.where((p) => !p.type.isList).toList();
}
@override
@@ -135,9 +149,7 @@ class _QueryBuilderUIState extends State<QueryBuilderUI> {
Expanded(
child: SingleChildScrollView(
child: Container(
- constraints: BoxConstraints(
- minHeight: size.height - 260,
- ),
+ constraints: BoxConstraints(minHeight: size.height - 270),
child: _GroupUI(
helper: _filter,
collection: widget.collection,
@@ -150,7 +162,7 @@ class _QueryBuilderUIState extends State<QueryBuilderUI> {
children: [
ElevatedButton(
onPressed: () {
- Navigator.pop(context, _filter);
+ Navigator.pop(context, {'filter': _filter, 'sort': _sort});
},
child: const Text('Build'),
),
@@ -159,13 +171,85 @@ class _QueryBuilderUIState extends State<QueryBuilderUI> {
onPressed: () {
Navigator.pop(
context,
- QueryBuilderUIGroupHelper(QueryBuilderUIOP.and),
+ {
+ 'filter': QueryBuilderUIGroupHelper(QueryBuilderUIOP.and),
+ 'sort': null
+ },
);
},
child: const Text('Clear'),
),
- ],
+ const Spacer(),
+ CheckBoxLabel(
+ value: _sort != null,
+ text: 'Sort By',
+ onChanged: (value) {
+ setState(() {
+ _sort = !value
+ ? null
+ : SortProperty(
+ property: _sortProps.first.name,
+ sort: Sort.asc,
+ );
+ });
+ },
+ ),
+ const SizedBox(width: 15),
+ DropdownButtonHideUnderline(
+ child: DropdownButton<String>(
+ value: _sort?.property ?? _sortProps.first.name,
+ items: _sortProps
+ .map(
+ (e) => DropdownMenuItem(
+ value: e.name,
+ child: Text(e.name),
+ ),
)
+ .toList(),
+ onChanged: _sort == null
+ ? null
+ : (value) {
+ if (value != null) {
+ setState(() {
+ _sort = SortProperty(
+ property: value,
+ sort: _sort!.sort,
+ );
+ });
+ }
+ },
+ ),
+ ),
+ const SizedBox(width: 15),
+ DropdownButtonHideUnderline(
+ child: DropdownButton<Sort>(
+ value: _sort?.sort ?? Sort.asc,
+ items: const [
+ DropdownMenuItem(
+ value: Sort.asc,
+ child: Text('ASC'),
+ ),
+ DropdownMenuItem(
+ value: Sort.desc,
+ child: Text('DESC'),
+ )
+ ],
+ onChanged: _sort == null
+ ? null
+ : (value) {
+ if (value != null) {
+ setState(() {
+ _sort = SortProperty(
+ property: _sort!.property,
+ sort: value,
+ );
+ });
+ }
+ },
+ ),
+ ),
+ ],
+ ),
],
),
);

MODIFY
packages/isar_inspector/lib/query_table.dart
packages/isar_inspector/lib/query_table.dart
@@ -49,8 +49,10 @@ class QueryTable extends ConsumerWidget {
return Stack(
children: [
TableBlock(
- key: ValueKey('${collection.name}'
- '_${objects[index].getValue(collection.idName)}'),
+ key: ValueKey(
+ '${collection.name}'
+ '_${objects[index].getValue(collection.idName)}',
+ ),
collection: collection,
object: objects[index],
editor: (id, property, index, value) {

MODIFY
packages/isar_inspector/lib/schema.dart
packages/isar_inspector/lib/schema.dart
@@ -26,7 +26,8 @@ class ICollection {
final String idName;
final List<IProperty> properties;
final List<ILink> links;
- QueryBuilderUIGroupHelper? lastFilter;
+ QueryBuilderUIGroupHelper? uiFilter;
+ SortProperty? uiSort;
late final List<IProperty> allProperties = [
IProperty(name: idName, type: IsarType.Long, isId: true),
@@ -41,8 +42,7 @@ class IProperty {
this.isId = false,
});
- factory IProperty.fromJson(Map<String, dynamic> json) =>
- IProperty(
+ factory IProperty.fromJson(Map<String, dynamic> json) => IProperty(
name: json['name'] as String,
type: IsarType.values.firstWhere((e) => e.name == json['type']),
isId: json['isId'] as bool? ?? false,

MODIFY
packages/isar_inspector/lib/state/query_state.dart
packages/isar_inspector/lib/state/query_state.dart
@@ -50,7 +50,6 @@ final queryResultsPod = FutureProvider<QueryResult>((ref) async {
),
);
- //ignore: avoid_dynamic_calls
final objects = (result['results']! as List<dynamic>)
.map((e) => e as Map<String, dynamic>)
.toList()

added SortBy in query builder

fix in query builder