From 9dac4cfa22dd5fb36a4684d1194be0f759a86191 Mon Sep 17 00:00:00 2001 From: Baoyuan Date: Sat, 7 Aug 2021 00:25:22 +0800 Subject: [PATCH 1/2] fix: delete null value in request body --- .../upstream/create_and_delete_upstream.spec.js | 2 ++ web/src/app.tsx | 15 +++++++++++++++ web/src/components/Upstream/locales/en-US.ts | 1 + 3 files changed, 18 insertions(+) diff --git a/web/cypress/integration/upstream/create_and_delete_upstream.spec.js b/web/cypress/integration/upstream/create_and_delete_upstream.spec.js index 31aba9f428..5e6cd9284e 100644 --- a/web/cypress/integration/upstream/create_and_delete_upstream.spec.js +++ b/web/cypress/integration/upstream/create_and_delete_upstream.spec.js @@ -58,6 +58,8 @@ context('Create and Delete Upstream', () => { cy.get(selector.nodes_0_host).type(data.ip1); cy.get(selector.nodes_0_port).clear().type('7000'); cy.get(selector.nodes_0_weight).clear().type(1); + cy.get('#custom_checks_active').click(); + cy.get('#checks_active_port').clear(); cy.contains('Next').click(); cy.get(selector.input).should('be.disabled'); cy.contains('Submit').click(); diff --git a/web/src/app.tsx b/web/src/app.tsx index a152e33148..f2afda6d78 100644 --- a/web/src/app.tsx +++ b/web/src/app.tsx @@ -18,6 +18,7 @@ import React from 'react'; import { history } from 'umi'; import type { RequestConfig } from 'umi'; import type { Settings as LayoutSettings } from '@ant-design/pro-layout'; +import { isPlainObject } from 'lodash'; import RightContent from '@/components/RightContent'; import Footer from '@/components/Footer'; @@ -55,6 +56,17 @@ export const layout = ({ initialState }: { initialState: { settings?: LayoutSett }; }; +/* eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["obj"] }] */ +const nullValueFilter = (obj: Record) => { + Object.keys(obj).forEach((key) => { + if (isPlainObject(obj[key])) { + nullValueFilter(obj[key]); + } else if (obj[key] === null) { + delete obj[key]; + } + }); +}; + export const request: RequestConfig = { prefix: '/apisix/admin', errorHandler, @@ -62,6 +74,9 @@ export const request: RequestConfig = { requestInterceptors: [ (url, options) => { const newOptions = { ...options }; + if (newOptions.data) { + nullValueFilter(newOptions.data); + } newOptions.headers = { ...options.headers, Authorization: localStorage.getItem('token') || '', diff --git a/web/src/components/Upstream/locales/en-US.ts b/web/src/components/Upstream/locales/en-US.ts index 6bb9cb6e72..f865624412 100644 --- a/web/src/components/Upstream/locales/en-US.ts +++ b/web/src/components/Upstream/locales/en-US.ts @@ -60,6 +60,7 @@ export default { 'component.upstream.fields.checks.active.http_path': 'HTTP Path', 'component.upstream.fields.checks.active.http_path.tooltip': 'The path that should be used when issuing the HTTP GET request to the target. The default value is /.', + 'component.upstream.fields.checks.active.http_path.placeholder': 'Please enter HTTP path', 'component.upstream.fields.checks.active.https_verify_certificate': 'Verify HTTPs Certificate', 'component.upstream.fields.checks.active.https_verify_certificate.tooltip': From f6a67e16ee07bceade3f3fc9a6e4ef9bd70d81c4 Mon Sep 17 00:00:00 2001 From: Baoyuan Date: Sat, 7 Aug 2021 15:39:56 +0800 Subject: [PATCH 2/2] fix: replace with Object.entries --- web/cypress/integration/route/search-route.spec.js | 2 +- web/src/app.tsx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/web/cypress/integration/route/search-route.spec.js b/web/cypress/integration/route/search-route.spec.js index 77b5def307..167e0b285b 100644 --- a/web/cypress/integration/route/search-route.spec.js +++ b/web/cypress/integration/route/search-route.spec.js @@ -95,7 +95,7 @@ context('Create and Search Route', () => { }); }); - cy.contains('Next').click(); + cy.contains('button', 'Next').should('not.be.disabled').click(); cy.get(selector.nodes_0_host).type(data.host2, { timeout, }); diff --git a/web/src/app.tsx b/web/src/app.tsx index f2afda6d78..421febe45d 100644 --- a/web/src/app.tsx +++ b/web/src/app.tsx @@ -58,10 +58,10 @@ export const layout = ({ initialState }: { initialState: { settings?: LayoutSett /* eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["obj"] }] */ const nullValueFilter = (obj: Record) => { - Object.keys(obj).forEach((key) => { - if (isPlainObject(obj[key])) { - nullValueFilter(obj[key]); - } else if (obj[key] === null) { + Object.entries(obj).forEach(([key, value]) => { + if (isPlainObject(value)) { + nullValueFilter(value); + } else if ([null, undefined].includes(value)) { delete obj[key]; } });