-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
404 additions
and
419 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 was deleted.
Oops, something went wrong.
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,78 @@ | ||
import { FC, ReactNode, useEffect, useState } from 'react' | ||
import OrganisationStore from 'common/stores/organisation-store' | ||
import AppActions from 'common/dispatcher/app-actions' | ||
import { Environment, Metadata, Project } from 'common/types/responses' | ||
import ProjectStore from 'common/stores/project-store' | ||
export type CreateEnvType = (data: { | ||
name: string | ||
projectId: string | ||
cloneId?: string | ||
description?: string | ||
cloneFeatureStatesAsync?: boolean | ||
metadata: Environment['metadata'] | ||
}) => void | ||
export type ProjectProviderType = { | ||
children: (props: { | ||
createEnv: CreateEnvType | ||
deleteEnv: typeof AppActions.deleteEnv | ||
deleteProject: typeof AppActions.deleteProject | ||
editEnv: typeof AppActions.editEnv | ||
editProject: typeof AppActions.editProject | ||
error: any | ||
isLoading: boolean | ||
isSaving: boolean | ||
project: Project | null | ||
}) => ReactNode | ||
id?: string | ||
onRemove?: () => void | ||
onRemoveEnvironment?: (environment: Environment) => void | ||
onSave?: (environment: Environment) => void | ||
} | ||
|
||
const ProjectProvider: FC<ProjectProviderType> = ({ | ||
children, | ||
id, | ||
onRemove, | ||
onRemoveEnvironment, | ||
onSave, | ||
}) => { | ||
const [_, setUpdated] = useState(Date.now()) | ||
|
||
useEffect(() => { | ||
const _onChange = () => setUpdated(Date.now) | ||
const _onRemove = () => onRemove?.() | ||
const _onRemoveEnvironment = (environment: Environment) => | ||
onRemoveEnvironment?.(environment) | ||
// @ts-ignore | ||
const _onSave = () => onSave?.(ProjectStore.savedEnv) | ||
OrganisationStore.on('removed', _onRemove) | ||
ProjectStore.on('change', _onChange) | ||
ProjectStore.on('removed', _onRemoveEnvironment) | ||
ProjectStore.on('saved', _onSave) | ||
return () => { | ||
OrganisationStore.off('removed', _onRemove) | ||
ProjectStore.off('change', _onChange) | ||
ProjectStore.off('removed', _onRemoveEnvironment) | ||
ProjectStore.off('saved', _onSave) | ||
} | ||
//eslint-disable-next-line | ||
}, []) | ||
|
||
return ( | ||
<> | ||
{children({ | ||
createEnv: AppActions.createEnv, | ||
deleteEnv: AppActions.deleteEnv, | ||
deleteProject: AppActions.deleteProject, | ||
editEnv: AppActions.editEnv, | ||
editProject: AppActions.editProject, | ||
error: ProjectStore.error, | ||
isLoading: !ProjectStore.getEnvs() || ProjectStore.id !== id, | ||
isSaving: ProjectStore.isSaving, | ||
project: ProjectStore.model || null, | ||
})} | ||
</> | ||
) | ||
} | ||
|
||
export default ProjectProvider |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { FC } from 'react' | ||
import { useGetEnvironmentQuery } from 'common/services/useEnvironment' | ||
|
||
type EnvironmentReadyCheckerType = { | ||
match: { | ||
params: { | ||
environmentId?: string | ||
} | ||
} | ||
} | ||
|
||
const EnvironmentReadyChecker: FC<EnvironmentReadyCheckerType> = ({ | ||
children, | ||
match, | ||
}) => { | ||
const { data, isLoading } = useGetEnvironmentQuery( | ||
{ | ||
id: match.params.environmentId, | ||
}, | ||
{ pollingInterval: 3000, skip: !match.params.environmentId }, | ||
) | ||
if (!match?.params?.environmentId) { | ||
return children | ||
} | ||
return isLoading ? ( | ||
<div className='text-center'> | ||
<Loader /> | ||
</div> | ||
) : data?.is_creating ? ( | ||
<div className='container'> | ||
<div className='d-flex flex-column h-100 flex-1 justify-content-center align-items-center'> | ||
<Loader /> | ||
<h3>Preparing your environment</h3> | ||
<p>We are setting up your new environment...</p> | ||
</div> | ||
</div> | ||
) : ( | ||
children | ||
) | ||
} | ||
|
||
export default EnvironmentReadyChecker |
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
Oops, something went wrong.