Compact contour actions and delete VPS applications with all access
Device Core qualification / qualify (push) Successful in 7m19s
Device Core qualification / qualify (push) Successful in 7m19s
This commit is contained in:
@@ -20,7 +20,7 @@ export function B2HostSettings({ host, workspace, onClose, onChanged, onError }:
|
||||
const [expanded, setExpanded] = useState<string[]>([]), [keyRows, setKeyRows] = useState<string[]>([]);
|
||||
const [creating, setCreating] = useState(''), [name, setName] = useState('');
|
||||
const [creationIntent, setCreationIntent] = useState<{ id: string; name: string } | null>(null);
|
||||
const [history, setHistory] = useState<string[]>([]);
|
||||
const [hiddenHistory, setHiddenHistory] = useState<string[]>([]);
|
||||
const [issued, setIssued] = useState<{ applicationId: string; clientId: string; value: string } | null>(null);
|
||||
const [credentialRows, setCredentialRows] = useState<string[]>([]);
|
||||
const [confirm, setConfirm] = useState<{ action: string; fields: Record<string, unknown>; text: string } | null>(null);
|
||||
@@ -46,6 +46,7 @@ export function B2HostSettings({ host, workspace, onClose, onChanged, onError }:
|
||||
setCredentialRows((rows) => [...new Set([...rows, clientId])]);
|
||||
}
|
||||
if (action === 'key-revoke' && issued?.clientId === data.clientId) setIssued(null);
|
||||
if (action === 'application-delete' && issued?.applicationId === data.integrationId) setIssued(null);
|
||||
if (action === 'connect') { setConnection(''); setImportOpen(false); setSection('contours'); }
|
||||
setCreating(''); setName(''); setCreationIntent(null);
|
||||
try { await refresh(); await onChanged(); } catch (error) { onError(error); }
|
||||
@@ -65,13 +66,22 @@ export function B2HostSettings({ host, workspace, onClose, onChanged, onError }:
|
||||
const open = keyRows.includes(app.id), active = app.credentials.some((item) => item.enabled);
|
||||
return <li key={app.id} className="b2-disclosure">
|
||||
<ResourceRow title={app.name} metadata={legacy ? 'Подключение Mission Core · v1' : active ? 'Ключ выдан' : 'Нет действующего ключа'}
|
||||
actions={<IconButton label={`Ключи ${app.name}`} aria-expanded={open} aria-controls={`keys-${app.id}`} onClick={() => setKeyRows(toggle(keyRows, app.id))}><Icon name={open ? 'chevron-up' : 'chevron-down'} /></IconButton>} />
|
||||
actions={<>
|
||||
{open && !legacy ? <>
|
||||
<IconButton label={`История ключей ${app.name}`} aria-pressed={!hiddenHistory.includes(app.id)} onClick={() => setHiddenHistory(toggle(hiddenHistory, app.id))}><Icon name={hiddenHistory.includes(app.id) ? 'eye-off' : 'eye'} /></IconButton>
|
||||
{canManage ? <>
|
||||
<IconButton label={`${active ? 'Перевыпустить' : 'Выдать'} ключ ${app.name}`} disabled={busy} onClick={() => setConfirm({ action: 'key-issue', fields: { integrationId: app.id, replace: active }, text: active ? `Перевыпустить ключ «${app.name}»? Прежний ключ перестанет работать.` : `Выдать ключ «${app.name}»?` })}><Icon name="plus" /></IconButton>
|
||||
<IconButton label={`Удалить приложение ${app.name}`} disabled={busy} onClick={() => setConfirm({ action: 'application-delete', fields: { integrationId: app.id }, text: `Удалить «${app.name}» со всеми ключами и связями с контурами на этом VPS? Доступ приложения прекратится. Устройства, данные контуров и другие приложения сохранятся.` })}><Icon name="trash" /></IconButton>
|
||||
</> : null}
|
||||
</> : null}
|
||||
<IconButton label={`Ключи ${app.name}`} aria-expanded={open} aria-controls={`keys-${app.id}`} onClick={() => setKeyRows(toggle(keyRows, app.id))}><Icon name={open ? 'chevron-up' : 'chevron-down'} /></IconButton>
|
||||
</>} />
|
||||
{open ? <div id={`keys-${app.id}`} className="b2-disclosure__body">
|
||||
{legacy ? <>
|
||||
<dl className="b2-tracker-facts"><dt>Тип подключения</dt><dd>Прямая привязка Mission Core</dd><dt>ID приложения</dt><dd>{app.id}</dd></dl>
|
||||
<p>Это прежняя привязка сервера, без OAuth-ключа. Выпуск и отзыв ключей ниже относятся к приложениям API v2 и не изменяют эту привязку.</p>
|
||||
</> : <>
|
||||
<ResourceList>{app.credentials.filter((item) => item.enabled || history.includes(app.id)).map((item) => {
|
||||
<ResourceList>{app.credentials.filter((item) => item.enabled || !hiddenHistory.includes(app.id)).map((item) => {
|
||||
const keyOpen = credentialRows.includes(item.client_id);
|
||||
const secret = issued?.applicationId === app.id && issued.clientId === item.client_id ? issued : null;
|
||||
return <li key={item.client_id} className="b2-disclosure">
|
||||
@@ -87,10 +97,7 @@ export function B2HostSettings({ host, workspace, onClose, onChanged, onError }:
|
||||
</div> : null}
|
||||
</li>;
|
||||
})}</ResourceList>
|
||||
<div className="b2-actions">
|
||||
{app.credentials.some((item) => !item.enabled) ? <Button variant="ghost" onClick={() => setHistory(toggle(history, app.id))}>{history.includes(app.id) ? 'Скрыть историю' : 'История ключей'}</Button> : null}
|
||||
{canManage ? <Button disabled={busy} onClick={() => setConfirm({ action: 'key-issue', fields: { integrationId: app.id, replace: active }, text: active ? `Перевыпустить ключ «${app.name}»? Прежний ключ перестанет работать.` : `Выдать ключ «${app.name}»?` })}>{active ? 'Перевыпустить ключ' : 'Выдать ключ'}</Button> : null}
|
||||
</div>
|
||||
{!app.credentials.length ? <p>Ключи ещё не выданы</p> : null}
|
||||
</>}
|
||||
</div> : null}
|
||||
</li>;
|
||||
@@ -126,13 +133,16 @@ export function B2HostSettings({ host, workspace, onClose, onChanged, onError }:
|
||||
const available = (status?.contours || []).filter((contour) => !status?.links?.some((link) => link.contourId === contour.id));
|
||||
return <li key={item.projectRef} className="b2-disclosure">
|
||||
<ResourceRow title={item.name} metadata={linked ? 'Контур VPS связан с проектом' : 'Проект Device Core'}
|
||||
actions={<IconButton label={`Контур ${item.name}`} aria-expanded={open} aria-controls={`contour-${item.projectRef}`} onClick={() => setExpanded(toggle(expanded, item.projectRef))}><Icon name={open ? 'chevron-up' : 'chevron-down'} /></IconButton>} />
|
||||
actions={<>
|
||||
{open && linked && canManage ? <IconButton label={`Добавить приложение в ${item.name}`} disabled={busy} onClick={() => { setCreating(item.projectRef); setName(''); setCreationIntent(null); }}><Icon name="plus" /></IconButton> : null}
|
||||
<IconButton label={`Контур ${item.name}`} aria-expanded={open} aria-controls={`contour-${item.projectRef}`} onClick={() => setExpanded(toggle(expanded, item.projectRef))}><Icon name={open ? 'chevron-up' : 'chevron-down'} /></IconButton>
|
||||
</>} />
|
||||
{open ? <div id={`contour-${item.projectRef}`} className="b2-disclosure__body">
|
||||
{!linked ? <>
|
||||
{canManage ? <Button disabled={busy} loading={pending === 'project-connect'} onClick={() => void run('project-connect', { targetProjectRef: item.projectRef })}>Подключить проект к VPS</Button> : null}
|
||||
{available.length ? <Select label="Связать с существующим контуром" value="" options={[{ value: '', label: 'Выбрать контур VPS' }, ...available.map((c) => ({ value: c.id, label: c.name }))]} onChange={(contourId) => { if (contourId) void run('link', { contourId, targetProjectRef: item.projectRef }); }} disabled={busy} /> : null}
|
||||
</> : <>
|
||||
<div className="b2-section-heading"><strong>Приложения и ключи</strong>{canManage ? <IconButton label={`Добавить приложение в ${item.name}`} disabled={busy} onClick={() => { setCreating(item.projectRef); setName(''); setCreationIntent(null); }}><Icon name="plus" /></IconButton> : null}</div>
|
||||
<div className="b2-section-heading"><strong>Приложения и ключи</strong></div>
|
||||
<ResourceList>{apps.map(applicationRow)}</ResourceList>
|
||||
{!apps.length && creating !== item.projectRef ? <p>Ключи приложений ещё не выданы</p> : null}
|
||||
{creating === item.projectRef ? <div className="b2-settings">
|
||||
@@ -149,6 +159,6 @@ export function B2HostSettings({ host, workspace, onClose, onChanged, onError }:
|
||||
})}</ResourceList> : null}
|
||||
</div>
|
||||
</FeatureSettingsWindow>
|
||||
<ConfirmationModal open={Boolean(confirm)} title="Ключ приложения" description={confirm?.text} confirmLabel="Подтвердить" cancelLabel="Отмена" onClose={() => setConfirm(null)} onConfirm={async () => { if (confirm && await run(confirm.action, confirm.fields)) setConfirm(null); }} />
|
||||
<ConfirmationModal open={Boolean(confirm)} title={confirm?.action === 'application-delete' ? 'Удалить приложение' : 'Ключ приложения'} description={confirm?.text} confirmLabel={confirm?.action === 'application-delete' ? 'Удалить приложение' : 'Подтвердить'} cancelLabel="Отмена" onClose={() => setConfirm(null)} onConfirm={async () => { if (confirm && !busy && await run(confirm.action, confirm.fields)) setConfirm(null); }} />
|
||||
</>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user