diff --git a/web/src/utils/common.js b/web/src/utils/common.js index e9890fc5..32059e94 100644 --- a/web/src/utils/common.js +++ b/web/src/utils/common.js @@ -201,3 +201,23 @@ export function removeTrailingSlash(url) { return url; } } + +export function trims(values) { + if (typeof values === 'string') { + return values.trim(); + } + + if (Array.isArray(values)) { + return values.map((value) => trims(value)); + } + + if (typeof values === 'object') { + let newValues = {}; + for (let key in values) { + newValues[key] = trims(values[key]); + } + return newValues; + } + + return values; +} diff --git a/web/src/views/Channel/component/EditModal.js b/web/src/views/Channel/component/EditModal.js index b9339c54..2814ff2b 100644 --- a/web/src/views/Channel/component/EditModal.js +++ b/web/src/views/Channel/component/EditModal.js @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react'; import { CHANNEL_OPTIONS } from 'constants/ChannelConstants'; import { useTheme } from '@mui/material/styles'; import { API } from 'utils/api'; -import { showError, showSuccess } from 'utils/common'; +import { showError, showSuccess, trims } from 'utils/common'; import { Dialog, DialogTitle, @@ -171,6 +171,8 @@ const EditModal = ({ open, channelId, onCancel, onOk, groupOptions }) => { const submit = async (values, { setErrors, setStatus, setSubmitting }) => { setSubmitting(true); + console.log(values); + values = trims(values); if (values.base_url && values.base_url.endsWith('/')) { values.base_url = values.base_url.slice(0, values.base_url.length - 1); } diff --git a/web/src/views/Channel/index.js b/web/src/views/Channel/index.js index 99200313..da979780 100644 --- a/web/src/views/Channel/index.js +++ b/web/src/views/Channel/index.js @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react'; -import { showError, showSuccess, showInfo } from 'utils/common'; +import { showError, showSuccess, showInfo, trims } from 'utils/common'; import { useTheme } from '@mui/material/styles'; import Table from '@mui/material/Table'; @@ -256,6 +256,7 @@ export default function ChannelPage() { const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => { setSearching(true); + keyword = trims(keyword); const data = await fetchChannelData(page, rowsPerPage, keyword, order, orderBy); if (data) { diff --git a/web/src/views/Log/component/TableToolBar.js b/web/src/views/Log/component/TableToolBar.js index 2498babf..def609f7 100644 --- a/web/src/views/Log/component/TableToolBar.js +++ b/web/src/views/Log/component/TableToolBar.js @@ -101,12 +101,12 @@ export default function TableToolBar({ filterName, handleFilterName, userIsAdmin - 类型 + 类型