-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add projects select to analytics page gf-348 #470
Changes from 7 commits
a9057c7
ffcb2aa
99f9e4d
28f1f79
2c248dc
fed6b54
18080e5
c0d6074
f591dff
710a066
94e6f79
19df425
4803f13
6bfb4f4
1cea696
4a8cef3
99b9a0f
e7e231b
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 |
---|---|---|
|
@@ -120,7 +120,7 @@ class ProjectService implements Service { | |
} | ||
|
||
public async findAll( | ||
parameters: ProjectGetAllRequestDto, | ||
parameters: object | ProjectGetAllRequestDto, | ||
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. same |
||
): Promise<ProjectGetAllResponseDto> { | ||
const { items, totalItems } = | ||
await this.projectRepository.findAll(parameters); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -66,10 +66,10 @@ const { actions, name, reducer } = createSlice({ | |||||
}); | ||||||
builder.addCase(loadAll.fulfilled, (state, action) => { | ||||||
const { items, totalItems } = action.payload; | ||||||
const { page } = action.meta.arg; | ||||||
|
||||||
state.projects = | ||||||
const page = action.meta.arg?.page; | ||||||
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.
Suggested change
|
||||||
const projectsItems = | ||||||
page === FIRST_PAGE ? items : [...state.projects, ...items]; | ||||||
state.projects = page ? projectsItems : items; | ||||||
state.projectsTotalCount = totalItems; | ||||||
state.dataStatus = DataStatus.FULFILLED; | ||||||
}); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import { DateInput, Loader, PageLayout } from "~/libs/components/components.js"; | ||
import { | ||
DateInput, | ||
Loader, | ||
PageLayout, | ||
Select, | ||
} from "~/libs/components/components.js"; | ||
import { DataStatus } from "~/libs/enums/enums.js"; | ||
import { subtractDays } from "~/libs/helpers/helpers.js"; | ||
import { | ||
|
@@ -10,9 +15,11 @@ import { | |
useFormWatch, | ||
} from "~/libs/hooks/hooks.js"; | ||
import { actions as activityLogActions } from "~/modules/activity/activity.js"; | ||
import { actions as projectActions } from "~/modules/projects/projects.js"; | ||
|
||
import { AnalyticsTable } from "./libs/components/components.js"; | ||
import { ANALYTICS_DATE_MAX_RANGE } from "./libs/constants/constants.js"; | ||
import { getProjectOptions } from "./libs/helpers/helpers.js"; | ||
import styles from "./styles.module.css"; | ||
|
||
const Analytics = (): JSX.Element => { | ||
|
@@ -22,26 +29,34 @@ const Analytics = (): JSX.Element => { | |
const { activityLogs, dataStatus } = useAppSelector( | ||
({ activityLogs }) => activityLogs, | ||
); | ||
const { projects } = useAppSelector(({ projects }) => projects); | ||
|
||
useEffect(() => { | ||
void dispatch(projectActions.loadAll()); | ||
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. We need to load these projects separately, specifically for analytics module, so it should be in analytics slice. Also on the backend side we need to split service method for pagination and without and the same for repository. Take a look at how it's done here #491 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. Did I understand correctly that I can make a separate request on the backend in order to get all the projects (without pagination)? And use it in the analytics slice? I thought it would be better that way, I asked, but I didn't get an answer then 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. Yes, let's make it as a separate request and keep it separately 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. probably missed your question in the chat 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. Everything is fine, I hope it is correct now |
||
}, [dispatch]); | ||
|
||
const { control, handleSubmit, isDirty } = useAppForm({ | ||
defaultValues: { | ||
dateRange: [ | ||
subtractDays(todayDate, ANALYTICS_DATE_MAX_RANGE), | ||
todayDate, | ||
] as [Date, Date], | ||
project: null, | ||
}, | ||
}); | ||
|
||
const dateRangeValue = useFormWatch({ control, name: "dateRange" }); | ||
const projectValue = useFormWatch({ control, name: "project" }); | ||
|
||
const handleLoadLogs = useCallback( | ||
([startDate, endDate]: [Date, Date]) => { | ||
([startDate, endDate]: [Date, Date], projectId?: null | number) => { | ||
const formattedStartDate = startDate.toISOString(); | ||
const formattedEndDate = endDate.toISOString(); | ||
|
||
void dispatch( | ||
activityLogActions.loadAll({ | ||
endDate: formattedEndDate, | ||
projectId: projectId ?? undefined, | ||
startDate: formattedStartDate, | ||
}), | ||
); | ||
|
@@ -50,23 +65,25 @@ const Analytics = (): JSX.Element => { | |
); | ||
|
||
useEffect(() => { | ||
handleLoadLogs(dateRangeValue); | ||
}, [dateRangeValue, handleLoadLogs]); | ||
handleLoadLogs(dateRangeValue, projectValue); | ||
}, [dateRangeValue, projectValue, handleLoadLogs]); | ||
|
||
const handleFormSubmit = useCallback( | ||
(event_?: React.BaseSyntheticEvent): void => { | ||
void handleSubmit((formData) => { | ||
handleLoadLogs(formData.dateRange); | ||
handleLoadLogs(formData.dateRange, formData.project); | ||
})(event_); | ||
}, | ||
[handleLoadLogs, handleSubmit], | ||
); | ||
|
||
const projectOptions = getProjectOptions(projects); | ||
|
||
useEffect(() => { | ||
if (isDirty) { | ||
handleFormSubmit(); | ||
} | ||
}, [dateRangeValue, isDirty, handleFormSubmit]); | ||
}, [dateRangeValue, projectValue, isDirty, handleFormSubmit]); | ||
|
||
const isLoading = | ||
dataStatus === DataStatus.IDLE || dataStatus === DataStatus.PENDING; | ||
|
@@ -76,6 +93,18 @@ const Analytics = (): JSX.Element => { | |
<h1 className={styles["title"]}>Analytics</h1> | ||
<section> | ||
<form className={styles["filters-form"]} onSubmit={handleFormSubmit}> | ||
<div className={styles["wraper-selector"]}> | ||
GvoFor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Select | ||
control={control} | ||
isClearable | ||
isLabelHidden | ||
isSearchable | ||
label="Select project" | ||
name="project" | ||
options={projectOptions} | ||
placeholder="Select project" | ||
/> | ||
</div> | ||
<DateInput | ||
control={control} | ||
maxDate={todayDate} | ||
|
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. Place helpers in their separate folders |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type SelectOption } from "~/libs/types/select-option.type.js"; | ||
import { type ProjectGetAllItemResponseDto } from "~/modules/projects/projects.js"; | ||
|
||
const getProjectOptions = ( | ||
projects: ProjectGetAllItemResponseDto[], | ||
): SelectOption<number>[] => | ||
projects.map((project) => ({ | ||
label: project.name, | ||
value: project.id, | ||
})); | ||
|
||
export { getProjectOptions }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { getAnalyticsColumns } from "./get-analytics-columns/get-analytics-columns.helper.jsx"; | ||
export { getAnalyticsRows } from "./get-analytics-rows/get-analytics-rows.helper.js"; | ||
export { getProjectOptions } from "./get-project-options.helper.js"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
type ActivityLogQueryParameters = { | ||
endDate: string; | ||
projectId?: number | undefined; | ||
startDate: string; | ||
}; | ||
|
||
|
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.
specify type