-
-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update project overview endpoint (#5518)
1. Created new hook for endpoint 2. Start removing useProject hook, when features not needed.
- Loading branch information
Showing
10 changed files
with
172 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
frontend/src/hooks/api/getters/useProjectOverview/getProjectOverviewFetcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { formatApiPath } from 'utils/formatPath'; | ||
import handleErrorResponses from '../httpErrorResponseHandler'; | ||
|
||
export const getProjectOverviewFetcher = (id: string) => { | ||
const fetcher = () => { | ||
const path = formatApiPath(`api/admin/projects/${id}/overview`); | ||
return fetch(path, { | ||
method: 'GET', | ||
}) | ||
.then(handleErrorResponses('Project overview')) | ||
.then((res) => res.json()); | ||
}; | ||
|
||
const KEY = `api/admin/projects/${id}/overview`; | ||
|
||
return { | ||
fetcher, | ||
KEY, | ||
}; | ||
}; |
53 changes: 53 additions & 0 deletions
53
frontend/src/hooks/api/getters/useProjectOverview/useProjectOverview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import useSWR, { SWRConfiguration } from 'swr'; | ||
import { useCallback } from 'react'; | ||
import { getProjectOverviewFetcher } from './getProjectOverviewFetcher'; | ||
import { IProjectOverview } from 'interfaces/project'; | ||
|
||
const fallbackProject: IProjectOverview = { | ||
featureTypeCounts: [], | ||
environments: [], | ||
name: '', | ||
health: 0, | ||
members: 0, | ||
version: '1', | ||
description: 'Default', | ||
favorite: false, | ||
mode: 'open', | ||
defaultStickiness: 'default', | ||
stats: { | ||
archivedCurrentWindow: 0, | ||
archivedPastWindow: 0, | ||
avgTimeToProdCurrentWindow: 0, | ||
createdCurrentWindow: 0, | ||
createdPastWindow: 0, | ||
projectActivityCurrentWindow: 0, | ||
projectActivityPastWindow: 0, | ||
projectMembersAddedCurrentWindow: 0, | ||
}, | ||
}; | ||
|
||
const useProjectOverview = (id: string, options: SWRConfiguration = {}) => { | ||
const { KEY, fetcher } = getProjectOverviewFetcher(id); | ||
const { data, error, mutate } = useSWR<IProjectOverview>( | ||
KEY, | ||
fetcher, | ||
options, | ||
); | ||
|
||
const refetch = useCallback(() => { | ||
mutate(); | ||
}, [mutate]); | ||
|
||
return { | ||
project: data || fallbackProject, | ||
loading: !error && !data, | ||
error, | ||
refetch, | ||
}; | ||
}; | ||
|
||
export const useProjectOverviewNameOrId = (id: string): string => { | ||
return useProjectOverview(id).project.name || id; | ||
}; | ||
|
||
export default useProjectOverview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters