mirror of https://github.com/apache/superset.git
keep modal open on error, utilize useEffect (#12360)
This commit is contained in:
parent
908c0f2b52
commit
628a9b2b7b
|
@ -110,7 +110,11 @@ const CssTemplateModal: FunctionComponent<CssTemplateModalProps> = ({
|
||||||
const update_id = currentCssTemplate.id;
|
const update_id = currentCssTemplate.id;
|
||||||
delete currentCssTemplate.id;
|
delete currentCssTemplate.id;
|
||||||
delete currentCssTemplate.created_by;
|
delete currentCssTemplate.created_by;
|
||||||
updateResource(update_id, currentCssTemplate).then(() => {
|
updateResource(update_id, currentCssTemplate).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (onCssTemplateAdd) {
|
if (onCssTemplateAdd) {
|
||||||
onCssTemplateAdd();
|
onCssTemplateAdd();
|
||||||
}
|
}
|
||||||
|
@ -120,7 +124,11 @@ const CssTemplateModal: FunctionComponent<CssTemplateModalProps> = ({
|
||||||
}
|
}
|
||||||
} else if (currentCssTemplate) {
|
} else if (currentCssTemplate) {
|
||||||
// Create
|
// Create
|
||||||
createResource(currentCssTemplate).then(() => {
|
createResource(currentCssTemplate).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (onCssTemplateAdd) {
|
if (onCssTemplateAdd) {
|
||||||
onCssTemplateAdd();
|
onCssTemplateAdd();
|
||||||
}
|
}
|
||||||
|
@ -166,29 +174,35 @@ const CssTemplateModal: FunctionComponent<CssTemplateModalProps> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
if (
|
useEffect(() => {
|
||||||
isEditMode &&
|
if (
|
||||||
(!currentCssTemplate ||
|
isEditMode &&
|
||||||
!currentCssTemplate.id ||
|
(!currentCssTemplate ||
|
||||||
(cssTemplate && cssTemplate.id !== currentCssTemplate.id) ||
|
!currentCssTemplate.id ||
|
||||||
(isHidden && show))
|
(cssTemplate && cssTemplate.id !== currentCssTemplate.id) ||
|
||||||
) {
|
(isHidden && show))
|
||||||
if (cssTemplate && cssTemplate.id !== null && !loading) {
|
) {
|
||||||
const id = cssTemplate.id || 0;
|
if (cssTemplate && cssTemplate.id !== null && !loading) {
|
||||||
|
const id = cssTemplate.id || 0;
|
||||||
|
|
||||||
fetchResource(id).then(() => {
|
fetchResource(id);
|
||||||
setCurrentCssTemplate(resource);
|
}
|
||||||
|
} else if (
|
||||||
|
!isEditMode &&
|
||||||
|
(!currentCssTemplate || currentCssTemplate.id || (isHidden && show))
|
||||||
|
) {
|
||||||
|
setCurrentCssTemplate({
|
||||||
|
template_name: '',
|
||||||
|
css: '',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (
|
}, [cssTemplate]);
|
||||||
!isEditMode &&
|
|
||||||
(!currentCssTemplate || currentCssTemplate.id || (isHidden && show))
|
useEffect(() => {
|
||||||
) {
|
if (resource) {
|
||||||
setCurrentCssTemplate({
|
setCurrentCssTemplate(resource);
|
||||||
template_name: '',
|
}
|
||||||
css: '',
|
}, [resource]);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
Loading…
Reference in New Issue