Skip to content

Commit b770346

Browse files
committed
show permission table/history if a single/seleced resource
1 parent f7a2eb6 commit b770346

File tree

1 file changed

+115
-90
lines changed

1 file changed

+115
-90
lines changed

lib/src/widgets/grant_permission_ui_state.dart

Lines changed: 115 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ class GrantPermissionUiState extends State<GrantPermissionUi>
125125
// otherwise use the first entry from resourceNames.
126126
final displayResource =
127127
widget.resourceName ?? widget.resourceNames?.firstOrNull;
128-
_selectedResourceName = displayResource;
128+
// When resourceNames is provided, start with no selection so the
129+
// permission table/history are hidden until the user picks a resource.
130+
_selectedResourceName =
131+
widget.resourceNames != null ? null : displayResource;
129132
if (displayResource != null) {
130133
getACLPerm = loadACLData(
131134
displayResource,
@@ -364,14 +367,17 @@ class GrantPermissionUiState extends State<GrantPermissionUi>
364367
),
365368
// Separator between Sharing and Permissions sections
366369
const Divider(),
367-
smallGapV,
368-
makeSubHeading(
369-
showCurrentPermOnly
370-
? 'People with current access'
371-
: 'Permission history',
372-
addPadding: false,
373-
),
374-
smallGapV,
370+
if (widget.resourceNames != null ||
371+
widget.resourceName != null) ...[
372+
smallGapV,
373+
makeSubHeading(
374+
showCurrentPermOnly
375+
? 'People with current access'
376+
: 'Permission history',
377+
addPadding: false,
378+
),
379+
smallGapV,
380+
],
375381
// Dropdown to select which resource's permission table/history to show.
376382
if (widget.resourceNames != null) ...[
377383
DropdownMenu<String>(
@@ -381,7 +387,7 @@ class GrantPermissionUiState extends State<GrantPermissionUi>
381387
// to zero to align with other elements
382388
// in the layout
383389
expandedInsets: const EdgeInsets.symmetric(horizontal: 0),
384-
initialSelection: _selectedResourceName,
390+
initialSelection: null,
385391
label: Text(widget.isFile ? 'Select File' : 'Select Folder'),
386392
textStyle: Theme.of(context)
387393
.dropdownMenuTheme
@@ -457,95 +463,114 @@ class GrantPermissionUiState extends State<GrantPermissionUi>
457463
},
458464
),
459465
smallGapV,
466+
if (_selectedResourceName != null)
467+
Align(
468+
alignment: Alignment.centerLeft,
469+
child: Text(
470+
_displayName(_selectedResourceName!),
471+
style: Theme.of(context)
472+
.textTheme
473+
.bodyMedium
474+
?.copyWith(fontSize: 12),
475+
),
476+
),
477+
smallGapV,
460478
],
461-
Row(
462-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
463-
spacing: 5.0,
464-
children: [
465-
Expanded(
466-
flex: 3,
467-
child: showCurrentPermOnly
468-
? const Text('')
469-
: TextField(
470-
onChanged: (value) => _searchLogs(value),
471-
decoration: const InputDecoration(
472-
labelText:
473-
'Search access level, permission type, recipient or granter name',
474-
labelStyle: TextStyle(fontSize: 12),
475-
hintText: 'Enter search text',
476-
hintStyle: TextStyle(fontSize: 12),
477-
prefixIcon: Icon(Icons.search),
478-
border: OutlineInputBorder(
479-
borderRadius:
480-
BorderRadius.all(Radius.circular(25.0)),
479+
if (widget.resourceNames != null || widget.resourceName != null)
480+
Row(
481+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
482+
spacing: 5.0,
483+
children: [
484+
Expanded(
485+
flex: 3,
486+
child: showCurrentPermOnly
487+
? const Text('')
488+
: TextField(
489+
onChanged: (value) => _searchLogs(value),
490+
decoration: const InputDecoration(
491+
labelText:
492+
'Search access level, permission type, recipient or granter name',
493+
labelStyle: TextStyle(fontSize: 12),
494+
hintText: 'Enter search text',
495+
hintStyle: TextStyle(fontSize: 12),
496+
prefixIcon: Icon(Icons.search),
497+
border: OutlineInputBorder(
498+
borderRadius:
499+
BorderRadius.all(Radius.circular(25.0)),
500+
),
481501
),
482502
),
483-
),
484-
),
485-
SizedBox(
486-
width: 170.0,
487-
child: MarkdownTooltip(
488-
message:
489-
'Switch between current people with access and permission history log',
490-
child: Row(
491-
mainAxisAlignment: MainAxisAlignment.end,
492-
spacing: 5.0,
493-
children: [
494-
SizedBox(
495-
width: 100,
496-
child: Text(
497-
showCurrentPermOnly
498-
? 'Current Permissions'
499-
: 'All Permissions',
500-
maxLines: 2,
501-
overflow: TextOverflow.ellipsis,
502-
textAlign: TextAlign.end,
503+
),
504+
SizedBox(
505+
width: 170.0,
506+
child: MarkdownTooltip(
507+
message:
508+
'Switch between current people with access and permission history log',
509+
child: Row(
510+
mainAxisAlignment: MainAxisAlignment.end,
511+
spacing: 5.0,
512+
children: [
513+
SizedBox(
514+
width: 100,
515+
child: Text(
516+
showCurrentPermOnly
517+
? 'Current Permissions'
518+
: 'All Permissions',
519+
maxLines: 2,
520+
overflow: TextOverflow.ellipsis,
521+
textAlign: TextAlign.end,
522+
),
503523
),
504-
),
505-
Switch(
506-
value: showCurrentPermOnly,
507-
activeThumbColor: Theme.of(context)
508-
.switchTheme
509-
.thumbColor
510-
?.resolve(
511-
{WidgetState.selected},
512-
) ??
513-
ActionColors.success,
514-
onChanged: (bool value) {
515-
setState(() {
516-
showCurrentPermOnly = value;
517-
});
518-
if (!showCurrentPermOnly) {
524+
Switch(
525+
value: showCurrentPermOnly,
526+
activeThumbColor: Theme.of(context)
527+
.switchTheme
528+
.thumbColor
529+
?.resolve(
530+
{WidgetState.selected},
531+
) ??
532+
ActionColors.success,
533+
onChanged: (bool value) {
519534
setState(() {
520-
permHistoryList = unFilteredPermHistoryList;
535+
showCurrentPermOnly = value;
521536
});
522-
}
523-
},
524-
),
525-
],
537+
if (!showCurrentPermOnly) {
538+
setState(() {
539+
permHistoryList = unFilteredPermHistoryList;
540+
});
541+
}
542+
},
543+
),
544+
],
545+
),
526546
),
527547
),
528-
),
529-
],
530-
),
548+
],
549+
),
531550
vSmallGapV,
532-
showCurrentPermOnly
533-
? PermissionTable(
534-
resourceName: permDataFile,
535-
permDataMap: permDataMap,
536-
ownerWebId: _ownerWebId,
537-
granterWebId: _granterWebId,
538-
updatePermissionsFunction: _updatePermissions,
539-
isFile: getIsFile(),
540-
isExternalRes: widget.isExternalRes,
541-
constraints: constraints,
542-
)
543-
: PermissionHistory(
544-
key: ValueKey(permHistoryList),
545-
resourceName: resolvedResourceName!,
546-
permHistory: permHistoryList,
547-
constraints: constraints,
548-
),
551+
// Show the permission table/history
552+
// if single resource name or if
553+
// a resource is selected from a resource list
554+
if (widget.resourceNames == null ||
555+
_selectedResourceName != null) ...[
556+
showCurrentPermOnly
557+
? PermissionTable(
558+
resourceName: permDataFile,
559+
permDataMap: permDataMap,
560+
ownerWebId: _ownerWebId,
561+
granterWebId: _granterWebId,
562+
updatePermissionsFunction: _updatePermissions,
563+
isFile: getIsFile(),
564+
isExternalRes: widget.isExternalRes,
565+
constraints: constraints,
566+
)
567+
: PermissionHistory(
568+
key: ValueKey(permHistoryList),
569+
resourceName: resolvedResourceName!,
570+
permHistory: permHistoryList,
571+
constraints: constraints,
572+
),
573+
],
549574
],
550575
),
551576
);

0 commit comments

Comments
 (0)