LiteSun commented on code in PR #3437:
URL: https://github.com/apache/apisix-dashboard/pull/3437#discussion_r3628772184
##########
src/components/form-slice/FormPartStreamRoute/util.ts:
##########
@@ -15,28 +15,33 @@
* limitations under the License.
*/
import { produce } from 'immer';
-import { pipe } from 'rambdax';
import { produceRmEmptyUpstreamFields } from
'@/components/form-slice/FormPartUpstream/util';
import { produceRmUpstreamWhenHas } from '@/utils/form-producer';
+import { pipeProduce } from '@/utils/producer';
import type { StreamRoutePostType } from './schema';
-export const produceStreamRoute = (val: StreamRoutePostType) =>
- pipe(
- produceRmEmptyUpstreamFields,
- (produceRmUpstreamWhenHas('service_id', 'upstream_id') as unknown as (
- d: StreamRoutePostType
- ) => StreamRoutePostType),
- produce((draft: StreamRoutePostType) => {
- // Stream Routes do not support name and status
- const d = draft as StreamRoutePostType & { name?: string; status?:
number };
- delete d.name;
- delete d.status;
+/**
+ * Shared by BOTH the create and edit paths — stream routes used to be the
+ * only resource whose two paths ran different cleaning pipelines (create
+ * skipped pipeProduce entirely; edit borrowed the HTTP-route producer).
+ * pipeProduce supplies the __-flag removal, empty-value cleaning and
+ * empty-plugin restore every other resource gets (#3417).
+ */
+export const produceStreamRoute = pipeProduce(
Review Comment:
This switches Stream Route creation to the current `pipeProduce`, which
deep-cleans empty members inside partially non-empty plugin configs and drops
inline `upstream.discovery_args: {}`. Those are the behaviors fixed separately
by #3438. If this PR lands first, creating a Stream Route can silently change
valid user input. Please either make this PR depend on/rebase onto #3438, or
include the preservation change and a Stream Route create regression test here.
##########
src/components/form-slice/FormPartStreamRoute/util.ts:
##########
@@ -15,28 +15,33 @@
* limitations under the License.
*/
import { produce } from 'immer';
-import { pipe } from 'rambdax';
import { produceRmEmptyUpstreamFields } from
'@/components/form-slice/FormPartUpstream/util';
import { produceRmUpstreamWhenHas } from '@/utils/form-producer';
+import { pipeProduce } from '@/utils/producer';
import type { StreamRoutePostType } from './schema';
-export const produceStreamRoute = (val: StreamRoutePostType) =>
- pipe(
- produceRmEmptyUpstreamFields,
- (produceRmUpstreamWhenHas('service_id', 'upstream_id') as unknown as (
- d: StreamRoutePostType
- ) => StreamRoutePostType),
- produce((draft: StreamRoutePostType) => {
- // Stream Routes do not support name and status
- const d = draft as StreamRoutePostType & { name?: string; status?:
number };
- delete d.name;
- delete d.status;
+/**
+ * Shared by BOTH the create and edit paths — stream routes used to be the
+ * only resource whose two paths ran different cleaning pipelines (create
+ * skipped pipeProduce entirely; edit borrowed the HTTP-route producer).
+ * pipeProduce supplies the __-flag removal, empty-value cleaning and
+ * empty-plugin restore every other resource gets (#3417).
+ */
+export const produceStreamRoute = pipeProduce(
+ produceRmUpstreamWhenHas('service_id', 'upstream_id'),
+ produceRmEmptyUpstreamFields,
+ produce((draft: StreamRoutePostType) => {
+ // the form never renders name/status for stream routes; strip them in
+ // case values arrive via reused generic components
+ const d = draft as StreamRoutePostType & { name?: string; status?: number
};
+ delete d.name;
Review Comment:
The comment correctly notes that the current Admin API accepts Stream Route
`name`, but the producer still deletes it and the schema still omits it. A
Stream Route created through the API with a name will therefore lose that name
after an edit-save in the Dashboard. Please preserve/register `name` and only
strip fields that the resource actually does not support.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]