Skip to content

fix: fallback to default avatar in ActivityTree #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drive/api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,4 +940,4 @@ def get_translate():
l["old_name"]: l["name"]
for l in frappe.get_list("Drive File", fields=["old_name", "name"])
if l["old_name"]
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 9 additions & 5 deletions frontend/src/components/ActivityTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
:key="activity"
class="flex items-start justify-start py-3 gap-x-2"
>
<Avatar
size="md"
:image="activity.user_image"
:label="activity.full_name"
/>
<Avatar
shape="circle"
:image="userData.value[row.owner]?.user_image || require('@/assets/images/icons/default-avatar.png')"
label="userData.value[row.owner]?.full_name || row.owner"
size="sm"
/>



<div class="flex flex-col items-start justify-center">
<span class="text-sm text-gray-900">{{ activity.message }}</span>
<span class="text-xs text-gray-600 mb-3">{{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ActivityTreeShare.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
>
<Avatar
size="xs"
:image="activity.share_user_image"
:image="user?.user_image || require('@/assets/images/icons/default-avatar.png')"
:label="
activity.share_user_fullname
? activity.share_user_fullname
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/ListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
:event="rowEvent"
/>
</template>

<script setup>
import {
ListHeader,
Expand Down Expand Up @@ -135,12 +136,11 @@ const selectedColumns = [
? "You"
: userData.value[row.owner]?.full_name || row.owner,
prefix: ({ row }) => {
// Fallback to default avatar if no image is available
return h(Avatar, {
shape: "circle",
image: userData.value[row.owner]?.user_image,
label:
userData.value[row.owner]?.full_name ||
userData.value[row.owner]?.email,
image: userData.value[row.owner]?.user_image || 'path_to_default_avatar_image',
label: userData.value[row.owner]?.full_name || userData.value[row.owner]?.email,
size: "sm",
})
},
Expand Down
85 changes: 74 additions & 11 deletions frontend/src/components/RenameDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
<Dialog v-model="open" :options="{ title: 'Rename', size: 'xs' }">
<template #body-content>
<div class="flex items-center justify-center">
<!-- Input field for new name -->
<Input
v-model="newName"
class="w-full"
type="text"
@keyup.enter="submit"
/>

<!-- File extension display (if any) -->
<span
v-if="entity.file_ext"
:variant="'subtle'"
Expand All @@ -18,28 +21,41 @@
{{ entity.file_ext.toUpperCase().slice(1) }}
</span>
</div>

<!-- Inline error message (if any) -->
<p v-if="errorMsg" class="text-sm text-red-600 mt-2">{{ errorMsg }}</p>

<!-- Rename Button -->
<div class="flex mt-8">
<Button variant="solid" class="w-full" @click="submit"> Rename </Button>
<Button variant="solid" class="w-full" @click="submit" :disabled="isSubmitting">
Rename
</Button>
</div>
</template>
</Dialog>
</template>

<script setup>
import { ref, computed } from "vue"
import { Dialog, Input } from "frappe-ui"
import { useToast } from "frappe-ui"
import { Dialog, Input, Button } from "frappe-ui"
import { useRoute } from "vue-router"
import { useStore } from "vuex"
import { rename } from "@/resources/files"

const props = defineProps({ modelValue: String })
const emit = defineEmits(["update:modelValue", "success"])
const store = useStore()
const toast = useToast()

// Reactive states
const entity = computed(() => store.state.activeEntity)
const newName = ref("")
const ext = ref("")
const errorMsg = ref("") // For inline error message
const isSubmitting = ref(false) // To disable button during submission

// Initialize newName and ext based on entity data
if (entity.value.is_group || entity.value.document) {
newName.value = entity.value.title
if (useRoute().meta.documentPage) {
Expand All @@ -55,6 +71,7 @@ if (entity.value.is_group || entity.value.document) {
}
}

// Computed property to control Dialog open state
const open = computed({
get: () => {
return props.modelValue === "rn"
Expand All @@ -65,14 +82,60 @@ const open = computed({
},
})

const submit = () => {
emit("success", {
name: entity.value.name,
title: newName.value + (ext.value ? "." + ext.value : ""),
})
rename.submit({
entity_name: entity.value.name,
new_title: newName.value + (ext.value ? "." + ext.value : ""),
})
// Submit function to rename the file
const submit = async () => {
const new_title = newName.value + (ext.value ? "." + ext.value : "")

// Prevent double submission
if (isSubmitting.value) return

try {
isSubmitting.value = true // Disable the button during submission

// Call backend validation
await frappe.call("drive.files.validate_rename", {
entity_name: entity.value.name,
new_title,
})

// Emit success and rename the file
emit("success", {
name: entity.value.name,
title: new_title,
})

rename.submit({
entity_name: entity.value.name,
new_title,
})

// Reset error message on success
errorMsg.value = ""
} catch (err) {
// Show Toast notification for global feedback
toast.show({
title: "Rename Failed",
description: err.message || "A file with that name already exists.",
status: "error",
})

// Show inline error message
errorMsg.value = err.message || "Rename failed. Please try another name."
} finally {
isSubmitting.value = false // Re-enable button after submission
}
}
</script>

<style scoped>
/* Optional styling for error message */
.text-sm {
font-size: 0.875rem;
}
.text-red-600 {
color: #e53e3e;
}
.mt-2 {
margin-top: 0.5rem;
}
</style>
2 changes: 1 addition & 1 deletion frontend/src/components/UsersBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
borderRadius: '100%',
borderColor: user.color,
}"
:image="user.avatar"
:image="user?.user_image || require('@/assets/images/icons/default-avatar.png')"
:label="user.name"
:title="user.name"
/>
Expand Down