修复任务视图bug (#1612)

* 修复了视图无排序时无法再次修改的问题

* 修复在视图管理中编辑、新建视图点击确定后不能关闭页面的问题

* 修复#1611 避免查询条件被覆盖

* 修复视图筛选不能正确处理`不包含`
This commit is contained in:
景大侠 2022-09-06 00:25:05 +08:00 committed by GitHub
parent 687d16e21b
commit daf6f94c51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 11 deletions

View File

@ -28,7 +28,7 @@ export default (app: Router) => {
celebrate({ celebrate({
body: Joi.object({ body: Joi.object({
name: Joi.string().required(), name: Joi.string().required(),
sorts: Joi.array().optional(), sorts: Joi.array().optional().allow(null),
filters: Joi.array().optional(), filters: Joi.array().optional(),
}), }),
}), }),
@ -49,7 +49,7 @@ export default (app: Router) => {
body: Joi.object({ body: Joi.object({
name: Joi.string().required(), name: Joi.string().required(),
id: Joi.number().required(), id: Joi.number().required(),
sorts: Joi.array().optional(), sorts: Joi.array().optional().allow(null),
filters: Joi.array().optional(), filters: Joi.array().optional(),
}), }),
}), }),

View File

@ -115,18 +115,25 @@ export default class CronService {
private formatViewQuery(query: any, viewQuery: any) { private formatViewQuery(query: any, viewQuery: any) {
if (viewQuery.filters && viewQuery.filters.length > 0) { if (viewQuery.filters && viewQuery.filters.length > 0) {
if (!query[Op.and]) {
query[Op.and] = [];
}
for (const col of viewQuery.filters) { for (const col of viewQuery.filters) {
const { property, value, operation } = col; const { property, value, operation } = col;
let q: any = {};
let operate2 = null;
let operate = null; let operate = null;
switch (operation) { switch (operation) {
case 'Reg': case 'Reg':
operate = Op.like; operate = Op.like;
operate2 = Op.or;
break; break;
case 'NotReg': case 'NotReg':
operate = Op.notLike; operate = Op.notLike;
operate2 = Op.and;
break; break;
case 'In': case 'In':
query[Op.or] = [ q[Op.or] = [
{ {
[property]: value, [property]: value,
}, },
@ -136,7 +143,7 @@ export default class CronService {
]; ];
break; break;
case 'Nin': case 'Nin':
query[Op.and] = [ q[Op.and] = [
{ {
[property]: { [property]: {
[Op.notIn]: value, [Op.notIn]: value,
@ -150,20 +157,25 @@ export default class CronService {
default: default:
break; break;
} }
if (operate) { if (operate && operate2) {
query[property] = { q[property] = {
[Op.or]: [ [operate2]: [
{ [operate]: `%${value}%` }, { [operate]: `%${value}%` },
{ [operate]: `%${encodeURIComponent(value)}%` }, { [operate]: `%${encodeURIComponent(value)}%` },
], ],
}; };
} }
query[Op.and].push(q);
} }
} }
} }
private formatSearchText(query: any, searchText: string | undefined) { private formatSearchText(query: any, searchText: string | undefined) {
if (searchText) { if (searchText) {
if (!query[Op.and]) {
query[Op.and] = [];
}
let q: any = {};
const textArray = searchText.split(':'); const textArray = searchText.split(':');
switch (textArray[0]) { switch (textArray[0]) {
case 'name': case 'name':
@ -171,7 +183,7 @@ export default class CronService {
case 'schedule': case 'schedule':
case 'label': case 'label':
const column = textArray[0] === 'label' ? 'labels' : textArray[0]; const column = textArray[0] === 'label' ? 'labels' : textArray[0];
query[column] = { q[column] = {
[Op.or]: [ [Op.or]: [
{ [Op.like]: `%${textArray[1]}%` }, { [Op.like]: `%${textArray[1]}%` },
{ [Op.like]: `%${encodeURIComponent(textArray[1])}%` }, { [Op.like]: `%${encodeURIComponent(textArray[1])}%` },
@ -185,7 +197,7 @@ export default class CronService {
{ [Op.like]: `%${encodeURIComponent(searchText)}%` }, { [Op.like]: `%${encodeURIComponent(searchText)}%` },
], ],
}; };
query[Op.or] = [ q[Op.or] = [
{ {
name: reg, name: reg,
}, },
@ -201,6 +213,7 @@ export default class CronService {
]; ];
break; break;
} }
query[Op.and].push(q);
} }
} }

View File

@ -231,7 +231,10 @@ const ViewManageModal = ({
<Button <Button
key="2" key="2"
type="primary" type="primary"
onClick={() => setIsCreateViewModalVisible(true)} onClick={() => {
setEditedView(null);
setIsCreateViewModalVisible(true);
}}
> >
</Button> </Button>
@ -258,8 +261,8 @@ const ViewManageModal = ({
view={editedView} view={editedView}
visible={isCreateViewModalVisible} visible={isCreateViewModalVisible}
handleCancel={(data) => { handleCancel={(data) => {
cronViewChange(data);
setIsCreateViewModalVisible(false); setIsCreateViewModalVisible(false);
cronViewChange(data);
}} }}
/> />
</Modal> </Modal>