Skip to content

Commit 21da9ee

Browse files
WIP: preserving team code selection after replace
2 parents 1e01ba1 + 392fb2b commit 21da9ee

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/components/WeeklySummariesReport/WeeklySummariesReport.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ const WeeklySummariesReport = props => {
308308
teamCodes,
309309
teamCodeWarningUsers: summariesCopy.filter(s => s.teamCodeWarning),
310310
tabsLoading: { ...prevState.tabsLoading, [activeTab]: false },
311+
selectedCodes: [],
311312
}));
312313

313314
// 🔐 Now load info collections
@@ -688,7 +689,7 @@ const WeeklySummariesReport = props => {
688689
const handleSelectCodeChange = event => {
689690
setState(prev => {
690691
const selectedValues = event.map(e => e.value);
691-
// Move selected codes to the front of the dropdown list
692+
// Move selected codes to the front of the dropdown list // newly added
692693
const reorderedTeamCodes = [
693694
...prev.teamCodes.filter(code => selectedValues.includes(code.value)), // selected first
694695
...prev.teamCodes.filter(code => !selectedValues.includes(code.value)), // then the rest
@@ -872,6 +873,11 @@ const WeeklySummariesReport = props => {
872873
_ids: updatedSummaries.filter(s => s.teamCode === replaceCode).map(s => s._id),
873874
});
874875

876+
const reorderedTeamCodes = [
877+
updatedSelectedCodes[0], // the newly replaced code on top
878+
...updatedTeamCodes.filter(tc => tc.value !== updatedSelectedCodes[0].value),
879+
];
880+
875881
const updatedWarningUsers = [...teamCodeWarningUsers];
876882
updatedUsers.forEach(({ userId, teamCodeWarning }) => {
877883
const existingIndex = updatedWarningUsers.findIndex(user => user._id === userId);
@@ -894,7 +900,9 @@ const WeeklySummariesReport = props => {
894900
setState(prev => ({
895901
...prev,
896902
summaries: updatedSummaries,
897-
teamCodes: updatedTeamCodes,
903+
// teamCodes: updatedTeamCodes,
904+
teamCodes: reorderedTeamCodes,
905+
// selectedCodes: [],
898906
selectedCodes: updatedSelectedCodes,
899907
replaceCode: '',
900908
replaceCodeError: null,

0 commit comments

Comments
 (0)