lxbme commented on code in PR #3437:
URL: https://github.com/apache/apisix-dashboard/pull/3437#discussion_r3635511897


##########
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:
   Fixed in 77a7b2ad. Verified against a live gateway: the Admin API accepts 
`name`/`desc`/`labels` on a stream route (201) and rejects `status` (400). The 
base `StreamRoute` schema now omits only `status` (the edit form resolves 
against it, which was why the stored name was stripped before submit), the 
producer keeps `name` and strips only `status`, and the form renders the name 
input on create and edit. Unit test: producer keeps name / strips status. e2e: 
an API-created named stream route keeps its name across a no-op edit-save. This 
also removed a create/edit asymmetry (create resolved against a schema with 
`name`, edit against one without).
   



-- 
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]

Reply via email to