This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show archived toggles on a project level (#942)
* feat: show archived toggles on a project level * Update src/component/feature/FeatureToggleList/FeatureToggleListActions/FeatureToggleListActions.tsx Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com> * refactor: adapt code to PR comments, clarity Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
- Loading branch information
1 parent
0eb2ba9
commit 08ed45f
Showing
20 changed files
with
202 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { FC } from 'react'; | ||
import { useProjectFeaturesArchive } from 'hooks/api/getters/useProjectFeaturesArchive/useProjectFeaturesArchive'; | ||
import { FeatureToggleList } from '../feature/FeatureToggleList/FeatureToggleList'; | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
import { useFeaturesFilter } from 'hooks/useFeaturesFilter'; | ||
import { useFeatureArchiveApi } from 'hooks/api/actions/useFeatureArchiveApi/useReviveFeatureApi'; | ||
import useToast from 'hooks/useToast'; | ||
import { useFeaturesSort } from 'hooks/useFeaturesSort'; | ||
|
||
interface IProjectFeaturesArchiveList { | ||
projectId: string; | ||
} | ||
|
||
export const ProjectFeaturesArchiveList: FC<IProjectFeaturesArchiveList> = ({ | ||
projectId, | ||
}) => { | ||
const { setToastData, setToastApiError } = useToast(); | ||
const { uiConfig } = useUiConfig(); | ||
const { reviveFeature } = useFeatureArchiveApi(); | ||
|
||
const { | ||
archivedFeatures = [], | ||
refetchArchived, | ||
loading, | ||
} = useProjectFeaturesArchive(projectId); | ||
|
||
const { filtered, filter, setFilter } = useFeaturesFilter(archivedFeatures); | ||
const { sorted, sort, setSort } = useFeaturesSort(filtered); | ||
|
||
const onRevive = (feature: string) => { | ||
reviveFeature(feature) | ||
.then(refetchArchived) | ||
.then(() => | ||
setToastData({ | ||
type: 'success', | ||
title: "And we're back!", | ||
text: 'The feature toggle has been revived.', | ||
confetti: true, | ||
}) | ||
) | ||
.catch(e => setToastApiError(e.toString())); | ||
}; | ||
|
||
return ( | ||
<FeatureToggleList | ||
features={sorted} | ||
loading={loading} | ||
onRevive={onRevive} | ||
flags={uiConfig.flags} | ||
filter={filter} | ||
setFilter={setFilter} | ||
sort={sort} | ||
setSort={setSort} | ||
isArchive | ||
inProject={Boolean(projectId)} | ||
/> | ||
); | ||
}; |
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
14 changes: 14 additions & 0 deletions
14
src/component/project/Project/ProjectFeaturesArchive/ProjectFeaturesArchive.tsx
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,14 @@ | ||
import { ProjectFeaturesArchiveList } from 'component/archive/ProjectFeaturesArchiveList'; | ||
import { usePageTitle } from 'hooks/usePageTitle'; | ||
|
||
interface IProjectFeaturesArchiveProps { | ||
projectId: string; | ||
} | ||
|
||
export const ProjectFeaturesArchive = ({ | ||
projectId, | ||
}: IProjectFeaturesArchiveProps) => { | ||
usePageTitle('Project Archived Features'); | ||
|
||
return <ProjectFeaturesArchiveList projectId={projectId} />; | ||
}; |
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
33 changes: 33 additions & 0 deletions
33
src/hooks/api/getters/useProjectFeaturesArchive/useProjectFeaturesArchive.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,33 @@ | ||
import { openApiAdmin } from 'utils/openapiClient'; | ||
import { FeatureSchema } from 'openapi'; | ||
import { useApiGetter } from 'hooks/api/getters/useApiGetter/useApiGetter'; | ||
|
||
export interface IUseProjectFeaturesArchiveOutput { | ||
archivedFeatures?: FeatureSchema[]; | ||
refetchArchived: () => void; | ||
loading: boolean; | ||
error?: Error; | ||
} | ||
|
||
export const useProjectFeaturesArchive = ( | ||
projectId: string | ||
): IUseProjectFeaturesArchiveOutput => { | ||
const { data, refetch, loading, error } = useApiGetter( | ||
['apiAdminArchiveFeaturesGet', projectId], | ||
() => { | ||
if (projectId) { | ||
return openApiAdmin.apiAdminArchiveFeaturesProjectIdGet({ | ||
projectId, | ||
}); | ||
} | ||
return openApiAdmin.apiAdminArchiveFeaturesGet(); | ||
} | ||
); | ||
|
||
return { | ||
archivedFeatures: data?.features, | ||
refetchArchived: refetch, | ||
loading, | ||
error, | ||
}; | ||
}; |
Oops, something went wrong.