When opening config preview modal, displaying the contents instead of using preview modal which tries to download it.
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

This commit is contained in:
Roland 2026-03-14 13:29:03 -06:00
parent 8455955e69
commit f146b332a8
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680

View file

@ -3,8 +3,7 @@ import {Button, Header, Icon, Loader, Modal, Popup, Table} from "../Theme";
import React, {useContext, useEffect, useState} from "react";
import {TableBody, TableCell, TableHeader, TableHeaderCell, TableRow} from "semantic-ui-react";
import {TableRowPlaceholder} from "../Placeholder";
import {useNavigate} from "react-router";
import {getConfigBackups, postConfigBackupImport, postConfigBackupPreview} from "../../api";
import {getConfig, getConfigBackups, postConfigBackupImport, postConfigBackupPreview} from "../../api";
import {ThemeContext} from "../../contexts/contexts";
function WarningIcon({ok}) {
@ -292,10 +291,47 @@ function BackupsModal({open, onClose, fileName, fetchConfigs}) {
</Modal>;
}
function ConfigContentModal({open, onClose, fileName}) {
const [content, setContent] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (!open) return;
let cancelled = false;
setLoading(true);
setContent(null);
getConfig(fileName).then(result => {
if (cancelled) return;
setContent(result);
setLoading(false);
}).catch(() => {
if (cancelled) return;
setContent(null);
setLoading(false);
});
return () => { cancelled = true; };
}, [open, fileName]);
return <Modal open={open} onClose={onClose} closeIcon size='large'>
<Modal.Header>{fileName}</Modal.Header>
<Modal.Content scrolling>
{loading
? <Loader active inline='centered'/>
: content
? <pre style={{whiteSpace: 'pre-wrap', wordBreak: 'break-word'}}>{JSON.stringify(content, null, 2)}</pre>
: <p>Failed to load config contents.</p>
}
</Modal.Content>
<Modal.Actions>
<Button onClick={onClose}>Close</Button>
</Modal.Actions>
</Modal>;
}
function ConfigTableRow({config, importConfig, saveConfig, fetchConfigs}) {
const {file_name, rel_path, valid, successful_import, has_backup_import} = config;
const navigate = useNavigate();
const {file_name, valid, successful_import, has_backup_import} = config;
const [backupsModalOpen, setBackupsModalOpen] = useState(false);
const [contentModalOpen, setContentModalOpen] = useState(false);
const localImportConfig = async () => {
await importConfig(file_name);
@ -332,7 +368,7 @@ function ConfigTableRow({config, importConfig, saveConfig, fetchConfigs}) {
}
return <TableRow>
<TableCell><span onClick={() => navigate(`?preview=${rel_path}`)}>{file_name}</span></TableCell>
<TableCell><span style={{cursor: 'pointer'}} onClick={() => setContentModalOpen(true)}>{file_name}</span></TableCell>
<TableCell><WarningIcon ok={successful_import}/></TableCell>
<TableCell><WarningIcon ok={valid}/></TableCell>
<TableCell className="hide-on-mobile">
@ -351,6 +387,11 @@ function ConfigTableRow({config, importConfig, saveConfig, fetchConfigs}) {
fileName={file_name}
fetchConfigs={fetchConfigs}
/>}
{contentModalOpen && <ConfigContentModal
open={contentModalOpen}
onClose={() => setContentModalOpen(false)}
fileName={file_name}
/>}
</TableRow>
}