-
Notifications
You must be signed in to change notification settings - Fork 58
Feature: Add recent filters drop-down to the message browser #279
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
base: main
Are you sure you want to change the base?
Changes from all commits
585be55
68ebccf
b1cefe0
15954f7
c360924
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: 2025 Mitch Gaffigan | ||
|
|
||
| package com.mirth.connect.client.ui.browsers.message; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| import com.mirth.connect.model.converters.ObjectXMLSerializer; | ||
| import com.mirth.connect.model.filters.MessageFilter; | ||
|
|
||
| class MessageBrowserRecentFilterStore { | ||
| private static final int MAX_RECENT_FILTERS = 10; | ||
| private static final String RECENT_FILTERS_PREFERENCE_PREFIX = "messageBrowserRecentFilters."; | ||
| // TODO: Replace with a cross-session time-limited encrypted store | ||
| // (In-memory assuming text searches represent PHI) | ||
| private static final Map<String, String> RECENT_FILTERS_BY_CHANNEL = new ConcurrentHashMap<>(); | ||
| private Logger logger = LogManager.getLogger(this.getClass()); | ||
|
|
||
| private final String prefKey; | ||
|
|
||
| public MessageBrowserRecentFilterStore(String channelId) { | ||
| this.prefKey = RECENT_FILTERS_PREFERENCE_PREFIX + channelId; | ||
| } | ||
|
|
||
| public List<MessageFilter> getRecentFilters() { | ||
| try { | ||
| String serialized = RECENT_FILTERS_BY_CHANNEL.getOrDefault(prefKey, ""); | ||
| if (serialized.isBlank()) return List.of(); | ||
|
|
||
| var result = ObjectXMLSerializer.getInstance().deserializeList(serialized, MessageFilter.class); | ||
| if (result == null) return List.of(); | ||
|
|
||
| return result; | ||
| } catch (Exception e) { | ||
| // Fail quietly if the stored filters cannot be deserialized for any reason. | ||
| logger.warn("Failed to deserialize recent message filters for key {}.", prefKey, e); | ||
| return List.of(); | ||
|
Comment on lines
+31
to
+43
|
||
| } | ||
| } | ||
|
|
||
| public void addRecentFilter(MessageFilter filter) { | ||
| if (filter == null) { | ||
| throw new IllegalArgumentException("Filter cannot be null"); | ||
| } | ||
|
|
||
| var filters = new ArrayList<>(getRecentFilters()); | ||
|
|
||
| // Remove then re-add to avoid duplicates | ||
| filters.remove(filter); | ||
| filters.add(0, filter); | ||
|
|
||
| // Trim to the maximum number of recent filters | ||
| if (filters.size() > MAX_RECENT_FILTERS) { | ||
| filters.subList(MAX_RECENT_FILTERS, filters.size()).clear(); | ||
| } | ||
|
jonbartels marked this conversation as resolved.
|
||
|
|
||
| try { | ||
| RECENT_FILTERS_BY_CHANNEL.put(prefKey, ObjectXMLSerializer.getInstance().serialize(filters)); | ||
| } catch (Exception e) { | ||
| logger.warn("Failed to serialize recent message filters for key {}.", prefKey, e); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max should be configurable in
mirth.propertiesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we take a feature issue on this? It seems useful even with the MRU size hard coded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. How about a broad feature issue that finds hardcoded constants or limits in the Client and makes them configurable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a big to me, but maybe with sub-issues for each constant, sure. The issues I had in mind were:
MAX_RECENT_FILTERSa user preference