-
Notifications
You must be signed in to change notification settings - Fork 29
Some Timetracking view improvements #8170
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
Changes from 6 commits
3728f25
08e83b5
d2b73cd
d5821e6
f530d00
07cc3d3
5496895
c1d6301
3419184
a92f6c5
1bbb675
939fd16
a958867
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 |
---|---|---|
|
@@ -13,11 +13,19 @@ export enum AnnotationTypeFilterEnum { | |
TASKS_AND_ANNOTATIONS_KEY = "Task,Explorational", | ||
} | ||
|
||
export enum AnnotationStateFilterEnum { | ||
ALL = "All", | ||
ACTIVE = "Active", | ||
FINISHED_OR_ARCHIVED = "Finished", | ||
} | ||
type ProjectAndTypeDropdownProps = { | ||
selectedProjectIds: string[]; | ||
setSelectedProjectIds: (projectIds: string[]) => void; | ||
selectedAnnotationType: AnnotationTypeFilterEnum; | ||
setSelectedAnnotationType: (type: AnnotationTypeFilterEnum) => void; | ||
selectedAnnotationState: string; | ||
setSelectedAnnotationState: (state: AnnotationStateFilterEnum) => void; | ||
|
||
style?: React.CSSProperties; | ||
}; | ||
|
||
|
@@ -38,11 +46,21 @@ const ANNOTATION_TYPE_FILTERS: NestedSelectOptions = { | |
], | ||
}; | ||
|
||
const ANNOTATION_STATE_FILTERS: NestedSelectOptions = { | ||
label: "Filter by state", | ||
options: [ | ||
{ label: "Active", value: AnnotationStateFilterEnum.ACTIVE }, | ||
{ label: "Finished / Archived", value: AnnotationStateFilterEnum.FINISHED_OR_ARCHIVED }, | ||
], | ||
}; | ||
|
||
function ProjectAndAnnotationTypeDropdown({ | ||
selectedProjectIds, | ||
setSelectedProjectIds, | ||
selectedAnnotationType, | ||
setSelectedAnnotationType, | ||
selectedAnnotationState, | ||
setSelectedAnnotationState, | ||
style, | ||
}: ProjectAndTypeDropdownProps) { | ||
// This state property is derived from selectedProjectIds and selectedAnnotationType. | ||
|
@@ -60,12 +78,14 @@ function ProjectAndAnnotationTypeDropdown({ | |
); | ||
|
||
useEffect(() => { | ||
const selectedKeys = | ||
selectedAnnotationState !== AnnotationStateFilterEnum.ALL ? [selectedAnnotationState] : []; | ||
if (selectedProjectIds.length > 0) { | ||
setSelectedFilters(selectedProjectIds); | ||
setSelectedFilters([...selectedProjectIds, ...selectedKeys]); | ||
} else { | ||
setSelectedFilters([selectedAnnotationType]); | ||
setSelectedFilters([selectedAnnotationType, ...selectedKeys]); | ||
} | ||
}, [selectedProjectIds, selectedAnnotationType]); | ||
}, [selectedProjectIds, selectedAnnotationType, selectedAnnotationState]); | ||
|
||
useEffect(() => { | ||
const projectOptions = allProjects.map((project) => { | ||
|
@@ -74,14 +94,18 @@ function ProjectAndAnnotationTypeDropdown({ | |
value: project.id, | ||
}; | ||
}); | ||
let allOptions = [ANNOTATION_TYPE_FILTERS]; | ||
let allOptions = [ANNOTATION_TYPE_FILTERS, ANNOTATION_STATE_FILTERS]; | ||
if (projectOptions.length > 0) { | ||
allOptions.push({ label: "Filter projects (only tasks)", options: projectOptions }); | ||
} | ||
setFilterOptions(allOptions); | ||
}, [allProjects]); | ||
|
||
const setSelectedProjects = async (_prevSelection: string[], selectedValue: string) => { | ||
if (Object.values<string>(AnnotationStateFilterEnum).includes(selectedValue)) { | ||
setSelectedAnnotationState(selectedValue as AnnotationStateFilterEnum); | ||
return; | ||
} | ||
if (Object.values<string>(AnnotationTypeFilterEnum).includes(selectedValue)) { | ||
setSelectedAnnotationType(selectedValue as AnnotationTypeFilterEnum); | ||
setSelectedProjectIds([]); | ||
|
@@ -94,6 +118,8 @@ function ProjectAndAnnotationTypeDropdown({ | |
const onDeselect = (removedKey: string) => { | ||
if (Object.values<string>(AnnotationTypeFilterEnum).includes(removedKey)) { | ||
setSelectedAnnotationType(AnnotationTypeFilterEnum.TASKS_AND_ANNOTATIONS_KEY); | ||
} else if (Object.values<string>(AnnotationStateFilterEnum).includes(removedKey)) { | ||
setSelectedAnnotationState(AnnotationStateFilterEnum.ALL); | ||
} else { | ||
setSelectedProjectIds(selectedProjectIds.filter((projectId) => projectId !== removedKey)); | ||
} | ||
|
@@ -108,6 +134,7 @@ function ProjectAndAnnotationTypeDropdown({ | |
options={filterOptions} | ||
optionFilterProp="label" | ||
value={selectedFilters} | ||
popupMatchSelectWidth={false} | ||
|
||
onDeselect={(removedKey: string) => onDeselect(removedKey)} | ||
onSelect={(newSelection: string) => setSelectedProjects(selectedFilters, newSelection)} | ||
/> | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Remove duplicate annotationStates parameter.
There is a critical issue where the annotationStates parameter is being set twice:
This could lead to unexpected behavior as the second append will add a duplicate parameter to the URL.
if (selectedState !== AnnotationStateFilterEnum.ALL) { params.append("annotationStates", selectedState); } else { params.append("annotationStates", "Active,Finished"); } // Omit empty parameters in request if (projectIds.length > 0) params.append("projectIds", projectIds.join(",")); if (teamIds.length > 0) params.append("teamIds", teamIds.join(",")); - params.append("annotationStates", "Active,Finished"); return await Request.receiveJSON(`api/time/overview?${params}`);
Also applies to: 1793-1793
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.
nice, thanks for saving me here 🙏
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.
@MichaelBuessemeyer, glad I could help!
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!