-
Notifications
You must be signed in to change notification settings - Fork 233
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: Clone DataDocs into other Environments #1419
Open
baumandm
wants to merge
1
commit into
pinterest:master
Choose a base branch
from
baumandm:external/clone-datadoc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
76 changes: 76 additions & 0 deletions
76
querybook/webapp/components/DataDocRightSidebar/DataDocCloneButton.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,76 @@ | ||
import React, { useCallback, useRef } from 'react'; | ||
import toast from 'react-hot-toast'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
|
||
import { ComponentType, ElementType } from 'const/analytics'; | ||
import { trackClick } from 'lib/analytics'; | ||
import { sendConfirm } from 'lib/querybookUI'; | ||
import history from 'lib/router-history'; | ||
import * as dataDocActions from 'redux/dataDoc/action'; | ||
import { currentEnvironmentSelector } from 'redux/environment/selector'; | ||
import { IEnvironment } from 'redux/environment/types'; | ||
import { Dispatch } from 'redux/store/types'; | ||
import { IconButton } from 'ui/Button/IconButton'; | ||
|
||
import { DataDocCloneButtonConfirm } from './DataDocCloneButtonConfirm'; | ||
|
||
interface IProps { | ||
docId: number; | ||
} | ||
|
||
export const DataDocCloneButton: React.FunctionComponent<IProps> = ({ | ||
docId, | ||
}) => { | ||
const dispatch: Dispatch = useDispatch(); | ||
const currentEnvironment = useSelector(currentEnvironmentSelector); | ||
const selectedEnvironment = useRef<IEnvironment>(currentEnvironment); | ||
|
||
const onClone = useCallback(() => { | ||
sendConfirm({ | ||
header: 'Clone DataDoc?', | ||
message: ( | ||
<DataDocCloneButtonConfirm | ||
defaultEnvironment={currentEnvironment} | ||
onEnvironmentChange={(environment) => { | ||
selectedEnvironment.current = environment; | ||
}} | ||
/> | ||
), | ||
onConfirm: () => { | ||
trackClick({ | ||
component: ComponentType.DATADOC_PAGE, | ||
element: ElementType.CLONE_DATADOC_BUTTON, | ||
}); | ||
toast.promise( | ||
dispatch( | ||
dataDocActions.cloneDataDoc( | ||
docId, | ||
selectedEnvironment.current.id | ||
) | ||
).then((dataDoc) => | ||
history.push( | ||
`/${selectedEnvironment.current.name}/datadoc/${dataDoc.id}/` | ||
) | ||
), | ||
{ | ||
loading: 'Cloning DataDoc...', | ||
success: 'Clone Success!', | ||
error: 'Cloning failed.', | ||
} | ||
); | ||
}, | ||
cancelColor: 'default', | ||
confirmIcon: 'Copy', | ||
}); | ||
}, [currentEnvironment, dispatch, docId]); | ||
|
||
return ( | ||
<IconButton | ||
icon="Copy" | ||
onClick={onClone} | ||
tooltip={'Clone'} | ||
tooltipPos={'left'} | ||
title="Clone" | ||
/> | ||
); | ||
}; |
66 changes: 66 additions & 0 deletions
66
querybook/webapp/components/DataDocRightSidebar/DataDocCloneButtonConfirm.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,66 @@ | ||
import React, { useCallback } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { availableEnvironmentsSelector } from 'redux/environment/selector'; | ||
import { IEnvironment } from 'redux/environment/types'; | ||
import { makeSelectOptions, Select } from 'ui/Select/Select'; | ||
import { StyledText } from 'ui/StyledText/StyledText'; | ||
|
||
interface IProps { | ||
defaultEnvironment: IEnvironment; | ||
onEnvironmentChange: (environment: IEnvironment) => void; | ||
} | ||
|
||
export const DataDocCloneButtonConfirm: React.FunctionComponent<IProps> = ({ | ||
defaultEnvironment, | ||
onEnvironmentChange, | ||
}) => { | ||
const availableEnvironments = useSelector(availableEnvironmentsSelector); | ||
|
||
const [selectedEnvironmentId, setSelectedEnvironmentId] = | ||
React.useState<number>(defaultEnvironment.id); | ||
|
||
const internalEnvironmentChange = useCallback( | ||
(event) => { | ||
if (event.target.value) { | ||
const environmentId = Number(event.target.value); | ||
onEnvironmentChange( | ||
availableEnvironments.find( | ||
(env) => env.id === environmentId | ||
) | ||
); | ||
setSelectedEnvironmentId(environmentId); | ||
} | ||
}, | ||
[availableEnvironments, onEnvironmentChange] | ||
); | ||
|
||
const selectOptionsDOM = React.useMemo( | ||
() => | ||
makeSelectOptions( | ||
availableEnvironments.map((env) => ({ | ||
value: env.name, | ||
key: env.id, | ||
})) | ||
), | ||
[availableEnvironments] | ||
); | ||
|
||
return ( | ||
<> | ||
<StyledText className="mb16"> | ||
Select the environment to clone the DataDoc to: | ||
</StyledText> | ||
<Select | ||
value={selectedEnvironmentId} | ||
onChange={internalEnvironmentChange} | ||
className="mb16" | ||
> | ||
{selectOptionsDOM} | ||
</Select> | ||
<StyledText> | ||
You will be redirected to the new Data Doc after cloning. | ||
</StyledText> | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.
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.
this component name seems a bit weird to me. I think this component could be just an environment selector, and move the messages to the DataDocCloneButton component.