-
Notifications
You must be signed in to change notification settings - Fork 429
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: LaunchDarkly importer UI #2837
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
348ebc4
feat: LauncDarkly importer UI
novakzaballa 2c5f372
feat: Update name flag
novakzaballa 587b030
Merge branch 'main' into feat/launchdark-importer-ui
novakzaballa 7fc524c
Merge branch 'main' into feat/launchdark-importer-ui
novakzaballa efc4ef9
reduce time to one sec
novakzaballa 0d5a6f0
Compare url with Project.api in _request
novakzaballa ccefd2d
chore: Correct typo on Import Page
novakzaballa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
|
||
export const launchDarklyService = service | ||
.enhanceEndpoints({ addTagTypes: ['launchDarklyProjectImport'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
createLaunchDarklyProjectImport: builder.mutation< | ||
Res['launchDarklyProjectImport'], | ||
Req['createLaunchDarklyProjectImport'] | ||
>({ | ||
invalidatesTags: [{ id: 'LIST', type: 'launchDarklyProjectImport' }], | ||
query: (query: Req['createLaunchDarklyProjectImport']) => ({ | ||
body: query.body, | ||
method: 'POST', | ||
url: `projects/${query.project_id}/imports/launch-darkly/`, | ||
}), | ||
}), | ||
getLaunchDarklyProjectImport: builder.query< | ||
Res['launchDarklyProjectImport'], | ||
Req['getLaunchDarklyProjectImport'] | ||
>({ | ||
providesTags: [{ id: 'LIST', type: 'launchDarklyProjectImport' }], | ||
query: (query) => ({ | ||
url: `projects/${query.project_id}/imports/launch-darkly/${query.import_id}/`, | ||
}), | ||
}), | ||
getLaunchDarklyProjectsImport: builder.query< | ||
Res['launchDarklyProjectsImport'], | ||
Req['getLaunchDarklyProjectsImport'] | ||
>({ | ||
providesTags: [{ id: 'LIST', type: 'launchDarklyProjectImport' }], | ||
query: (query) => ({ | ||
url: `projects/${query.project_id}/imports/launch-darkly/`, | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function createLaunchDarklyProjectImport( | ||
store: any, | ||
data: Req['createLaunchDarklyProjectImport'], | ||
options?: Parameters< | ||
typeof launchDarklyService.endpoints.createLaunchDarklyProjectImport.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
launchDarklyService.endpoints.createLaunchDarklyProjectImport.initiate(data, options), | ||
) | ||
} | ||
export async function getLaunchDarklyProjectImport( | ||
store: any, | ||
data: Req['getLaunchDarklyProjectImport'], | ||
options?: Parameters< | ||
typeof launchDarklyService.endpoints.getLaunchDarklyProjectImport.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
launchDarklyService.endpoints.getLaunchDarklyProjectImport.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
export async function getLaunchDarklyProjectsImport( | ||
store: any, | ||
data: Req['getLaunchDarklyProjectsImport'], | ||
options?: Parameters< | ||
typeof launchDarklyService.endpoints.getLaunchDarklyProjectsImport.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
launchDarklyService.endpoints.getLaunchDarklyProjectsImport.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useCreateLaunchDarklyProjectImportMutation, | ||
useGetLaunchDarklyProjectImportQuery, | ||
useGetLaunchDarklyProjectsImportQuery, | ||
// END OF EXPORTS | ||
} = launchDarklyService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetLaunchDarklyProjectQuery({ id: 2 }, {}) //get hook | ||
const [createLaunchDarklyProjectImport, { isLoading, data, isSuccess }] = useCreateLaunchDarklyProjectImportMutation() //create hook | ||
launchDarklyService.endpoints.getLaunchDarklyProjectImport.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
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,181 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import _data from 'common/data/base/_data' | ||
import { | ||
useCreateLaunchDarklyProjectImportMutation, | ||
useGetLaunchDarklyProjectImportQuery, | ||
} from 'common/services/useLaunchDarklyProjectImport' | ||
import AppLoader from 'components/AppLoader' | ||
|
||
type ImportPageType = { | ||
projectId: string | ||
projectName: string | ||
} | ||
|
||
const ImportPage: FC<ImportPageType> = ({ projectId, projectName }) => { | ||
const [LDKey, setLDKey] = useState<string>('') | ||
const [importId, setImportId] = useState<string>('') | ||
const [isLoading, setIsLoading] = useState<boolean>(false) | ||
const [isAppLoading, setAppIsLoading] = useState<boolean>(false) | ||
const [projects, setProjects] = useState<string>([]) | ||
const [createLaunchDarklyProjectImport, { data, isSuccess }] = | ||
useCreateLaunchDarklyProjectImportMutation() | ||
|
||
const { | ||
data: status, | ||
isSuccess: statusLoaded, | ||
refetch, | ||
} = useGetLaunchDarklyProjectImportQuery({ | ||
import_id: importId, | ||
project_id: projectId, | ||
}) | ||
|
||
useEffect(() => { | ||
const checkImportStatus = async () => { | ||
setAppIsLoading(true) | ||
const intervalId = setInterval(async () => { | ||
await refetch() | ||
|
||
if (statusLoaded && status && status.status.result === 'success') { | ||
clearInterval(intervalId) | ||
setAppIsLoading(false) | ||
window.location.reload() | ||
} | ||
}, 1000) | ||
} | ||
|
||
if (statusLoaded) { | ||
checkImportStatus() | ||
} | ||
}, [statusLoaded, status, refetch]) | ||
|
||
useEffect(() => { | ||
if (isSuccess) { | ||
setImportId(data.id) | ||
refetch() | ||
} | ||
}, [isSuccess, data, refetch]) | ||
|
||
const getProjectList = (LDKey: string) => { | ||
setIsLoading(true) | ||
_data | ||
.get( | ||
`https://app.launchdarkly.com/api/v2/projects`, | ||
'', | ||
{ | ||
'Authorization': LDKey, | ||
}, | ||
true, | ||
) | ||
.then((res) => { | ||
setIsLoading(false) | ||
setProjects(res.items) | ||
}) | ||
} | ||
|
||
const createImportLDProjects = (LDKey: string, projectId: string) => { | ||
createLaunchDarklyProjectImport({ | ||
body: { project_key: 'default', token: LDKey }, | ||
project_id: projectId, | ||
}) | ||
} | ||
|
||
return ( | ||
<> | ||
{isAppLoading && ( | ||
<div className='overlay'> | ||
<div className='title'>Importing Project</div> | ||
<AppLoader /> | ||
</div> | ||
)} | ||
<div className='mt-4'> | ||
<h5>Import LaunchDarkly Projects</h5> | ||
<label>Set LaunchDarkly key</label> | ||
<FormGroup> | ||
<Row className='align-items-start col-md-8'> | ||
<Flex className='ml-0'> | ||
<Input | ||
value={LDKey} | ||
name='ldkey' | ||
onChange={(e) => setLDKey(Utils.safeParseEventValue(e))} | ||
type='text' | ||
placeholder='My LaunchDarkly key' | ||
/> | ||
</Flex> | ||
<Button | ||
id='save-proj-btn' | ||
disabled={!LDKey} | ||
className='ml-3' | ||
onClick={() => getProjectList(LDKey)} | ||
> | ||
{'Next'} | ||
</Button> | ||
</Row> | ||
</FormGroup> | ||
{isLoading ? ( | ||
<div className='text-center'> | ||
<Loader /> | ||
</div> | ||
) : ( | ||
projects.length > 0 && ( | ||
<div> | ||
<FormGroup> | ||
<PanelSearch | ||
id='projects-list' | ||
className='no-pad panel-projects' | ||
listClassName='row mt-n2 gy-4' | ||
title='Launch Darkly Projects' | ||
items={projects} | ||
renderRow={({ name }, i) => { | ||
return ( | ||
<> | ||
<Button | ||
className='btn-project' | ||
onClick={() => | ||
openConfirm( | ||
'Import LaunchDarkly project', | ||
<div> | ||
{`Are you sure you want import ${name} to ${projectName}`} | ||
</div>, | ||
() => { | ||
createImportLDProjects(LDKey, projectId) | ||
}, | ||
() => { | ||
return | ||
}, | ||
) | ||
} | ||
> | ||
<Row className='flex-nowrap'> | ||
<h2 | ||
style={{ | ||
backgroundColor: Utils.getProjectColour(i), | ||
}} | ||
className='btn-project-letter mb-0' | ||
> | ||
{name[0]} | ||
</h2> | ||
<div className='font-weight-medium btn-project-title'> | ||
{name} | ||
</div> | ||
</Row> | ||
</Button> | ||
</> | ||
) | ||
}} | ||
renderNoResults={ | ||
<div> | ||
<Row> | ||
<div className='font-weight-medium'>No Prokects</div> | ||
novakzaballa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Row> | ||
</div> | ||
} | ||
/> | ||
</FormGroup> | ||
</div> | ||
) | ||
)} | ||
</div> | ||
</> | ||
) | ||
} | ||
export default ImportPage |
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 |
---|---|---|
|
@@ -18,3 +18,4 @@ | |
@import "spacing-utils"; | ||
@import "tooltips"; | ||
@import "base"; | ||
@import "overlay"; |
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,15 @@ | ||
.overlay { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.544); | ||
z-index: 9999; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
.title{ | ||
color: #fff | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think I mentioned this in another PR, but we can just base this on if the url is Project.api in _request
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.
Done.