Skip to content
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: add duplicate operate for scope config #7439

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions config-ui/src/plugins/components/scope-config-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface Props {
connectionId: ID;
defaultName?: string;
showWarning?: boolean;
forceCreate?: boolean;
scopeId?: ID;
scopeConfigId?: ID;
onCancel: () => void;
Expand All @@ -53,6 +54,7 @@ export const ScopeConfigForm = ({
connectionId,
defaultName,
showWarning = false,
forceCreate = false,
scopeId,
scopeConfigId,
onCancel,
Expand Down Expand Up @@ -81,7 +83,7 @@ export const ScopeConfigForm = ({
(async () => {
try {
const res = await API.scopeConfig.get(plugin, connectionId, scopeConfigId);
setName(res.name);
setName(forceCreate ? `${res.name}-copy` : res.name);
setEntities(res.entities ?? []);
setTransformation(omit(res, ['id', 'connectionId', 'name', 'entities', 'createdAt', 'updatedAt']));
} catch {}
Expand All @@ -99,7 +101,7 @@ export const ScopeConfigForm = ({
const handleSubmit = async () => {
const [success, res] = await operator(
() =>
!scopeConfigId
!scopeConfigId || forceCreate
? API.scopeConfig.create(plugin, connectionId, { name, entities, ...transformation })
: API.scopeConfig.update(plugin, connectionId, scopeConfigId, { name, entities, ...transformation }),
{
Expand Down
32 changes: 27 additions & 5 deletions config-ui/src/plugins/components/scope-config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ interface Props {
}

export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name, onSuccess }: Props) => {
const [type, setType] = useState<'associate' | 'update' | 'relatedProjects'>();
const [relatedProjects, setRelatedProjects] = useState<Array<{ name: string; scopes: string[] }>>([]);
const [type, setType] = useState<'associate' | 'update' | 'relatedProjects' | 'duplicate'>();
const [relatedProjects, setRelatedProjects] = useState<
Array<{ name: string; scopes: Array<{ scopeId: ID; scopeName: string }> }>
>([]);

const {
token: { colorPrimary },
Expand All @@ -57,7 +59,10 @@ export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name
const [success, res] = await operator(() => API.scopeConfig.check(plugin, id), { hideToast: true });

if (success) {
const projects = res.projects.map((it: any) => ({ name: it.name, scopes: [] }));
const projects = res.projects.map((it: any) => ({
name: it.name,
scopes: it.scopes,
}));

if (projects.length !== 1) {
setRelatedProjects(projects);
Expand Down Expand Up @@ -141,6 +146,20 @@ export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name
/>
</Modal>
)}
{type === 'duplicate' && (
<Modal open width={960} centered footer={null} title="Edit Scope Config" onCancel={handleHideDialog}>
<ScopeConfigForm
plugin={plugin}
connectionId={connectionId}
showWarning
forceCreate
scopeConfigId={id}
scopeId={scopeId}
onCancel={handleHideDialog}
onSubmit={handleAssociate}
/>
</Modal>
)}
{type === 'relatedProjects' && (
<Modal
open
Expand All @@ -151,10 +170,10 @@ export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name
onCancel={handleHideDialog}
>
<Message content="The change will apply to all following projects:" />
<ul style={{ marginTop: 15, marginLeft: 30 }}>
<ul style={{ margin: '15px 0 30px 30px' }}>
{relatedProjects.map((it) => (
<li style={{ color: colorPrimary }}>
{it.name}:{it.scopes.join(',')}
{it.name}: {it.scopes.map((sc) => sc.scopeName).join(',')}
</li>
))}
</ul>
Expand All @@ -164,6 +183,9 @@ export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name
<Button type="primary" onClick={() => setType('update')}>
Continue
</Button>
<Button type="primary" onClick={() => setType('duplicate')}>
Duplicate a scope config for {scopeName}
</Button>
</Space>
</Flex>
</Modal>
Expand Down
Loading