Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: Fix Partner Location Bugs, Improve Hide/Unhide UX #57

Merged
merged 6 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pvdthings-api",
"version": "1.18.2",
"version": "1.18.3",
"description": "",
"main": "server.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions apps/api/services/inventory/mapItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function mapItem(record) {
estimatedValue: record.get('Estimated Value'),
eyeProtection: Boolean(record.get('Eye Protection')),
condition: record.get('Condition'),
location: record.get('Location')?.[0],
totalLoans: record.get('Total Loans'),
images: record.get('Picture')?.map(image => image.thumbnails.large.url) || [],
manuals: record.get('Manuals')?.map(manual => ({
Expand Down
1 change: 1 addition & 0 deletions apps/api/services/inventory/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const inventoryFields = [
'Eye Protection',
'Active Loans',
'Total Loans',
'Location',
'Manuals',
'Picture',
'Hidden',
Expand Down
8 changes: 8 additions & 0 deletions apps/librarian/lib/core/api/models/item_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ItemModel {
this.condition,
this.description,
this.estimatedValue,
this.location,
});

final String id;
Expand All @@ -23,6 +24,7 @@ class ItemModel {
final String? description;
final String? brand;
final String? condition;
final String? location;
final double? estimatedValue;
final bool available;
final bool hidden;
Expand All @@ -31,6 +33,11 @@ class ItemModel {
final List<String> imageUrls;
final List<ManualModel> manuals;

// TECH DEBT - Will be replaced by a location system in the future.
bool get isManagedByPartner {
return location == 'Providence Public Library';
}

factory ItemModel.fromJson(Map<String, dynamic> json) {
return ItemModel(
id: json['id'] as String,
Expand All @@ -42,6 +49,7 @@ class ItemModel {
totalLoans: json['totalLoans'] as int,
brand: json['brand'] as String?,
condition: json['condition'] as String?,
location: json['location'] as String?,
estimatedValue: json['estimatedValue'] as double?,
eyeProtection: json['eyeProtection'] as bool,
imageUrls: (json['images'] as List).cast<String>(),
Expand Down
34 changes: 34 additions & 0 deletions apps/librarian/lib/modules/things/details/inventory/icons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/material.dart';
import 'package:librarian_app/core/api/models/item_model.dart';

const checkedInIcon = Tooltip(
message: 'Available',
child: Icon(Icons.circle, color: Colors.green, size: 16),
);

const checkedOutIcon = Tooltip(
message: 'Unavailable',
child: Icon(Icons.circle, color: Colors.amber, size: 16),
);

const partnerLocationIcon = Tooltip(
message: 'Partner Location',
child: Icon(Icons.circle, color: Colors.grey, size: 16),
);

const hiddenIcon = Tooltip(
message: 'Hidden',
child: Icon(Icons.circle, color: Colors.red, size: 16),
);

Widget getIcon(ItemModel item) {
if (item.hidden) {
return hiddenIcon;
}

if (item.isManagedByPartner) {
return partnerLocationIcon;
}

return item.available ? checkedInIcon : checkedOutIcon;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'package:librarian_app/modules/things/details/inventory/icons.dart';
import 'package:librarian_app/modules/things/details/inventory/item_details/item_details_controller.dart';
import 'package:librarian_app/widgets/filled_progress_button.dart';

import '../item_details/item_details.dart';
import 'item_details.dart';

class ItemDetailsDrawer extends StatefulWidget {
const ItemDetailsDrawer({
Expand Down Expand Up @@ -38,11 +39,14 @@ class _ItemDetailsDrawerState extends State<ItemDetailsDrawer> {
Padding(
padding: const EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'#${widget.controller.item!.number}',
style: Theme.of(context).textTheme.titleLarge,
getIcon(widget.controller.item!),
const SizedBox(width: 8.0),
Expanded(
child: Text(
'#${widget.controller.item!.number}',
style: Theme.of(context).textTheme.titleLarge,
),
),
MenuAnchor(
controller: menuController,
Expand Down Expand Up @@ -71,7 +75,7 @@ class _ItemDetailsDrawerState extends State<ItemDetailsDrawer> {
ItemDetails(
controller: widget.controller,
item: widget.controller.item!,
hiddenLocked: widget.isHiddenLocked,
isThingHidden: widget.isHiddenLocked,
),
const SizedBox(height: 80),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class ItemDetails extends ConsumerWidget {
super.key,
required this.controller,
required this.item,
required this.hiddenLocked,
required this.isThingHidden,
});

final ItemDetailsController controller;
final ItemModel item;
final bool hiddenLocked;
final bool isThingHidden;

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -43,27 +43,12 @@ class ItemDetails extends ConsumerWidget {
clipBehavior: Clip.antiAlias,
elevation: isMobile(context) ? 1 : 0,
margin: EdgeInsets.zero,
child: Builder(
builder: (context) {
final newCheckbox = CheckboxListTile(
title: const Text('Hidden'),
secondary: const Icon(Icons.visibility_off_outlined),
value: controller.hiddenNotifier.value,
onChanged: hiddenLocked
? null
: (value) {
controller.hiddenNotifier.value = value ?? false;
},
);

if (!hiddenLocked) {
return newCheckbox;
}

return Tooltip(
message: 'Unable to unhide because the thing is hidden.',
child: newCheckbox,
);
child: _HiddenCheckboxListTile(
isThingHidden: isThingHidden,
isManagedByPartner: item.isManagedByPartner,
value: controller.hiddenNotifier.value,
onChanged: (value) {
controller.hiddenNotifier.value = value ?? false;
},
),
),
Expand Down Expand Up @@ -166,6 +151,15 @@ class ItemDetails extends ConsumerWidget {
},
value: controller.conditionNotifier.value,
),
const SizedBox(height: 16),
TextFormField(
decoration: const InputDecoration(
labelText: 'Location',
),
enabled: false,
initialValue: controller.item?.location,
readOnly: true,
),
],
),
),
Expand All @@ -188,3 +182,55 @@ class ItemDetails extends ConsumerWidget {
);
}
}

class _HiddenCheckboxListTile extends StatelessWidget {
const _HiddenCheckboxListTile({
required this.isThingHidden,
required this.isManagedByPartner,
required this.value,
required this.onChanged,
});

final bool isThingHidden;
final bool isManagedByPartner;
final bool? value;
final void Function(bool?) onChanged;

@override
Widget build(BuildContext context) {
return Builder(
builder: (context) {
if (isThingHidden) {
return const CheckboxListTile(
title: Text('Hidden'),
subtitle:
Text('Unable to unhide because the parent thing is hidden.'),
secondary: Icon(Icons.visibility_off_outlined),
value: true,
onChanged: null,
);
}

if (isManagedByPartner) {
return const CheckboxListTile(
title: Text('Hidden'),
subtitle: Text(
'Unable to unhide because this item is at a partner location.'),
secondary: Icon(Icons.visibility_off_outlined),
value: true,
onChanged: null,
);
}

return CheckboxListTile(
title: const Text('Hidden'),
secondary: value == true
? const Icon(Icons.visibility_off_outlined)
: const Icon(Icons.visibility_outlined),
value: value,
onChanged: onChanged,
);
},
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class _ItemDetailsPageState extends ConsumerState<ItemDetailsPage> {
child: ItemDetails(
controller: _controller,
item: widget.item,
hiddenLocked: widget.hiddenLocked,
isThingHidden: widget.hiddenLocked,
),
),
),
Expand Down
Loading