-
Notifications
You must be signed in to change notification settings - Fork 2
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
draft: hiding filters showing no results (not working) #1403
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,11 @@ export const filterDialogs = ( | |
}); | ||
}; | ||
|
||
export const getFilterBarSettings = (dialogs: InboxItemInput[], format: FormatFunction): FilterSetting[] => { | ||
export const getFilterBarSettings = ( | ||
dialogs: InboxItemInput[], | ||
filteredDialogs: InboxItemInput[], | ||
format: FormatFunction, | ||
): FilterSetting[] => { | ||
Comment on lines
+77
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using only filteredDialogs for consistency The function now takes both export const getFilterBarSettings = (
- dialogs: InboxItemInput[],
filteredDialogs: InboxItemInput[],
format: FormatFunction,
): FilterSetting[] => {
|
||
return [ | ||
{ | ||
id: 'sender', | ||
|
@@ -85,7 +89,11 @@ export const getFilterBarSettings = (dialogs: InboxItemInput[], format: FormatFu | |
options: (() => { | ||
const senders = dialogs.map((p) => p.sender.name); | ||
const senderCounts = countOccurrences(senders); | ||
return Array.from(new Set(senders)).map((sender) => ({ | ||
|
||
const validSenders = filteredDialogs.map((p) => p.sender.name); | ||
const uniqueSenders = Array.from(new Set(validSenders)); | ||
|
||
return uniqueSenders.map((sender) => ({ | ||
displayLabel: `${t('filter_bar_fields.from')} ${sender}`, | ||
value: sender, | ||
count: senderCounts[sender], | ||
|
@@ -101,7 +109,11 @@ export const getFilterBarSettings = (dialogs: InboxItemInput[], format: FormatFu | |
options: (() => { | ||
const receivers = dialogs.map((p) => p.receiver.name); | ||
const receiversCount = countOccurrences(receivers); | ||
return Array.from(new Set(receivers)).map((receiver) => ({ | ||
|
||
const validReceivers = filteredDialogs.map((p) => p.receiver.name); | ||
const uniqueReceivers = Array.from(new Set(validReceivers)); | ||
|
||
return uniqueReceivers.map((receiver) => ({ | ||
Comment on lines
+112
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix inconsistent receiver counts and reduce code duplication
First, fix the counting: -const receivers = dialogs.map((p) => p.receiver.name);
+const receivers = filteredDialogs.map((p) => p.receiver.name);
const receiversCount = countOccurrences(receivers); Then, consider extracting a helper function to reduce duplication: const getParticipantOptions = (
dialogs: InboxItemInput[],
participantType: 'sender' | 'receiver',
labelPrefix: string
) => {
const participants = dialogs.map((p) => p[participantType].name);
const counts = countOccurrences(participants);
const unique = Array.from(new Set(participants));
return unique.map((name) => ({
displayLabel: `${t(labelPrefix)} ${name}`,
value: name,
count: counts[name],
}));
}; |
||
displayLabel: `${t('filter_bar_fields.to')} ${receiver}`, | ||
value: receiver, | ||
count: receiversCount[receiver], | ||
|
@@ -116,12 +128,16 @@ export const getFilterBarSettings = (dialogs: InboxItemInput[], format: FormatFu | |
operation: 'includes', | ||
horizontalRule: true, | ||
options: (() => { | ||
const status = dialogs.map((p) => p.status); | ||
const statusCount = countOccurrences(status); | ||
return Array.from(new Set(status)).map((statusLabel) => ({ | ||
const statuses = dialogs.map((p) => p.status); | ||
const statusCounts = countOccurrences(statuses); | ||
|
||
const validStatuses = filteredDialogs.map((p) => p.status); | ||
const uniqueStatuses = Array.from(new Set(validStatuses)); | ||
|
||
return uniqueStatuses.map((statusLabel) => ({ | ||
displayLabel: t(`status.${statusLabel.toLowerCase()}`), | ||
value: statusLabel, | ||
count: statusCount[statusLabel], | ||
count: statusCounts[statusLabel], | ||
Comment on lines
+131
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Based on the results from our verification attempts, I can generate the final response: Fix status counts and verify translation key case handling The status counts issue needs to be fixed as proposed in the diff, but regarding the translation keys, we found evidence in the translation files (nb.json and en.json) that the lowercase status keys are correct. The translation files contain entries like "status.completed", "status.draft", etc., which match the lowercase transformation in the code.
🔗 Analysis chainFix status counts and verify translation key case handling
-const statuses = dialogs.map((p) => p.status);
+const statuses = filteredDialogs.map((p) => p.status);
const statusCounts = countOccurrences(statuses); Let's verify the translation keys: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check if translation keys exist in lowercase
rg -l "status\.: \{" . | xargs rg "status\.[A-Z]+" -A 1
Length of output: 57 Script: #!/bin/bash
# Let's try a different approach to find translation files and keys
fd -e json -e yaml -e yml | xargs rg "status\." -B 1 -A 1
# Also search for translation related files
fd "i18n|translation|locale" --type f
# Look for actual status values in the code
rg "status: ['\"](.*?)['\"]" --type ts
Length of output: 4105 Script: #!/bin/bash
# Let's find the actual status values used in the dialogs
rg "status: ['\"]" packages/frontend/src/pages/Inbox -B 2 -A 2
# Also check how these status values are used in the code
ast-grep --pattern 'status.$_'
Length of output: 99 Script: #!/bin/bash
# Let's try to find the Dialog type definition to see status values
rg "type.*Dialog.*status" --type ts -A 5
# And check for enum definitions related to status
rg "enum.*Status" --type ts -A 10
# Also look for actual status assignments in the Inbox directory
rg "\.status\s*(=|:)" packages/frontend/src/pages/Inbox
Length of output: 136 |
||
})); | ||
})(), | ||
}, | ||
|
@@ -132,7 +148,7 @@ export const getFilterBarSettings = (dialogs: InboxItemInput[], format: FormatFu | |
unSelectedLabel: t('filter_bar.label.all_dates'), | ||
operation: 'equals', | ||
options: generateDateOptions( | ||
dialogs.map((p) => new Date(p.updatedAt)), | ||
filteredDialogs.map((p) => new Date(p.updatedAt)), | ||
format, | ||
), | ||
}, | ||
|
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.
🛠️ Refactor suggestion
Remove duplicate memoized variable
The
filteredDialogs
variable duplicates the exact same logic asitemsToDisplay
defined above. This creates unnecessary memory overhead and complexity.Remove this duplicate and use the existing
itemsToDisplay
variable instead: