17 lines
781 B
TypeScript
17 lines
781 B
TypeScript
// The "Open" button for a finding, notice or ask that carries an absolute console deep link (`url` from the CLI's
|
|
// console-links module, pitfall 71): opens it in the browser through the open-external command.
|
|
import { api, errorText } from '../api';
|
|
import { t } from '../i18n';
|
|
import { useData } from '../store';
|
|
import { Icon } from './icons';
|
|
|
|
export function OpenLink({ url }: { url?: string | null }) {
|
|
const d = useData();
|
|
if (!url || !/^https:\/\//.test(url)) return null;
|
|
return (
|
|
<button className="btn btn-sm btn-ghost" title={url} data-testid="open-link"
|
|
onClick={() => api.openExternal(url).catch(e => d.toast({ kind: 'bad', title: t('link.openFailed'), detail: errorText(e) }))}>
|
|
<Icon name="external" />{t('link.open')}
|
|
</button>
|
|
);
|
|
}
|