0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Improved Audit log filtering UI

refs https://github.com/TryGhost/Toolbox/issues/356

- the existing structure of 1 checkbox per resource was becoming unsustainable
  as we added events for more resources
- instead, we're going to group resources together into categories so
  they can be disabled/enabled together
- this implements that, and also enables showing Tier and Offer events
  now we have something that works nicely
This commit is contained in:
Daniel Lockyer 2022-08-24 16:03:14 +02:00
parent 663204d308
commit 05e32b3ea5
No known key found for this signature in database
GPG key ID: D21186F0B47295AD
3 changed files with 19 additions and 19 deletions

View file

@ -34,7 +34,7 @@
id="resource-type-{{idx}}" id="resource-type-{{idx}}"
name="resourceTypes" name="resourceTypes"
class="gh-input post-settings-featured" class="gh-input post-settings-featured"
{{on "input" (fn this.toggleResourceType type.event)}}> {{on "input" (fn this.toggleResourceType type.targets)}}>
<span class="input-toggle-component"></span> <span class="input-toggle-component"></span>
<p>{{type.name}}</p> <p>{{type.name}}</p>
</label> </label>

View file

@ -8,15 +8,12 @@ const ALL_EVENT_TYPES = [
]; ];
const ALL_RESOURCE_TYPES = [ const ALL_RESOURCE_TYPES = [
{event: 'post', name: 'Posts'}, {targets: 'post', name: 'Posts'},
{event: 'page', name: 'Pages'}, {targets: 'page', name: 'Pages'},
{event: 'tag', name: 'Tags'}, {targets: 'tag', name: 'Tags'},
{event: 'label', name: 'Member labels'}, {targets: 'label,member', name: 'Members'},
{event: 'user', name: 'Users'}, {targets: 'offer,product', name: 'Tiers & offers'},
{event: 'setting', name: 'Settings'}, {targets: 'api_key,integration,setting,user,webhook', name: 'Settings & users'}
{event: 'integration', name: 'Integrations'},
{event: 'api_key', name: 'API keys'},
{event: 'webhook', name: 'Webhooks'}
]; ];
export default class AuditLogEventFilter extends Component { export default class AuditLogEventFilter extends Component {
@ -34,12 +31,12 @@ export default class AuditLogEventFilter extends Component {
} }
get resourceTypes() { get resourceTypes() {
const excludedEvents = (this.args.excludedResources || '').split(','); const excludedResources = (this.args.excludedResources || '').split(',');
return ALL_RESOURCE_TYPES.map(type => ({ return ALL_RESOURCE_TYPES.map(type => ({
event: type.event, targets: type.targets,
name: type.name, name: type.name,
isSelected: !excludedEvents.includes(type.event) isSelected: !type.targets.split(',').every(t => excludedResources.includes(t))
})); }));
} }
@ -62,12 +59,15 @@ export default class AuditLogEventFilter extends Component {
@action @action
toggleResourceType(resourceType) { toggleResourceType(resourceType) {
const excludedResources = new Set(this.resourceTypes.reject(type => type.isSelected).map(type => type.event)); const resourceTypeElements = resourceType.split(',');
const excludedResources = new Set(this.resourceTypes.reject(type => type.isSelected).flatMap(type => type.targets.split(',')));
if (excludedResources.has(resourceType)) { for (const resource of resourceTypeElements) {
excludedResources.delete(resourceType); if (excludedResources.has(resource)) {
} else { excludedResources.delete(resource);
excludedResources.add(resourceType); } else {
excludedResources.add(resource);
}
} }
this.excludedResources = Array.from(excludedResources).join(','); this.excludedResources = Array.from(excludedResources).join(',');

View file

@ -26,7 +26,7 @@ export default class AuditLogEventFilter extends Helper {
filterParts.push(`event:-[${excludedEventsArray.join(',')}]`); filterParts.push(`event:-[${excludedEventsArray.join(',')}]`);
} }
const IGNORED_RESOURCES = ['offer', 'product']; const IGNORED_RESOURCES = [];
const excludedResourcesArray = Array.from(excludedResourcesSet).concat(IGNORED_RESOURCES).reject(isBlank); const excludedResourcesArray = Array.from(excludedResourcesSet).concat(IGNORED_RESOURCES).reject(isBlank);
if (excludedResourcesArray.length > 0) { if (excludedResourcesArray.length > 0) {
filterParts.push(`resource_type:-[${excludedResourcesArray.join(',')}]`); filterParts.push(`resource_type:-[${excludedResourcesArray.join(',')}]`);