-
Notifications
You must be signed in to change notification settings - Fork 7
OpenConceptLab/ocl_issues#2485 | Copy project #13
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ import moment from 'moment' | |||||
| import Split from 'react-split'; | ||||||
| import BridgeMatch from '../../services/LazyLoader' | ||||||
|
|
||||||
| import { useParams, useHistory } from 'react-router-dom' | ||||||
| import { useParams, useHistory, useLocation } from 'react-router-dom' | ||||||
|
|
||||||
| import Paper from '@mui/material/Paper' | ||||||
| import Button from '@mui/material/Button'; | ||||||
|
|
@@ -122,6 +122,12 @@ const MapProject = () => { | |||||
| const user = getCurrentUser() | ||||||
| const params = useParams() | ||||||
| const history = useHistory() | ||||||
| const location = useLocation() | ||||||
| const copyFromProjectURL = React.useMemo(() => { | ||||||
| const queryParams = new URLSearchParams(location.search) | ||||||
| return queryParams.get('copyFrom') | ||||||
| }, [location.search]) | ||||||
|
|
||||||
| const bridgeRef = React.useRef() | ||||||
| const facetsRequestsRef = React.useRef({}) | ||||||
| const latestFacetRequestRef = React.useRef({}) | ||||||
|
|
@@ -304,10 +310,15 @@ const MapProject = () => { | |||||
|
|
||||||
| React.useEffect(() => { | ||||||
| fetchMapTypes() | ||||||
| fetchAIModels() | ||||||
|
|
||||||
| if(params.projectId && params.owner) { | ||||||
| fetchAndSetProject() | ||||||
| return | ||||||
| } | ||||||
| if(copyFromProjectURL) { | ||||||
| copyFromProject() | ||||||
| } | ||||||
| fetchAIModels() | ||||||
| }, []) | ||||||
|
|
||||||
| React.useEffect(() => { | ||||||
|
|
@@ -324,6 +335,27 @@ const MapProject = () => { | |||||
| } | ||||||
| }, [repoVersion, project]) | ||||||
|
|
||||||
|
|
||||||
| const copyFromProject = () => { | ||||||
| setLoadingProject(true) | ||||||
| APIService.new().overrideURL(copyFromProjectURL).appendToUrl('configurations/').get().then(response => { | ||||||
| const copiedProject = response.data | ||||||
| setProject(null) | ||||||
| setFilters(copiedProject.filters || {}) | ||||||
| setLookupConfig(copiedProject.lookup_config || {}) | ||||||
| setCandidatesScore(copiedProject.score_configuration || {recommended: 99, available: 70}) | ||||||
| setRetired(Boolean(copiedProject.include_retired || false)) | ||||||
| setAlgosSelected(copiedProject.algorithms || []) | ||||||
| setEncoderModel(copiedProject.encoder_model || DEFAULT_ENCODER_MODEL) | ||||||
| if(copiedProject.target_repo_url) { | ||||||
| const repoParams = URIToParentParams(copiedProject.target_repo_url, true) | ||||||
| fetchRepo(dropVersion(copiedProject.target_repo_url)) | ||||||
| fetchVersions(copiedProject.target_repo_url, repoParams?.repoVersion || 'HEAD') | ||||||
| } | ||||||
| setConfigure(true) | ||||||
| }).finally(() => setLoadingProject(false)) | ||||||
| } | ||||||
|
|
||||||
| const fetchAndSetProject = () => { | ||||||
| setLoadingProject(true) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefill |
||||||
| let url = ['', params.ownerType, params.owner, 'map-projects', params.projectId, ''].join('/') | ||||||
|
|
@@ -2707,6 +2739,15 @@ const MapProject = () => { | |||||
| /> | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| const onCopyClick = event => { | ||||||
| event.preventDefault() | ||||||
| event.stopPropagation() | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should open in the same tab to match the listing-page button.
Suggested change
|
||||||
| if(project?.url) { | ||||||
| window.open(`/#/map-projects/new?copyFrom=${encodeURIComponent(project.url)}`, '_blank', 'noopener,noreferrer') | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return permissionDenied ? <Error403/> : ( | ||||||
| <div className='col-xs-12 padding-0' style={{borderRadius: '10px', width: 'calc(100vw - 32px)'}}> | ||||||
| { | ||||||
|
|
@@ -2860,6 +2901,7 @@ const MapProject = () => { | |||||
| isProjectsLogOpen={showProjectLogs} | ||||||
| configure={configure} | ||||||
| setConfigure={setConfigure} | ||||||
| onCopyClick={onCopyClick} | ||||||
| /> | ||||||
| } | ||||||
| </div> | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| import React from 'react' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { useHistory } from 'react-router-dom' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { useTranslation } from 'react-i18next'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import moment from 'moment' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import reject from 'lodash/reject' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import Button from '@mui/material/Button' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -12,21 +15,24 @@ import TableHead from '@mui/material/TableHead'; | |||||||||||||||||||||||||||||||||||||||||||||||
| import TableRow from '@mui/material/TableRow'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import Skeleton from '@mui/material/Skeleton'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import ListItemText from '@mui/material/ListItemText' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import Tooltip from '@mui/material/Tooltip' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import AddIcon from '@mui/icons-material/Add' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import times from 'lodash/times' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import APIService from '../../services/APIService' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { getCurrentUser } from '../../common/utils' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import OwnerIcon from '../common/OwnerIcon' | ||||||||||||||||||||||||||||||||||||||||||||||||
| import NoResults from '../search/NoResults'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import MapProjectDeleteConfirmDialog from './MapProjectDeleteConfirmDialog'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { useTranslation } from 'react-i18next'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const MapProjects = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const { t } = useTranslation(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| const history = useHistory() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const user = getCurrentUser() | ||||||||||||||||||||||||||||||||||||||||||||||||
| const [loading, setLoading] = React.useState([]) | ||||||||||||||||||||||||||||||||||||||||||||||||
| const [projects, setProjects] = React.useState([]) | ||||||||||||||||||||||||||||||||||||||||||||||||
| const [deleteProject, setDeleteProject] = React.useState(null) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const fetchProjects = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| fetchUserProjects() | ||||||||||||||||||||||||||||||||||||||||||||||||
| fetchOrgProjects() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,6 +59,14 @@ const MapProjects = () => { | |||||||||||||||||||||||||||||||||||||||||||||||
| setDeleteProject(null) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const onCopyClick = (event, project) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| event.preventDefault() | ||||||||||||||||||||||||||||||||||||||||||||||||
| event.stopPropagation() | ||||||||||||||||||||||||||||||||||||||||||||||||
| if(project?.url) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| history.push(`/map-projects/new?copyFrom=${encodeURIComponent(project.url)}`) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const isSplitView = false | ||||||||||||||||||||||||||||||||||||||||||||||||
| const loaded = loading.length === 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -141,10 +155,15 @@ const MapProjects = () => { | |||||||||||||||||||||||||||||||||||||||||||||||
| </TableCell> | ||||||||||||||||||||||||||||||||||||||||||||||||
| <TableCell align='right'> | ||||||||||||||||||||||||||||||||||||||||||||||||
| <span style={{display: 'flex', alignItems: 'center'}}> | ||||||||||||||||||||||||||||||||||||||||||||||||
| <Button size='small' color='primary' variant='contained' sx={{textTransform: 'none'}} href={`#${project.url}`}> | ||||||||||||||||||||||||||||||||||||||||||||||||
| <Button size='small' color='primary' variant='contained' sx={{textTransform: 'none', margin: '0 4px'}} href={`#${project.url}`}> | ||||||||||||||||||||||||||||||||||||||||||||||||
| {t('common.open')} | ||||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||||
| <Button size='small' color='error' variant='text' sx={{marginLeft: '8px', textTransform: 'none'}} onClick={() => setDeleteProject(project)}> | ||||||||||||||||||||||||||||||||||||||||||||||||
| <Tooltip title={t('map_project.copy_project')}> | ||||||||||||||||||||||||||||||||||||||||||||||||
| <Button size='small' variant='contained' color='secondary' sx={{margin: '0 4px', textTransform: 'none'}} onClick={event => onCopyClick(event, project)}> | ||||||||||||||||||||||||||||||||||||||||||||||||
| {t('common.copy')} | ||||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||||
| </Tooltip> | ||||||||||||||||||||||||||||||||||||||||||||||||
| <Button size='small' color='error' variant='text' sx={{margin: '0 4px', textTransform: 'none'}} onClick={() => setDeleteProject(project)}> | ||||||||||||||||||||||||||||||||||||||||||||||||
| {t('common.delete')} | ||||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+158
to
168
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation inconsistency.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
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.
copyFromProjectURLis read inside this effect but missing from deps. If mount-only is intentional, add// eslint-disable-next-line react-hooks/exhaustive-depswith a one-line reason.