import 'package:invoiceninja_flutter/data/models/webhook_model.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:memoize/memoize.dart'; import 'package:built_collection/built_collection.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart'; var memoizedDropdownWebhookList = memo3( (BuiltMap webhookMap, BuiltList webhookList, String clientId) => dropdownWebhooksSelector(webhookMap, webhookList, clientId)); List dropdownWebhooksSelector( BuiltMap webhookMap, BuiltList webhookList, String clientId) { final list = webhookList.where((webhookId) { final webhook = webhookMap[webhookId]; /* if (clientId != null && clientId > 0 && webhook.clientId != clientId) { return false; } */ return webhook.isActive; }).toList(); list.sort((webhookAId, webhookBId) { final webhookA = webhookMap[webhookAId]; final webhookB = webhookMap[webhookBId]; return webhookA.compareTo(webhookB, WebhookFields.targetUrl, true); }); return list; } var memoizedFilteredWebhookList = memo4(( SelectionState selectionState, BuiltMap webhookMap, BuiltList webhookList, ListUIState webhookListState, ) => filteredWebhooksSelector( selectionState, webhookMap, webhookList, webhookListState, )); List filteredWebhooksSelector( SelectionState selectionState, BuiltMap webhookMap, BuiltList webhookList, ListUIState webhookListState, ) { final filterEntityId = selectionState.filterEntityId; final filterEntityType = selectionState.filterEntityType; final list = webhookList.where((webhookId) { final webhook = webhookMap[webhookId]; if (filterEntityId != null && webhook.id != filterEntityId) { return false; } else {} if (webhook.id == selectionState.selectedId) { return true; } if (!webhook.matchesStates(webhookListState.stateFilters)) { return false; } return webhook.matchesFilter(webhookListState.filter); }).toList(); list.sort((webhookAId, webhookBId) { final webhookA = webhookMap[webhookAId]; final webhookB = webhookMap[webhookBId]; return webhookA.compareTo( webhookB, webhookListState.sortField, webhookListState.sortAscending); }); return list; } bool hasWebhookChanges( WebhookEntity webhook, BuiltMap webhookMap) => webhook.isNew ? webhook.isChanged : webhook != webhookMap[webhook.id];