feat: Support for using regular expressions on the log page #707 (#959)

This commit is contained in:
lxk955 2024-04-30 22:59:42 +08:00 committed by GitHub
parent 41762be3a5
commit 80ee7aef8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 5 deletions

View File

@ -187,5 +187,7 @@
"Portable Updater Error": "The portable version does not support in-app updates. Please manually download and replace it",
"Tun Mode Info": "The Tun mode requires granting core-related permissions. Please enable service mode before using it",
"System and Mixed Can Only be Used in Service Mode": "System and Mixed Can Only be Used in Service Mode"
"System and Mixed Can Only be Used in Service Mode": "System and Mixed Can Only be Used in Service Mode",
"Use Regular Expression": "Use Regular Expression"
}

View File

@ -187,5 +187,7 @@
"Portable Updater Error": "Портативная версия не поддерживает обновление внутри приложения, пожалуйста, скачайте и замените вручную",
"Tun Mode Info": "Режим туннеля требует предоставления разрешений, связанных с ядром. Пожалуйста, включите сервисный режим перед его использованием",
"System and Mixed Can Only be Used in Service Mode": "Система и смешанные могут использоваться только в сервисном режиме"
"System and Mixed Can Only be Used in Service Mode": "Система и смешанные могут использоваться только в сервисном режиме",
"Use Regular Expression": "Использование регулярных выражений"
}

View File

@ -187,5 +187,7 @@
"Portable Updater Error": "便携版不支持应用内更新,请手动下载替换",
"Tun Mode Info": "Tun模式需要授予内核相关权限使用前请先开启服务模式",
"System and Mixed Can Only be Used in Service Mode": "System和Mixed只能在服务模式下使用"
"System and Mixed Can Only be Used in Service Mode": "System和Mixed只能在服务模式下使用",
"Use Regular Expression": "使用正则表达式"
}

View File

@ -47,8 +47,27 @@ const LogPage = () => {
const isDark = theme.palette.mode === "dark";
const [logState, setLogState] = useState("all");
const [filterText, setFilterText] = useState("");
const [useRegexSearch, setUseRegexSearch] = useState(true);
const [hasInputError, setInputError] = useState(false);
const [inputHelperText, setInputHelperText] = useState("");
const filterLogs = useMemo(() => {
setInputHelperText("");
setInputError(false);
if (useRegexSearch) {
try {
const regex = new RegExp(filterText);
return logData.filter((data) => {
return (
regex.test(data.payload) &&
(logState === "all" ? true : data.type.includes(logState))
);
});
} catch (err: any) {
setInputHelperText(err.message.substring(0, 60));
setInputError(true);
return logData;
}
}
return logData.filter((data) => {
return (
data.payload.includes(filterText) &&
@ -91,7 +110,7 @@ const LogPage = () => {
pt: 1,
mb: 0.5,
mx: "10px",
height: "36px",
height: "48px",
display: "flex",
alignItems: "center",
}}
@ -107,8 +126,31 @@ const LogPage = () => {
</StyledSelect>
<BaseStyledTextField
error={hasInputError}
value={filterText}
onChange={(e) => setFilterText(e.target.value)}
helperText={inputHelperText}
placeholder={t("Filter conditions")}
InputProps={{
sx: { pr: 1 },
endAdornment: (
<IconButton
sx={{ p: 0.5 }}
title={t("Use Regular Expression")}
style={{
backgroundColor: useRegexSearch
? "rgba(20, 20, 20, 0.2)"
: "rgba(30, 0, 0, 0.0)",
fontSize: "150%",
fontWeight: "800",
borderRadius: "10%",
}}
onClick={() => setUseRegexSearch(!useRegexSearch)}
>
.*
</IconButton>
),
}}
/>
</Box>