-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pulp_file: Repositories & Remotes (#137)
* RepositoryForm -> ContainerRepositoryForm * AnsibleRepositoryForm -> RepositoryForm * pulp_file: Repositories & Remotes * {Ansible,File}{Repository,Remote}{Detail,Edit,List} - unbeta * file repository distributions: show pulp-cli command to add it from elsewhere * LazyRepositories - support ansible, file, rpm * LazyDistributions - plugin * RemoteForm: fixup ids * FileRemote - remote requirements_file, auth_url, signed_only from type * FileRemoteAPI - add smartUpdate, use * Repository/Remote delete: fixup task api url
- Loading branch information
Showing
48 changed files
with
2,601 additions
and
1,032 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { msg } from '@lingui/core/macro'; | ||
import { Paths, formatPath } from 'src/paths'; | ||
import { Action } from './action'; | ||
|
||
export const fileRemoteCreateAction = Action({ | ||
title: msg`Add remote`, | ||
onClick: (item, { navigate }) => | ||
navigate(formatPath(Paths.file.remote.edit, { name: '_' })), | ||
}); |
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,44 @@ | ||
import { msg, t } from '@lingui/core/macro'; | ||
import { FileRemoteAPI } from 'src/api'; | ||
import { DeleteRemoteModal } from 'src/components'; | ||
import { | ||
handleHttpError, | ||
parsePulpIDFromURL, | ||
taskAlert, | ||
waitForTaskUrl, | ||
} from 'src/utilities'; | ||
import { Action } from './action'; | ||
|
||
export const fileRemoteDeleteAction = Action({ | ||
title: msg`Delete`, | ||
modal: ({ addAlert, listQuery, setState, state }) => | ||
state.deleteModalOpen ? ( | ||
<DeleteRemoteModal | ||
closeAction={() => setState({ deleteModalOpen: null })} | ||
deleteAction={() => | ||
deleteRemote(state.deleteModalOpen, { addAlert, setState, listQuery }) | ||
} | ||
name={state.deleteModalOpen.name} | ||
/> | ||
) : null, | ||
onClick: ( | ||
{ name, id, pulp_href }: { name: string; id?: string; pulp_href?: string }, | ||
{ setState }, | ||
) => | ||
setState({ | ||
deleteModalOpen: { pulpId: id || parsePulpIDFromURL(pulp_href), name }, | ||
}), | ||
}); | ||
|
||
function deleteRemote({ name, pulpId }, { addAlert, setState, listQuery }) { | ||
return FileRemoteAPI.delete(pulpId) | ||
.then(({ data }) => { | ||
addAlert(taskAlert(data.task, t`Removal started for remote ${name}`)); | ||
setState({ deleteModalOpen: null }); | ||
return waitForTaskUrl(data.task); | ||
}) | ||
.then(() => listQuery()) | ||
.catch( | ||
handleHttpError(t`Failed to remove remote ${name}`, () => null, addAlert), | ||
); | ||
} |
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,9 @@ | ||
import { msg } from '@lingui/core/macro'; | ||
import { Paths, formatPath } from 'src/paths'; | ||
import { Action } from './action'; | ||
|
||
export const fileRemoteEditAction = Action({ | ||
title: msg`Edit`, | ||
onClick: ({ name }, { navigate }) => | ||
navigate(formatPath(Paths.file.remote.edit, { name })), | ||
}); |
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,9 @@ | ||
import { msg } from '@lingui/core/macro'; | ||
import { Paths, formatPath } from 'src/paths'; | ||
import { Action } from './action'; | ||
|
||
export const fileRepositoryCreateAction = Action({ | ||
title: msg`Add repository`, | ||
onClick: (item, { navigate }) => | ||
navigate(formatPath(Paths.file.repository.edit, { name: '_' })), | ||
}); |
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,99 @@ | ||
import { msg, t } from '@lingui/core/macro'; | ||
import { FileDistributionAPI, FileRepositoryAPI } from 'src/api'; | ||
import { DeleteRepositoryModal } from 'src/components'; | ||
import { | ||
handleHttpError, | ||
parsePulpIDFromURL, | ||
taskAlert, | ||
waitForTaskUrl, | ||
} from 'src/utilities'; | ||
import { Action } from './action'; | ||
|
||
export const fileRepositoryDeleteAction = Action({ | ||
title: msg`Delete`, | ||
modal: ({ addAlert, listQuery, setState, state }) => | ||
state.deleteModalOpen ? ( | ||
<DeleteRepositoryModal | ||
closeAction={() => setState({ deleteModalOpen: null })} | ||
deleteAction={() => | ||
deleteRepository(state.deleteModalOpen, { | ||
addAlert, | ||
listQuery, | ||
setState, | ||
}) | ||
} | ||
name={state.deleteModalOpen.name} | ||
/> | ||
) : null, | ||
onClick: ( | ||
{ name, id, pulp_href }: { name: string; id?: string; pulp_href?: string }, | ||
{ setState }, | ||
) => | ||
setState({ | ||
deleteModalOpen: { | ||
pulpId: id || parsePulpIDFromURL(pulp_href), | ||
name, | ||
pulp_href, | ||
}, | ||
}), | ||
}); | ||
|
||
async function deleteRepository( | ||
{ name, pulp_href, pulpId }, | ||
{ addAlert, setState, listQuery }, | ||
) { | ||
// TODO: handle more pages | ||
const distributionsToDelete = await FileDistributionAPI.list({ | ||
repository: pulp_href, | ||
page: 1, | ||
page_size: 100, | ||
}) | ||
.then(({ data: { results } }) => results || []) | ||
.catch((e) => { | ||
handleHttpError( | ||
t`Failed to list distributions, removing only the repository.`, | ||
() => null, | ||
addAlert, | ||
)(e); | ||
return []; | ||
}); | ||
|
||
const deleteRepo = FileRepositoryAPI.delete(pulpId) | ||
.then(({ data }) => { | ||
addAlert(taskAlert(data.task, t`Removal started for repository ${name}`)); | ||
return waitForTaskUrl(data.task); | ||
}) | ||
.catch( | ||
handleHttpError( | ||
t`Failed to remove repository ${name}`, | ||
() => setState({ deleteModalOpen: null }), | ||
addAlert, | ||
), | ||
); | ||
|
||
const deleteDistribution = ({ name, pulp_href }) => { | ||
const distribution_id = parsePulpIDFromURL(pulp_href); | ||
return FileDistributionAPI.delete(distribution_id) | ||
.then(({ data }) => { | ||
addAlert( | ||
taskAlert(data.task, t`Removal started for distribution ${name}`), | ||
); | ||
return waitForTaskUrl(data.task); | ||
}) | ||
.catch( | ||
handleHttpError( | ||
t`Failed to remove distribution ${name}`, | ||
() => null, | ||
addAlert, | ||
), | ||
); | ||
}; | ||
|
||
return Promise.all([ | ||
deleteRepo, | ||
...distributionsToDelete.map(deleteDistribution), | ||
]).then(() => { | ||
setState({ deleteModalOpen: null }); | ||
listQuery(); | ||
}); | ||
} |
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,9 @@ | ||
import { msg } from '@lingui/core/macro'; | ||
import { Paths, formatPath } from 'src/paths'; | ||
import { Action } from './action'; | ||
|
||
export const fileRepositoryEditAction = Action({ | ||
title: msg`Edit`, | ||
onClick: ({ name }, { navigate }) => | ||
navigate(formatPath(Paths.file.repository.edit, { name })), | ||
}); |
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,148 @@ | ||
import { msg, t } from '@lingui/core/macro'; | ||
import { Button, FormGroup, Modal, Switch } from '@patternfly/react-core'; | ||
import { useEffect, useState } from 'react'; | ||
import { FileRepositoryAPI } from 'src/api'; | ||
import { HelpButton, Spinner } from 'src/components'; | ||
import { handleHttpError, parsePulpIDFromURL, taskAlert } from 'src/utilities'; | ||
import { Action } from './action'; | ||
|
||
const SyncModal = ({ | ||
closeAction, | ||
syncAction, | ||
name, | ||
}: { | ||
closeAction: () => null; | ||
syncAction: (syncParams) => Promise<void>; | ||
name: string; | ||
}) => { | ||
const [pending, setPending] = useState(false); | ||
const [syncParams, setSyncParams] = useState({ | ||
mirror: true, | ||
optimize: true, | ||
}); | ||
|
||
useEffect(() => { | ||
setPending(false); | ||
setSyncParams({ mirror: true, optimize: true }); | ||
}, [name]); | ||
|
||
if (!name) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Modal | ||
actions={[ | ||
<div data-cy='sync-button' key='sync'> | ||
<Button | ||
key='sync' | ||
onClick={() => { | ||
setPending(true); | ||
syncAction(syncParams) | ||
.then(closeAction) | ||
.finally(() => setPending(false)); | ||
}} | ||
variant='primary' | ||
isDisabled={pending} | ||
> | ||
{t`Sync`} | ||
{pending && <Spinner size='sm' />} | ||
</Button> | ||
</div>, | ||
<Button key='close' onClick={closeAction} variant='link'> | ||
{t`Close`} | ||
</Button>, | ||
]} | ||
isOpen | ||
onClose={closeAction} | ||
title={t`Sync repository "${name}"`} | ||
variant='medium' | ||
> | ||
<FormGroup | ||
label={t`Mirror`} | ||
labelIcon={ | ||
<HelpButton | ||
content={t`If selected, all content that is not present in the remote repository will be removed from the local repository; otherwise, sync will add missing content.`} | ||
/> | ||
} | ||
> | ||
<Switch | ||
isChecked={syncParams.mirror} | ||
onChange={(_event, mirror) => | ||
setSyncParams({ ...syncParams, mirror }) | ||
} | ||
label={t`Content not present in remote repository will be removed from the local repository`} | ||
labelOff={t`Sync will only add missing content`} | ||
/> | ||
</FormGroup> | ||
<br /> | ||
<FormGroup | ||
label={t`Optimize`} | ||
labelIcon={ | ||
<HelpButton | ||
content={t`Only perform the sync if changes are reported by the remote server. To force a sync to happen, deselect this option.`} | ||
/> | ||
} | ||
> | ||
<Switch | ||
isChecked={syncParams.optimize} | ||
onChange={(_event, optimize) => | ||
setSyncParams({ ...syncParams, optimize }) | ||
} | ||
label={t`Only perform the sync if changes are reported by the remote server.`} | ||
labelOff={t`Force a sync to happen.`} | ||
/> | ||
</FormGroup> | ||
<br /> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export const fileRepositorySyncAction = Action({ | ||
title: msg`Sync`, | ||
modal: ({ addAlert, query, setState, state }) => | ||
state.syncModalOpen ? ( | ||
<SyncModal | ||
closeAction={() => setState({ syncModalOpen: null })} | ||
syncAction={(syncParams) => | ||
syncRepository(state.syncModalOpen, { addAlert, query }, syncParams) | ||
} | ||
name={state.syncModalOpen.name} | ||
/> | ||
) : null, | ||
onClick: ({ name, pulp_href }, { setState }) => | ||
setState({ | ||
syncModalOpen: { name, pulp_href }, | ||
}), | ||
visible: (_item, { hasPermission }) => | ||
hasPermission('file.change_collectionremote'), | ||
disabled: ({ remote, last_sync_task }) => { | ||
if (!remote) { | ||
return t`There are no remotes associated with this repository.`; | ||
} | ||
|
||
if ( | ||
last_sync_task && | ||
['running', 'waiting'].includes(last_sync_task.state) | ||
) { | ||
return t`Sync task is already queued.`; | ||
} | ||
}, | ||
}); | ||
|
||
function syncRepository({ name, pulp_href }, { addAlert, query }, syncParams) { | ||
const pulpId = parsePulpIDFromURL(pulp_href); | ||
return FileRepositoryAPI.sync(pulpId, syncParams || { mirror: true }) | ||
.then(({ data }) => { | ||
addAlert(taskAlert(data.task, t`Sync started for repository "${name}".`)); | ||
|
||
query(); | ||
}) | ||
.catch( | ||
handleHttpError( | ||
t`Failed to sync repository "${name}"`, | ||
() => null, | ||
addAlert, | ||
), | ||
); | ||
} |
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.