Skip to content

Commit 07fbece

Browse files
authored
Add tooltip for Publish button (#30)
1 parent 56bb3d9 commit 07fbece

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

apps/serializers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class Meta:
114114
last_modified_by_email = serializers.SerializerMethodField()
115115
template = serializers.SerializerMethodField()
116116
visibility = serializers.SerializerMethodField()
117+
has_live_version = serializers.SerializerMethodField()
117118

118119
def get_logo(self, obj):
119120
profile = Profile.objects.get(user=obj.owner)
@@ -142,6 +143,12 @@ def get_data(self, obj):
142143
if app_data:
143144
return app_data.data
144145
return None
146+
147+
def get_has_live_version(self, obj):
148+
app_datas = AppData.objects.filter(
149+
app_uuid=obj.uuid, is_draft=False).first()
150+
return app_datas is not None
151+
145152

146153
def get_app_type_name(self, obj):
147154
return obj.type.name
@@ -237,7 +244,7 @@ class Meta:
237244
'logo', 'is_shareable', 'has_footer', 'domain', 'visibility', 'accessible_by',
238245
'access_permission', 'last_modified_by_email', 'owner_email', 'web_config',
239246
'slack_config', 'discord_config', 'app_type_name', 'processors', 'template',
240-
'read_accessible_by', 'write_accessible_by'
247+
'read_accessible_by', 'write_accessible_by', 'has_live_version'
241248
]
242249

243250

client/src/pages/AppEdit.jsx

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Paper,
2222
Stack,
2323
SvgIcon,
24+
Tooltip,
2425
} from "@mui/material";
2526
import ChangeHistoryIcon from "@mui/icons-material/ChangeHistory";
2627
import EditIcon from "@mui/icons-material/Edit";
@@ -401,27 +402,44 @@ export default function AppEditPage(props) {
401402
app={app}
402403
setIsPublished={setIsPublished}
403404
/>
405+
404406
{appId && app && (
405-
<Button
406-
variant="contained"
407-
color="success"
408-
style={{ textTransform: "none" }}
409-
disabled={app.owner_email !== profile.user_email}
410-
startIcon={
411-
isPublished ? (
412-
<UnpublishedIcon />
413-
) : (
414-
<PublishedWithChangesIcon />
415-
)
416-
}
417-
onClick={() =>
418-
isPublished
419-
? setShowUnpublishModal(true)
420-
: setShowPublishModal(true)
407+
<Tooltip
408+
arrow={true}
409+
title={
410+
app?.has_live_version
411+
? isPublished
412+
? "Unpublish App"
413+
: "Publish App"
414+
: "Please save App before publishing"
421415
}
422416
>
423-
{isPublished ? "Unpublish" : "Publish"}
424-
</Button>
417+
<span>
418+
<Button
419+
variant="contained"
420+
color="success"
421+
style={{ textTransform: "none" }}
422+
disabled={
423+
app.owner_email !== profile.user_email ||
424+
!app?.has_live_version
425+
}
426+
startIcon={
427+
isPublished ? (
428+
<UnpublishedIcon />
429+
) : (
430+
<PublishedWithChangesIcon />
431+
)
432+
}
433+
onClick={() =>
434+
isPublished
435+
? setShowUnpublishModal(true)
436+
: setShowPublishModal(true)
437+
}
438+
>
439+
{isPublished ? "Unpublish" : "Publish"}
440+
</Button>
441+
</span>
442+
</Tooltip>
425443
)}
426444
</Stack>
427445
</Stack>

0 commit comments

Comments
 (0)