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(cosnole): when create workload add register dialog - for master #2143

Merged
merged 2 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(console): add change displayName
  • Loading branch information
jo-hnny committed Nov 2, 2022
commit e4925483e8738f1b3c9785a7496743d5b8d4cf14
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { useState } from 'react';
import { Button, Modal, Form, TextArea } from 'tea-component';
import { registryApi } from '@src/webApi';

interface INamespaceDisplayNameEditorProps {
value: string;
name: string;
onSuccess: () => void;
}

export const NamespaceDisplayNameEditor = ({ value, name, onSuccess }: INamespaceDisplayNameEditorProps) => {
const [visible, _setVisible] = useState(false);

function setVisible(visible: boolean) {
_setVisible(visible);

setDisplayName(value);
}

const [displayName, setDisplayName] = useState(value);

async function handleSubmit() {
await registryApi.modifyNamespaceDisplayName({ name, displayName });

onSuccess();

setVisible(false);
}

return (
<>
<Button type="icon" icon="pencil" onClick={() => setVisible(true)} />

<Modal visible={visible} caption="编辑描述信息" onClose={() => setVisible(false)}>
<Modal.Body>
<Form>
<Form.Item label="描述" required>
<TextArea size="full" value={displayName} onChange={value => setDisplayName(value.trim())} />
</Form.Item>
</Form>
</Modal.Body>

<Modal.Footer>
<Button type="primary" disabled={!displayName} onClick={handleSubmit}>
确定
</Button>

<Button onClick={() => setVisible(false)}>取消</Button>
</Modal.Footer>
</Modal>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { DialogBodyLayout } from '../../../common/layouts';
import { Repo } from '../../models';
import { router } from '../../router';
import { RootProps } from '../RegistryApp';
import { NamespaceDisplayNameEditor } from './NamespaceDisplayNameEditor';

export class RepoTablePanel extends React.Component<RootProps, any> {
componentDidMount() {
Expand Down Expand Up @@ -96,6 +97,11 @@ export class RepoTablePanel extends React.Component<RootProps, any> {
render: (x: Repo) => (
<Text parent="div" overflow>
<span className="text">{x.spec.displayName}</span>
<NamespaceDisplayNameEditor
value={x?.spec?.displayName ?? ''}
name={x?.metadata?.name}
onSuccess={() => this.props.actions.repo.fetch()}
/>
</Text>
)
},
Expand Down
2 changes: 2 additions & 0 deletions web/console/src/webApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export * as virtualMachineAPI from './virtual-machine';
export * as storageClassAPI from './storage-class';

export * as PVCAPI from './pvc';

export * as registryApi from './registry';
25 changes: 25 additions & 0 deletions web/console/src/webApi/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Request } from './request';

export async function modifyNamespaceDisplayName({
name,

displayName
}: {
name: string;

displayName: string;
}) {
return Request.patch(
`/apis/registry.tkestack.io/v1/namespaces/${name}`,
{
spec: {
displayName
}
},
{
headers: {
'Content-Type': 'application/merge-patch+json'
}
}
);
}