MCPcopy
hub / github.com/electerm/electerm / ProfileFormElem

Function ProfileFormElem

src/client/components/profile/profile-form-elem.jsx:20–106  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

18const e = window.translate
19
20export default function ProfileFormElem (props) {
21 const [form] = Form.useForm()
22 const [activeTab, setActiveTab] = useState('ssh')
23 const { profiles } = props.store
24 function genId () {
25 let count = profiles.length ? profiles.length : ''
26 let id = 'PROFILE' + count
27 while (profiles.find(d => d.id === id)) {
28 count = count + 1
29 id = 'PROFILE' + count
30 }
31 return id
32 }
33 const handleSubmit = action(async function (res) {
34 const { formData } = props
35 const update1 = {
36 ...res,
37 id: genId()
38 }
39 let defaultId = update1.id
40 if (formData.id) {
41 defaultId = formData.id
42 props.store.editItem(formData.id, res, settingMap.profiles)
43 } else {
44 props.store.addItem(update1, settingMap.profiles)
45 props.store.setSettingItem({
46 id: '',
47 name: e('profile')
48 })
49 }
50 window.store.makeSureProfileDefault(defaultId)
51 message.success(e('saved'))
52 })
53 const tabsProps = {
54 activeTab,
55 onChangeTab: setActiveTab,
56 form,
57 store: props.store
58 }
59 const profileDefaultWikiLink = 'https://github.com/electerm/electerm/wiki/Default-Profile'
60 const defaultLabel = (
61 <span>
62 {e('default')} <HelpIcon link={profileDefaultWikiLink} />
63 </span>
64 )
65 return (
66 <Form
67 form={form}
68 onFinish={handleSubmit}
69 className='form-wrap pd2l'
70 layout='vertical'
71 initialValues={props.formData}
72 >
73 <p>ID: {props.formData.id || genId()}</p>
74 <FormItem
75 label={e('profileName')}
76 {...formItemLayout}
77 rules={[{

Callers

nothing calls this directly

Calls 2

actionFunction · 0.85
genIdFunction · 0.85

Tested by

no test coverage detected