Skip to content
Merged
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
21 changes: 11 additions & 10 deletions react/src/components/AutoRefreshSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { useRafInterval } from 'ahooks';
import { Switch, Typography } from 'antd';
import { Switch, SwitchProps, Typography } from 'antd';
import { BAIFlex } from 'backend.ai-ui';
import React, { useState } from 'react';
import React from 'react';
import { useInterval } from 'src/hooks/useIntervalValue';

const { Text } = Typography;

interface Props {
interface Props extends SwitchProps {
children?: React.ReactNode;
onRefresh: () => void;
interval: number;
interval: number | null;
}

const AutoRefreshSwitch: React.FC<Props> = ({
children,
interval,
onRefresh,
...switchProps
}) => {
const [on, setOn] = useState(true);

useRafInterval(
useInterval(
() => {
onRefresh();
},
on ? interval : undefined,
switchProps.checked ? interval : null,
);

return (
<BAIFlex direction="row" gap={'xs'}>
<Switch size="small" checked={on} onChange={setOn} />
<Switch size="small" {...switchProps} />
<Text>{children}</Text>
</BAIFlex>
);
Expand Down
67 changes: 44 additions & 23 deletions react/src/components/ComputeSessionNodeItems/ContainerLogModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ import { downloadBlob } from '../../helper/csv-util';
import { useSuspendedBackendaiClient } from '../../hooks';
import { useTanQuery } from '../../hooks/reactQueryAlias';
import { useMemoWithPrevious } from '../../hooks/useMemoWithPrevious';
import AutoRefreshSwitch from '../AutoRefreshSwitch';
import BAISelect from '../BAISelect';
import { ReloadOutlined } from '@ant-design/icons';
import { LazyLog, ScrollFollow } from '@melloware/react-logviewer';
import { Button, Divider, Grid, theme, Tooltip, Typography } from 'antd';
import {
Button,
Divider,
Grid,
InputNumber,
theme,
Tooltip,
Typography,
} from 'antd';
import { BAIFlex, BAIModal, BAIModalProps } from 'backend.ai-ui';
import _ from 'lodash';
import { DownloadIcon } from 'lucide-react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { graphql, useFragment } from 'react-relay';
import { useBAISettingUserState } from 'src/hooks/useBAISetting';

interface ContainerLogModalProps extends BAIModalProps {
sessionFrgmt: ContainerLogModalFragment$key | null;
Expand All @@ -24,9 +34,18 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
defaultKernelId,
...modalProps
}) => {
'use memo';
const baiClient = useSuspendedBackendaiClient();
const { token } = theme.useToken();

const [autoRefreshEnabled, setAutoRefreshEnabled] = useBAISettingUserState(
'container_log_auto_refresh_enabled',
);
const [autoRefreshInterval, setAutoRefreshInterval] = useBAISettingUserState(
'container_log_auto_refresh_interval',
);
const autoRefreshIntervalValue = autoRefreshInterval || 5_000;

const session = useFragment(
graphql`
fragment ContainerLogModalFragment on ComputeSessionNode {
Expand Down Expand Up @@ -86,7 +105,7 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
.get_logs(session?.row_id, session?.access_key, selectedKernelId, 15000)
.then((req: any) => req.result.logs);
},
staleTime: 5000,
staleTime: autoRefreshIntervalValue,
});

const [lastLineNumbers, { resetPrevious: resetPreviousLineNumber }] =
Expand Down Expand Up @@ -174,27 +193,6 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
.value()}
/>
<Divider type="vertical" />
{/* Request logs
<Select
value={logSize}
options={[
{
label: 'last 100 lines',
value: 100,
},
{
label: 'Full logs',
value: 'full',
},
]}
onChange={(value) => {
setLogSize(value);
if(value!=='full'){
resetPreviousLineNumber();
}
refetch();
}}
></Select> */}
<Tooltip title={t('button.Download')}>
<Button
size="middle"
Expand All @@ -217,6 +215,29 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
onClick={() => refetch()}
/>
</Tooltip>
<BAIFlex gap="xs" align="center">
<AutoRefreshSwitch
checked={autoRefreshEnabled}
onChange={setAutoRefreshEnabled}
interval={isRefetching ? null : autoRefreshIntervalValue}
onRefresh={() => {
refetch();
}}
>
{t('button.AutoRefresh')}:
</AutoRefreshSwitch>
<InputNumber
min={3}
value={(autoRefreshIntervalValue ?? 1000) / 1000}
onChange={(value) => {
if (typeof value === 'number') {
setAutoRefreshInterval(value * 1000);
}
}}
addonAfter={t('time.Sec')}
style={{ maxWidth: 150 }}
/>
</BAIFlex>
</BAIFlex>

<div
Expand Down
2 changes: 2 additions & 0 deletions react/src/hooks/useBAISetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface UserSettings {

classic_session_list?: boolean; // `experimental_neo_session_list` has been replaced with `classic_session_list`
max_concurrent_uploads?: number;
container_log_auto_refresh_enabled?: boolean;
container_log_auto_refresh_interval?: number;
}

export type SessionHistory = {
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Hinzufügen",
"Apply": "Bewerbung",
"AutoRefresh": "Automatische Aktualisierung",
"Cancel": "Stornieren",
"Clear": "Löschen",
"ClearLogs": "Protokolle löschen",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Προσθήκη",
"Apply": "Εφαρμογή",
"AutoRefresh": "Αυτόματη ανανέωση",
"Cancel": "Ματαίωση",
"Clear": "Διαγράφω",
"ClearLogs": "Εκκαθάριση αρχείων καταγραφής",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"button": {
"Add": "Add",
"Apply": "Apply",
"AutoRefresh": "Auto refresh",
"Cancel": "Cancel",
"Clear": "Clear",
"ClearLogs": "Clear Logs",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Añadir",
"Apply": "Solicitar",
"AutoRefresh": "Actualización automática",
"Cancel": "Cancelar",
"Clear": "Borrar",
"ClearLogs": "Borrar registros",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Lisää",
"Apply": "Hae",
"AutoRefresh": "Automaattinen päivitys",
"Cancel": "Peruuta",
"Clear": "Poistaa",
"ClearLogs": "Tyhjennä lokit",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Ajouter",
"Apply": "Appliquer",
"AutoRefresh": "Actualisation automatique",
"Cancel": "Annuler",
"Clear": "Supprimer",
"ClearLogs": "Effacer les journaux",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Tambah",
"Apply": "Menerapkan",
"AutoRefresh": "Penyegaran otomatis",
"Cancel": "Batalkan",
"Clear": "Menghapus",
"ClearLogs": "Hapus Log",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Inserisci",
"Apply": "Applicare",
"AutoRefresh": "Aggiornamento automatico",
"Cancel": "Annulla",
"Clear": "Eliminare",
"ClearLogs": "Cancella registri",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "追加",
"Apply": "応募する",
"AutoRefresh": "自動更新",
"Cancel": "キャンセル",
"Clear": "消去",
"ClearLogs": "ログをクリアする",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"button": {
"Add": "추가",
"Apply": "적용",
"AutoRefresh": "자동 새로고침",
"Cancel": "취소",
"Clear": "삭제",
"ClearLogs": "로그 삭제",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/mn.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Нэмэх",
"Apply": "Өргөдөл гаргах",
"AutoRefresh": "Автоматаар шинэчлэх",
"Cancel": "Цуцлах",
"Clear": "Устгах",
"ClearLogs": "Бүртгэлийг арилгах",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/ms.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Tambah",
"Apply": "Mohon",
"AutoRefresh": "Penyegaran automatik",
"Cancel": "Batal",
"Clear": "Padam",
"ClearLogs": "Kosongkan Log",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Dodaj",
"Apply": "Zastosuj",
"AutoRefresh": "Automatyczne odświeżanie",
"Cancel": "Anuluj",
"Clear": "Usuwać",
"ClearLogs": "Wyczyść dzienniki",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Adicionar",
"Apply": "Aplicar",
"AutoRefresh": "Atualização automática",
"Cancel": "Cancelar",
"Clear": "Excluir",
"ClearLogs": "Limpar registros",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Adicionar",
"Apply": "Aplicar",
"AutoRefresh": "Atualização automática",
"Cancel": "Cancelar",
"Clear": "Excluir",
"ClearLogs": "Limpar registros",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Добавлять",
"Apply": "Применить",
"AutoRefresh": "Автообновление",
"Cancel": "Отмена",
"Clear": "Удалить",
"ClearLogs": "Очистить журналы",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "เพิ่ม",
"Apply": "นำมาใช้",
"AutoRefresh": "รีเฟรชอัตโนมัติ",
"Cancel": "ยกเลิก",
"Clear": "ล้าง",
"ClearLogs": "ล้างบันทึก",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Ekle",
"Apply": "Başvurmak",
"AutoRefresh": "Otomatik yenileme",
"Cancel": "İptal etmek",
"Clear": "Silmek",
"ClearLogs": "Günlükleri Temizle",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "Thêm vào",
"Apply": "Áp dụng",
"AutoRefresh": "Tự động làm mới",
"Cancel": "Huỷ bỏ",
"Clear": "Xóa bỏ",
"ClearLogs": "Xóa các bản ghi",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "添加",
"Apply": "申请",
"AutoRefresh": "自动刷新",
"Cancel": "取消",
"Clear": "删除",
"ClearLogs": "清除日志",
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"button": {
"Add": "添加",
"Apply": "申请",
"AutoRefresh": "自動重新整理",
"Cancel": "取消",
"Clear": "刪除",
"ClearLogs": "清除日誌",
Expand Down
Loading