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

Add WM navigation through url #1597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 11 additions & 7 deletions frontend/apps/prb3-monitor/src/components/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ import {useStyletron} from 'baseui';

const WmSelector = ({isOpen, onClose}) => {
const allWm = useAtomValue(allWmAtom);
const setCurrWm = useSetAtom(currentWmIdAtom);
const setCurrWm = (key) => {
const parts = document.location.pathname.split('/');
parts[1] = key;
document.location.href = parts.join('/');
};
return (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalHeader>Select WM</ModalHeader>
<ModalBody>
<StatefulMenu
items={allWm}
onItemSelect={({item}) => {
setCurrWm(item.name);
setCurrWm(item.key);
onClose();
}}
overrides={{
Expand Down Expand Up @@ -84,8 +88,8 @@ export default function Nav() {
content={() => (
<StatefulMenu
items={[
{label: 'Workers', url: '/status/worker'},
{label: 'Transactions', url: '/status/tx'},
{label: 'Workers', url: `/${currWm.key}/status/worker`},
{label: 'Transactions', url: `/${currWm.key}/status/tx`},
]}
onItemSelect={({item: i}) => router.push(i.url)}
/>
Expand All @@ -107,10 +111,10 @@ export default function Nav() {
items={[
{
label: 'Workers',
url: '/inv/worker',
url: `/${currWm.key}/inv/worker`,
},
{label: 'Pools', url: '/inv/pool'},
{label: 'Pool Operators', url: '/inv/po'},
{label: 'Pools', url: `/${currWm.key}/inv/pool`},
{label: 'Pool Operators', url: `/${currWm.key}/inv/po`},
]}
onItemSelect={({item: i}) => router.push(i.url)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function PoolOperatorInvPage() {
id: data.pid,
}));
}, [rawFetcher]);
const {data, isLoading, mutate} = useSWR(`inv_po_${currWm?.name}`, fetcher, {refreshInterval: 6000});
const {data, isLoading, mutate} = useSWR(`inv_po_${currWm?.key}`, fetcher, {refreshInterval: 6000});
const [isModalOpen, setModalOpen] = useState(false);
const onModalClose = (reset) => {
setModalOpen(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function PoolInvPage() {
id: data.id,
}));
}, [rawFetcher]);
const {data, isLoading, mutate} = useSWR(`inv_pool_${currWm?.name}`, fetcher, {refreshInterval: 6000});
const {data, isLoading, mutate} = useSWR(`inv_pool_${currWm?.key}`, fetcher, {refreshInterval: 6000});
const [currModalItem, setCurrModalItem] = useState(null);
const [isModalOpen, setModalOpen] = useState(false);
const onModalClose = (reset) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function WorkerInvPage() {
.flat()
.map((data) => ({id: data.id, data}));
}, [rawFetcher]);
const {data, isLoading, mutate} = useSWR(`inv_workers_${currWm?.name}`, fetcher, {refreshInterval: 6000});
const {data, isLoading, mutate} = useSWR(`inv_workers_${currWm?.key}`, fetcher, {refreshInterval: 6000});
const [currModalItem, setCurrModalItem] = useState(null);
const [isModalOpen, setModalOpen] = useState(false);
const onModalClose = (reset) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function WorkerStatusPage() {
ret.txs = [...ret.running_txs, ...ret.pending_txs, ...ret.past_txs].map((data) => ({data, id: data.id}));
return ret;
}, [rawFetcher]);
const {data, isLoading, mutate} = useSWR(`tx_status_${currWm?.name}`, fetcher, {refreshInterval: 6000});
const {data, isLoading, mutate} = useSWR(`tx_status_${currWm?.key}`, fetcher, {refreshInterval: 6000});

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default function WorkerStatusPage() {
id: data.worker.id,
}));
}, [rawFetcher]);
const {data, isLoading, mutate} = useSWR(`worker_status_${currWm?.name}`, fetcher, {refreshInterval: 6000});
const {data, isLoading, mutate} = useSWR(`worker_status_${currWm?.key}`, fetcher, {refreshInterval: 6000});

const batchActions = useMemo(() => {
return [
Expand Down Expand Up @@ -369,10 +369,10 @@ export default function WorkerStatusPage() {
}
}
actionButtons={[
{
onClick: reloadWm,
label: 'Restart WM',
},
// {
// onClick: reloadWm,
// label: 'Restart WM',
// },
]}
/>
<div className={css({width: '12px'})} />
Expand Down
16 changes: 15 additions & 1 deletion frontend/apps/prb3-monitor/src/pages/api/p/[...slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ export default async function handler(req, res) {
const headers = req.headers;
delete headers['content-length'];
delete headers['Content-Length'];
delete headers['transfer-encoding'];
delete headers['Transfer-Encoding'];
delete headers['content-type'];
headers['Content-Type'] = 'application/json';

const body = req.body
? (
typeof req.body === 'object'
? JSON.stringify(req.body)
: req.body
)
: undefined
;

const r = await fetch(url, {
method: req.method,
cache: 'no-cache',
headers,
body: req.body ? (typeof req.body === 'object' ? JSON.stringify(req.body) : req.body) : undefined,
body,
});
res.status(r.status);
res.end(await r.text());
Expand Down
21 changes: 18 additions & 3 deletions frontend/apps/prb3-monitor/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,33 @@ export const allWmAtomRaw = loadable(

export const allWmAtom = atom((get) => {
const r = get(allWmAtomRaw);
return r.data || [];
if (!r.data) {
return [];
}

for (const wm of r.data) {
wm.key = wm.name.toLowerCase()
.replaceAll(/[\s]+/g, '-')
.replaceAll(/[^a-z0-9-]/g, '')
;
}

return r.data;
});

export const allWmAtomInObject = atom((get) => {
const ret = {};
for (const i of get(allWmAtom)) {
ret[i.name] = i;
ret[i.key] = i;
}
return ret;
});

export const currentWmIdAtom = atomWithStorage('currentWmIdAtom', '');
export const currentWmIdAtom = atom((get) => {
const allWm = get(allWmAtom);
const wmid = document?.location.pathname.split('/')[1];
return wmid;
});

export const currentWmAtom = atom((get) => {
const currentWmId = get(currentWmIdAtom);
Expand Down