Skip to content

Commit

Permalink
pulp_file: Repositories & Remotes
Browse files Browse the repository at this point in the history
scaffolding from ansible variants, menu, routes, paths

drop the write_only_fields vs hidden_fields distinction, pulp uses hidden_fields

RepositoryForm -> ContainerRepositoryForm

RepositoryForm, repositoryBasePath - handle file vs ansible different apis

unify remoteType and variant to plugin

DeleteRemoteModal
  • Loading branch information
himdel committed Nov 17, 2024
1 parent b8c0d5b commit 1878035
Show file tree
Hide file tree
Showing 43 changed files with 2,585 additions and 886 deletions.
4 changes: 2 additions & 2 deletions src/actions/ansible-remote-delete.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { msg, t } from '@lingui/macro';
import React from 'react';
import { AnsibleRemoteAPI } from 'src/api';
import { DeleteAnsibleRemoteModal } from 'src/components';
import { DeleteRemoteModal } from 'src/components';
import {
handleHttpError,
parsePulpIDFromURL,
Expand All @@ -14,7 +14,7 @@ export const ansibleRemoteDeleteAction = Action({
title: msg`Delete`,
modal: ({ addAlert, listQuery, setState, state }) =>
state.deleteModalOpen ? (
<DeleteAnsibleRemoteModal
<DeleteRemoteModal
closeAction={() => setState({ deleteModalOpen: null })}
deleteAction={() =>
deleteRemote(state.deleteModalOpen, { addAlert, setState, listQuery })
Expand Down
16 changes: 0 additions & 16 deletions src/actions/ansible-repository-delete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@ export const ansibleRepositoryDeleteAction = Action({
pulp_href,
},
}),
disabled: ({ name }) => {
if (
[
'certified',
'community',
'published',
'rejected',
'staging',
'validated',
].includes(name)
) {
return t`Protected repositories cannot be deleted.`;
}

return null;
},
});

async function deleteRepository(
Expand Down
9 changes: 9 additions & 0 deletions src/actions/file-remote-create.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { msg } from '@lingui/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: '_' })),
});
45 changes: 45 additions & 0 deletions src/actions/file-remote-delete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { msg, t } from '@lingui/macro';
import React from 'react';
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),
);
}
9 changes: 9 additions & 0 deletions src/actions/file-remote-edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { msg } from '@lingui/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 })),
});
9 changes: 9 additions & 0 deletions src/actions/file-repository-create.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { msg } from '@lingui/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: '_' })),
});
100 changes: 100 additions & 0 deletions src/actions/file-repository-delete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { msg, t } from '@lingui/macro';
import React from 'react';
import { FileDistributionAPI, FileRepositoryAPI } from 'src/api';
import { DeleteAnsibleRepositoryModal } 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 ? (
<DeleteAnsibleRepositoryModal
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();
});
}
9 changes: 9 additions & 0 deletions src/actions/file-repository-edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { msg } from '@lingui/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 })),
});
Loading

0 comments on commit 1878035

Please sign in to comment.