([]);
const isLoadingConnections = ref(false);
const isLoadingTags = ref(false);
-// Simulate data for itemsToSend for development if not provided
+const expandedTagGroups = ref>({});
+
+const getGroupId = (group: GroupedConnection): string => {
+ return group.tag ? String(group.tag.id) : 'untagged';
+};
+
+const toggleTagGroupExpansion = (group: GroupedConnection) => {
+ const groupId = getGroupId(group);
+ // If state is undefined, default to true (expanded), then toggle it.
+ // So, if undefined, it becomes !(true) = false. If defined, it's just toggled.
+ // To make it default to expanded and then collapse on first click:
+ // expandedTagGroups.value[groupId] = !(expandedTagGroups.value[groupId] ?? true);
+ // To make it default to collapsed and then expand on first click (if true means expanded):
+ expandedTagGroups.value[groupId] = !(expandedTagGroups.value[groupId] ?? true);
+ };
+
+ // Simulate data for itemsToSend for development if not provided
const itemsToSendInternal = computed(() => {
if (props.itemsToSend && props.itemsToSend.length > 0) {
return props.itemsToSend;
@@ -269,19 +297,38 @@ const groupedConnections = computed(() => {
});
const filteredGroupedConnections = computed(() => {
+ const baseGroups = groupedConnections.value;
+
if (!searchTerm.value.trim()) {
- return groupedConnections.value;
+ // If no search term, filter out groups that initially have no connections.
+ return baseGroups.filter(group => group.connections.length > 0);
}
+
const lowerSearchTerm = searchTerm.value.toLowerCase();
- return groupedConnections.value
+
+ const result = baseGroups
.map(group => {
- const filteredConns = group.connections.filter(conn =>
- conn.type?.toLowerCase() === 'ssh' && // 只包括 SSH 连接
+ const groupDisplayName = group.tag ? group.tag.name : t('sendFilesModal.untaggedConnections');
+ const isTagMatch = groupDisplayName.toLowerCase().includes(lowerSearchTerm);
+
+ const connsMatchingSearchByName = group.connections.filter(conn =>
conn.name.toLowerCase().includes(lowerSearchTerm)
+ // conn.type filtering is already handled in groupedConnections
);
- return { ...group, connections: filteredConns };
+
+ if (isTagMatch) {
+ // Tag name matches. Show all connections of this group.
+ return { ...group, connections: group.connections };
+ } else if (connsMatchingSearchByName.length > 0) {
+ // Tag name doesn't match, but some connection names do. Show only those connections.
+ return { ...group, connections: connsMatchingSearchByName };
+ }
+
+ return null; // Group doesn't match by tag name and has no connections matching by name
})
- .filter(group => group.connections.length > 0); // 只包括仍有连接的分组
+ .filter(group => group !== null && group.connections.length > 0) as GroupedConnection[];
+
+ return result;
});
const isTagGroupSelected = (group: GroupedConnection): boolean => {