mikebridge commented on code in PR #45524:
URL: https://github.com/apache/superset/pull/45524#discussion_r4330992149


##########
superset-frontend/src/features/semanticViews/AddSemanticViewModal.tsx:
##########
@@ -610,47 +623,65 @@ export default function AddSemanticViewModal({
           configuration: runtimeData,
         }));
 
-      const { json } = await SupersetClient.post({
-        endpoint: '/api/v1/semantic_view/',
-        jsonPayload: { views: viewsToCreate },
-      });
-
-      const created = Array.isArray(json?.result?.created)
-        ? json.result.created
-        : [];
-      const errors = Array.isArray(json?.result?.errors)
-        ? json.result.errors
-        : [];
+      let body: unknown;
+      try {
+        const { json } = await SupersetClient.post({
+          endpoint: '/api/v1/semantic_view/',
+          jsonPayload: { views: viewsToCreate },
+        });
+        body = json;
+      } catch (error) {
+        // SupersetClient rejects non-2xx responses before parsing their body.
+        if (
+          !isRecord(error) ||
+          error.status !== 422 ||
+          typeof error.json !== 'function'
+        ) {
+          throw error;
+        }
+        body = await error.json();
+      }
+      if (gen !== fetchGenRef.current) return;

Review Comment:
   Fixed in 6aee861628. A completed creation still refreshes the dataset list 
and reports success after the modal closes; the generation guard only prevents 
stale modal-local updates. The close/reopen regression test pins both sides.



##########
superset-frontend/src/features/semanticViews/AddSemanticViewModal.tsx:
##########
@@ -726,12 +757,32 @@ export default function AddSemanticViewModal({
       saveLoading={saving}
     >
       <ModalContent>
+        {creationErrors.length > 0 && (

Review Comment:
   Fixed in 6aee861628. An actual runtime configuration change clears the 
previous creation errors; an unchanged form notification does not. Added a 
rendered-form regression for changing configuration after a failed save.



##########
superset-frontend/src/features/semanticViews/AddSemanticViewModal.tsx:
##########
@@ -726,12 +757,32 @@ export default function AddSemanticViewModal({
       saveLoading={saving}
     >
       <ModalContent>
+        {creationErrors.length > 0 && (
+          <Alert
+            type="error"
+            showIcon
+            message={t('Some semantic views could not be added')}
+            description={
+              <List

Review Comment:
   Fixed in 6aee861628. The details are in a bounded, keyboard-scrollable 
region. Batches over three failures get a count-only toast, with every name and 
detail retained in the list. Added a 100-failure case.



##########
superset-frontend/src/features/semanticViews/AddSemanticViewModal.tsx:
##########
@@ -610,47 +623,65 @@ export default function AddSemanticViewModal({
           configuration: runtimeData,
         }));
 
-      const { json } = await SupersetClient.post({
-        endpoint: '/api/v1/semantic_view/',
-        jsonPayload: { views: viewsToCreate },
-      });
-
-      const created = Array.isArray(json?.result?.created)
-        ? json.result.created
-        : [];
-      const errors = Array.isArray(json?.result?.errors)
-        ? json.result.errors
-        : [];
+      let body: unknown;
+      try {
+        const { json } = await SupersetClient.post({
+          endpoint: '/api/v1/semantic_view/',
+          jsonPayload: { views: viewsToCreate },
+        });
+        body = json;
+      } catch (error) {
+        // SupersetClient rejects non-2xx responses before parsing their body.
+        if (
+          !isRecord(error) ||
+          error.status !== 422 ||
+          typeof error.json !== 'function'
+        ) {
+          throw error;
+        }
+        body = await error.json();
+      }
+      if (gen !== fetchGenRef.current) return;
+      const { created, errors } = parseCreationResult(body);
+      setCreationErrors(errors);
 
       if (created.length > 0) {
+        setAvailableViews(previous =>
+          previous.map(view =>
+            created.includes(view.name)
+              ? { ...view, already_added: true }
+              : view,
+          ),
+        );
+        setSelectedViewNames(previous =>
+          previous.filter(name => !created.includes(name)),
+        );
         addSuccessToast(t('%s semantic view(s) added', created.length));
+        onSuccess();
       }
 
       if (errors.length > 0) {
-        const failedNames = errors
-          .map((error: { name?: string }) => error?.name)
-          .filter((name: string | undefined): name is string => !!name);
+        const failedNames = errors.map(error => error.name).filter(Boolean);
         addDangerToast(
           failedNames.length > 0
             ? t(
                 '%s semantic view(s) failed to add: %s',
-                errors.length,
+                failedNames.length,

Review Comment:
   Fixed in 6aee861628. The count comes from server error records, including 
unnamed ones, rather than the names shown in the toast. Synthetic 
malformed-response feedback is excluded. Added unnamed and mixed named/unnamed 
cases; all 44 modal tests pass.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to