Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions frontend/common/lifecycleEnvironmentSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'

type LifecycleEnvironmentState = {
// Maps a project id to the environment id selected for lifecycle analysis.
byProject: Record<number, number>
}

const initialState: LifecycleEnvironmentState = {
byProject: {},
}

const lifecycleEnvironmentSlice = createSlice({
initialState,
name: 'lifecycleEnvironment',
reducers: {
setLifecycleEnvironment(
state,
action: PayloadAction<{ projectId: number; environmentId: number }>,
) {
state.byProject[action.payload.projectId] = action.payload.environmentId
},
},
})

export const { setLifecycleEnvironment } = lifecycleEnvironmentSlice.actions
export default lifecycleEnvironmentSlice.reducer
20 changes: 19 additions & 1 deletion frontend/common/services/useProjectFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ function recursivePageGet(
}
export const projectFlagService = service
.enhanceEndpoints({
addTagTypes: ['ProjectFlag', 'FeatureList', 'FeatureState', 'Environment'],
addTagTypes: [
'ProjectFlag',
'FeatureList',
'FeatureState',
'Environment',
'LifecycleCounts',
],
})
.injectEndpoints({
endpoints: (builder) => ({
Expand Down Expand Up @@ -68,6 +74,7 @@ export const projectFlagService = service
invalidatesTags: [
{ id: 'LIST', type: 'ProjectFlag' },
{ id: 'LIST', type: 'FeatureList' },
'LifecycleCounts',
],
query: (query: Req['createProjectFlag']) => ({
body: query.body,
Expand Down Expand Up @@ -132,6 +139,16 @@ export const projectFlagService = service
}),
}),

getLifecycleStatusCounts: builder.query<
Res['lifecycleStatusCounts'],
Req['getLifecycleStatusCounts']
>({
providesTags: ['LifecycleCounts'],
query: ({ environment }) => ({
url: `environments/${environment}/feature-lifecycle-counts/`,
}),
}),

getProjectFlag: builder.query<Res['projectFlag'], Req['getProjectFlag']>({
providesTags: (res) => [{ id: res?.id, type: 'ProjectFlag' }],
query: (query: Req['getProjectFlag']) => ({
Expand Down Expand Up @@ -284,6 +301,7 @@ export const {
useAddFlagOwnersMutation,
useCreateProjectFlagMutation,
useGetFeatureListQuery,
useGetLifecycleStatusCountsQuery,
useGetProjectFlagQuery,
useGetProjectFlagsQuery,
useRemoveFlagGroupOwnersMutation,
Expand Down
2 changes: 2 additions & 0 deletions frontend/common/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import storage from 'redux-persist/lib/storage'
import { Persistor } from 'redux-persist/es/types'
import { service } from './service'
import selectedOrganisationReducer from './selectedOrganisationSlice'
import lifecycleEnvironmentReducer from './lifecycleEnvironmentSlice'
// END OF IMPORTS
const createStore = () => {
const reducer = combineReducers({
[service.reducerPath]: service.reducer,
lifecycleEnvironment: lifecycleEnvironmentReducer,
selectedOrganisation: selectedOrganisationReducer,
// END OF REDUCERS
})
Expand Down
5 changes: 5 additions & 0 deletions frontend/common/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
FlagsmithValue,
TagStrategy,
FeatureType,
LifecycleStage,
} from './responses'
import { UtmsType } from './utms'

Expand Down Expand Up @@ -395,6 +396,10 @@ export type Req = {
group_owners?: number[]
sort_field?: string
sort_direction?: SortOrder
lifecycle_stage?: LifecycleStage
}
getLifecycleStatusCounts: {
environment: number
}
getProjectFlag: { project: number; id: number }
getRolesPermissionUsers: { organisation_id: number; role_id: number }
Expand Down
12 changes: 12 additions & 0 deletions frontend/common/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,19 @@ export type ProjectFlag = {
last_successful_repository_scanned_at: string
last_feature_found_at: string
}[]
lifecycle_stage?: LifecycleStage | null
}

export type LifecycleStage =
| 'new'
| 'live'
| 'permanent'
| 'stale'
| 'needs_monitoring'
| 'to_remove'

export type LifecycleStatusCounts = Record<LifecycleStage, number>

export type FeatureListProviderData = {
projectFlags: ProjectFlag[] | null
environmentFlags: Record<number, FeatureState> | undefined
Expand Down Expand Up @@ -1344,6 +1355,7 @@ export type Res = {
rolePermission: PagedResponse<RolePermission>
projectFlags: PagedResponse<ProjectFlag>
projectFlag: ProjectFlag
lifecycleStatusCounts: LifecycleStatusCounts
identityFeatureStatesAll: IdentityFeatureState[]
createRolesPermissionUsers: RolePermissionUser
rolesPermissionUsers: PagedResponse<RolePermissionUser>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface ProjectFeatureRowProps {
index: number
isSelected?: boolean
onSelect?: (projectFlag: ProjectFlag) => void
onClick?: (projectFlag: ProjectFlag) => void
className?: string
actions?: React.ReactNode
}
Expand All @@ -20,6 +21,7 @@ const ProjectFeatureRow: FC<ProjectFeatureRowProps> = ({
className,
index,
isSelected,
onClick,
onSelect,
projectFlag,
}) => {
Expand All @@ -40,8 +42,10 @@ const ProjectFeatureRow: FC<ProjectFeatureRowProps> = ({
className={classNames(
'd-none d-lg-flex align-items-lg-center flex-lg-row list-item py-0 list-item-xs fs-small',
className,
{ clickable: !!onClick },
)}
data-test={`cleanup-feature-item-${index}`}
onClick={onClick ? () => onClick(projectFlag) : undefined}
>
{onSelect && (
<div
Expand Down Expand Up @@ -92,7 +96,9 @@ const ProjectFeatureRow: FC<ProjectFeatureRowProps> = ({
<div
className={classNames(
'd-flex flex-column justify-content-center px-2 list-item py-1 d-lg-none',
{ clickable: !!onClick },
)}
onClick={onClick ? () => onClick(projectFlag) : undefined}
>
<div className='d-flex gap-2 align-items-center'>
{onSelect && (
Expand Down
Loading
Loading