2023-01-24 18:35:42 +03:00
|
|
|
import React from "react";
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Datagrid,
|
|
|
|
DateField,
|
|
|
|
List,
|
|
|
|
Pagination,
|
|
|
|
ReferenceField,
|
|
|
|
ReferenceManyField,
|
|
|
|
SearchInput,
|
|
|
|
Show,
|
|
|
|
Tab,
|
|
|
|
TabbedShowLayout,
|
|
|
|
TextField,
|
|
|
|
TopToolbar,
|
|
|
|
useRecordContext,
|
|
|
|
useDelete,
|
|
|
|
useNotify,
|
|
|
|
useRefresh,
|
|
|
|
useTranslate,
|
|
|
|
} from "react-admin";
|
2023-08-30 23:13:14 +03:00
|
|
|
import AutorenewIcon from "@mui/icons-material/Autorenew";
|
|
|
|
import FolderSharedIcon from "@mui/icons-material/FolderShared";
|
|
|
|
import ViewListIcon from "@mui/icons-material/ViewList";
|
2023-01-24 18:35:42 +03:00
|
|
|
|
|
|
|
const DestinationPagination = props => (
|
|
|
|
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
|
|
|
);
|
|
|
|
|
|
|
|
const date_format = {
|
|
|
|
year: "numeric",
|
|
|
|
month: "2-digit",
|
|
|
|
day: "2-digit",
|
|
|
|
hour: "2-digit",
|
|
|
|
minute: "2-digit",
|
|
|
|
second: "2-digit",
|
|
|
|
};
|
|
|
|
|
2023-02-04 18:57:37 +03:00
|
|
|
const destinationRowSx = (record, _index) => ({
|
2023-01-24 18:35:42 +03:00
|
|
|
backgroundColor: record.retry_last_ts > 0 ? "#ffcccc" : "white",
|
|
|
|
});
|
|
|
|
|
2024-02-03 15:46:33 +03:00
|
|
|
const destinationFilters = [<SearchInput source="destination" alwaysOn />];
|
2023-01-24 18:35:42 +03:00
|
|
|
|
2024-02-05 15:06:47 +03:00
|
|
|
export const DestinationReconnectButton = () => {
|
2023-01-24 18:35:42 +03:00
|
|
|
const record = useRecordContext();
|
|
|
|
const refresh = useRefresh();
|
|
|
|
const notify = useNotify();
|
2023-02-08 11:24:02 +03:00
|
|
|
const [handleReconnect, { isLoading }] = useDelete();
|
2023-01-24 18:35:42 +03:00
|
|
|
|
|
|
|
// Reconnect is not required if no error has occurred. (`failure_ts`)
|
|
|
|
if (!record || !record.failure_ts) return null;
|
|
|
|
|
|
|
|
const handleClick = e => {
|
|
|
|
// Prevents redirection to the detail page when clicking in the list
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
handleReconnect(
|
2023-02-08 11:24:02 +03:00
|
|
|
"destinations",
|
|
|
|
{ id: record.id },
|
2023-01-24 18:35:42 +03:00
|
|
|
{
|
|
|
|
onSuccess: () => {
|
|
|
|
notify("ra.notification.updated", {
|
|
|
|
messageArgs: { smart_count: 1 },
|
|
|
|
});
|
|
|
|
refresh();
|
|
|
|
},
|
2023-02-04 18:57:37 +03:00
|
|
|
onError: () => {
|
2023-01-24 18:35:42 +03:00
|
|
|
notify("ra.message.error", { type: "error" });
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
label="resources.destinations.action.reconnect"
|
|
|
|
onClick={handleClick}
|
|
|
|
disabled={isLoading}
|
|
|
|
>
|
|
|
|
<AutorenewIcon />
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-02-05 15:06:47 +03:00
|
|
|
const DestinationShowActions = () => (
|
2023-01-24 18:35:42 +03:00
|
|
|
<TopToolbar>
|
|
|
|
<DestinationReconnectButton />
|
|
|
|
</TopToolbar>
|
|
|
|
);
|
|
|
|
|
2024-02-05 15:06:47 +03:00
|
|
|
const DestinationTitle = () => {
|
2023-01-24 18:35:42 +03:00
|
|
|
const record = useRecordContext();
|
|
|
|
const translate = useTranslate();
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{translate("resources.destinations.name", 1)} {record.destination}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const DestinationList = props => {
|
|
|
|
return (
|
|
|
|
<List
|
|
|
|
{...props}
|
2024-02-03 15:46:33 +03:00
|
|
|
filters={destinationFilters}
|
2023-01-24 18:35:42 +03:00
|
|
|
pagination={<DestinationPagination />}
|
|
|
|
sort={{ field: "destination", order: "ASC" }}
|
|
|
|
>
|
|
|
|
<Datagrid
|
2023-02-04 18:57:37 +03:00
|
|
|
rowSx={destinationRowSx}
|
|
|
|
rowClick={(id, _resource, _record) => `${id}/show/rooms`}
|
|
|
|
bulkActionButtons={false}
|
2023-01-24 18:35:42 +03:00
|
|
|
>
|
|
|
|
<TextField source="destination" />
|
|
|
|
<DateField source="failure_ts" showTime options={date_format} />
|
|
|
|
<DateField source="retry_last_ts" showTime options={date_format} />
|
|
|
|
<TextField source="retry_interval" />
|
|
|
|
<TextField source="last_successful_stream_ordering" />
|
|
|
|
<DestinationReconnectButton />
|
|
|
|
</Datagrid>
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const DestinationShow = props => {
|
|
|
|
const translate = useTranslate();
|
|
|
|
return (
|
|
|
|
<Show
|
|
|
|
actions={<DestinationShowActions />}
|
|
|
|
title={<DestinationTitle />}
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
<TabbedShowLayout>
|
|
|
|
<Tab label="status" icon={<ViewListIcon />}>
|
|
|
|
<TextField source="destination" />
|
|
|
|
<DateField source="failure_ts" showTime options={date_format} />
|
|
|
|
<DateField source="retry_last_ts" showTime options={date_format} />
|
|
|
|
<TextField source="retry_interval" />
|
|
|
|
<TextField source="last_successful_stream_ordering" />
|
|
|
|
</Tab>
|
|
|
|
|
|
|
|
<Tab
|
|
|
|
label={translate("resources.rooms.name", { smart_count: 2 })}
|
|
|
|
icon={<FolderSharedIcon />}
|
|
|
|
path="rooms"
|
|
|
|
>
|
|
|
|
<ReferenceManyField
|
|
|
|
reference="destination_rooms"
|
|
|
|
target="destination"
|
|
|
|
addLabel={false}
|
|
|
|
pagination={<DestinationPagination />}
|
|
|
|
perPage={50}
|
|
|
|
>
|
|
|
|
<Datagrid
|
|
|
|
style={{ width: "100%" }}
|
2023-02-04 18:57:37 +03:00
|
|
|
rowClick={(id, resource, record) => `/rooms/${id}/show`}
|
2023-01-24 18:35:42 +03:00
|
|
|
>
|
|
|
|
<TextField
|
|
|
|
source="room_id"
|
|
|
|
label="resources.rooms.fields.room_id"
|
|
|
|
/>
|
|
|
|
<TextField source="stream_ordering" sortable={false} />
|
|
|
|
<ReferenceField
|
|
|
|
label="resources.rooms.fields.name"
|
|
|
|
source="id"
|
|
|
|
reference="rooms"
|
|
|
|
sortable={false}
|
|
|
|
link=""
|
|
|
|
>
|
|
|
|
<TextField source="name" sortable={false} />
|
|
|
|
</ReferenceField>
|
|
|
|
</Datagrid>
|
|
|
|
</ReferenceManyField>
|
|
|
|
</Tab>
|
|
|
|
</TabbedShowLayout>
|
|
|
|
</Show>
|
|
|
|
);
|
|
|
|
};
|