aminghadersohi commented on code in PR #44851:
URL: https://github.com/apache/superset/pull/44851#discussion_r4213148667
##########
superset-frontend/src/features/semanticViews/SemanticViewEditModal.tsx:
##########
@@ -188,15 +218,102 @@ export default function SemanticViewEditModal({
});
addSuccessToast?.(t('Semantic view updated'));
onSave();
- onHide();
+ if (isCurrent()) handleHide();
} catch (error) {
const clientError = await getClientErrorObject(error);
addDangerToast?.(
clientError.error ||
t('An error occurred while saving the semantic view'),
);
} finally {
- setSaving(false);
+ if (isCurrent()) {
+ busy.current = false;
+ setSaving(false);
+ }
+ }
+ };
+
+ const reloadFields = async (
+ viewId: number,
+ changed: boolean | null,
+ isCurrent: () => boolean,
+ ) => {
+ setSyncState({ status: 'reloading', changed });
+ try {
+ const { json } = await SupersetClient.get({
+ endpoint: `/api/v1/semantic_view/${viewId}/structure`,
+ });
+ if (!isCurrent()) return;
+ setStructure(json.result);
+ await onMetadataSync?.(isCurrent);
+ if (!isCurrent()) return;
+ if (structure?.uuid) dispatch(confirmReload(structure.uuid));
+ setSyncState({ status: 'done', changed });
+ } catch {
+ if (isCurrent()) setSyncState({ status: 'reload-error', changed });
+ }
+ };
+
+ const handleSync = async () => {
+ if (
+ !semanticView ||
+ !structure?.uuid ||
+ structure.can_refresh_metadata !== true ||
+ busy.current ||
+ reloadOnly
+ )
+ return;
+ busy.current = true;
+ generation.current += 1;
+ const requestGeneration = generation.current;
+ const isCurrent = () => requestGeneration === generation.current;
+ setSyncState({ status: 'syncing' });
+ try {
+ const { json } = await SupersetClient.post({
+ endpoint: `/api/v1/semantic_view/${structure.uuid}/refresh_metadata/`,
+ jsonPayload: {},
+ });
+ if (!isCurrent()) return;
+ await reloadFields(
+ semanticView.id,
+ json.result.status === 'changed',
+ isCurrent,
+ );
+ } catch (error) {
+ if (!isCurrent()) return;
+ const { message, reloadRequired } = await metadataSyncError(error);
+ if (!isCurrent()) return;
+ if (reloadRequired)
+ dispatch(markUnconfirmed({ uuid: structure.uuid, message }));
Review Comment:
Closing the editor while the sync POST is pending returns before
`markUnconfirmed`, so a late `indeterminate` result is lost and reopening shows
Sync enabled with no warning. Recording the lock first keeps it:
```suggestion
} catch (error) {
const { message, reloadRequired } = await metadataSyncError(error);
if (reloadRequired)
dispatch(markUnconfirmed({ uuid: structure.uuid, message }));
if (!isCurrent()) return;
```
--
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]