-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Francisco Aranda <[email protected]> Co-authored-by: Paco Aranda <[email protected]> Co-authored-by: Leire <[email protected]> Co-authored-by: José Francisco Calvo <[email protected]>
- Loading branch information
1 parent
d6f823b
commit 3643cf3
Showing
31 changed files
with
556 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
argilla-frontend/components/features/annotation/progress/share/Share.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<template> | ||
<div class="share" @click.stop="copyOnClipboard"> | ||
<BaseActionTooltip :tooltip="$t('copiedToClipboard')"> | ||
<BaseButton | ||
class="share__button" | ||
:title="$t('button.tooltip.copyToClipboard')" | ||
@mouseover="openDialog" | ||
@mouseleave="closeDialog" | ||
> | ||
<svgicon class="share__icon" name="link" width="14" height="14" /> | ||
{{ $t("share") }} | ||
</BaseButton> | ||
</BaseActionTooltip> | ||
<transition name="fade" appear> | ||
<dialog | ||
v-if="isDialogOpen" | ||
class="share__dialog" | ||
v-click-outside="closeDialog" | ||
> | ||
<div class="share__dialog--container"> | ||
<BaseSpinner v-if="!sharingImage.loaded" :size="20" /> | ||
<img v-else :src="sharingImage.src" /> | ||
</div> | ||
</dialog> | ||
</transition> | ||
</div> | ||
</template> | ||
<script> | ||
import { useShareViewModel } from "./useShareViewModel"; | ||
export default { | ||
setup() { | ||
return useShareViewModel(); | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
$bullet-size: 8px; | ||
.share { | ||
z-index: 2; | ||
margin-left: auto; | ||
margin-right: 0; | ||
&__dialog { | ||
position: absolute; | ||
right: 1em; | ||
left: auto; | ||
width: auto; | ||
height: 204px; | ||
min-width: 360px; | ||
max-width: 360px; | ||
bottom: calc(100% + $base-space + 2px); | ||
display: block; | ||
padding: $base-space * 2; | ||
border: 1px solid var(--bg-opacity-10); | ||
border-radius: $border-radius-m; | ||
box-shadow: $shadow; | ||
z-index: 2; | ||
&--container { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
} | ||
} | ||
&__button { | ||
@include font-size(12px); | ||
height: 24px; | ||
padding: $base-space; | ||
background: var(--bg-opacity-3); | ||
border-radius: $border-radius; | ||
} | ||
&__icon { | ||
padding: 0; | ||
flex-shrink: 0; | ||
} | ||
} | ||
</style> |
106 changes: 106 additions & 0 deletions
106
argilla-frontend/components/features/annotation/progress/share/useShareViewModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { onBeforeMount, ref } from "vue"; | ||
import { useUser } from "~/v1/infrastructure/services"; | ||
import { useClipboard } from "~/v1/infrastructure/services/useClipboard"; | ||
import { useDataset } from "~/v1/infrastructure/storage/DatasetStorage"; | ||
import { useMetrics } from "~/v1/infrastructure/storage/MetricsStorage"; | ||
import { useTeamProgress } from "~/v1/infrastructure/storage/TeamProgressStorage"; | ||
|
||
export const useShareViewModel = () => { | ||
const { copy } = useClipboard(); | ||
const { user } = useUser(); | ||
const { state: metrics } = useMetrics(); | ||
const { state: dataset } = useDataset(); | ||
const { state: progress } = useTeamProgress(); | ||
|
||
const isDialogOpen = ref(false); | ||
const sharingImage = ref<{ | ||
src: string; | ||
loaded: boolean; | ||
}>({ | ||
src: "", | ||
loaded: false, | ||
}); | ||
|
||
const copyOnClipboard = () => { | ||
closeDialog(); | ||
|
||
const url = new URL(`${window.location.origin}/share-your-progress`); | ||
const params = new URLSearchParams(""); | ||
params.set("user_name", user.value.userName); | ||
params.set("records_submitted", metrics.submitted.toString()); | ||
params.set("team_progress", progress.percentage.completed.toString()); | ||
params.set("dataset_name", dataset.name); | ||
params.set("dataset_id", dataset.id); | ||
|
||
url.search = params.toString(); | ||
|
||
const textToCopy = `I've just contributed ${ | ||
metrics.submitted | ||
} examples to this dataset: | ||
${url.toString()}`; | ||
|
||
copy(textToCopy); | ||
}; | ||
|
||
const createImageLink = () => { | ||
const url = new URL("https://argilla.imglab-cdn.net/dibt/dibt_v2.png"); | ||
const params = new URLSearchParams(url.search); | ||
params.set("width", "1200"); | ||
params.set("text-width", "700"); | ||
params.set("text-height", "590"); | ||
params.set("text-padding", "60"); | ||
params.set("text-color", "39,71,111"); | ||
params.set("text-x", "460"); | ||
params.set("text-y", "40"); | ||
|
||
params.set( | ||
"text", | ||
`<span size="9pt" weight="bold">@${user.value.userName}</span> | ||
I've just contributed <span weight="bold">${metrics.submitted}</span> examples to this dataset: | ||
<span size="9pt" weight="bold">${dataset.name}</span> | ||
<span size="8pt">Team progress</span> | ||
<span weight="bold">${progress.percentage.completed}%</span>` | ||
); | ||
|
||
return `${url.origin}${url.pathname}?${params.toString()}`; | ||
}; | ||
|
||
const openDialog = () => { | ||
setPreloadedImage(); | ||
|
||
isDialogOpen.value = true; | ||
}; | ||
|
||
const closeDialog = () => { | ||
isDialogOpen.value = false; | ||
}; | ||
|
||
const setPreloadedImage = () => { | ||
sharingImage.value.loaded = false; | ||
|
||
const image = createImageLink(); | ||
|
||
const preFetchImage = new Image(); | ||
preFetchImage.src = image; | ||
preFetchImage.onload = () => { | ||
sharingImage.value = { | ||
src: image, | ||
loaded: true, | ||
}; | ||
}; | ||
}; | ||
|
||
onBeforeMount(() => { | ||
setPreloadedImage(); | ||
}); | ||
|
||
return { | ||
sharingImage, | ||
isDialogOpen, | ||
openDialog, | ||
closeDialog, | ||
copyOnClipboard, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 18 additions & 1 deletion
19
argilla-frontend/components/features/annotation/progress/useAnnotationProgressViewModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import { onBeforeMount } from "vue-demi"; | ||
import { computed, onBeforeMount, ref } from "vue-demi"; | ||
import { | ||
useEvents, | ||
UpdateMetricsEventHandler, | ||
} from "~/v1/infrastructure/events"; | ||
import { useRunningEnvironment } from "~/v1/infrastructure/services"; | ||
import { useMetrics } from "~/v1/infrastructure/storage/MetricsStorage"; | ||
|
||
export const useAnnotationProgressViewModel = () => { | ||
const isShareYourProgressEnabled = ref<boolean>(false); | ||
|
||
const { state: metrics } = useMetrics(); | ||
const { getShareYourProgressEnabled } = useRunningEnvironment(); | ||
|
||
onBeforeMount(async () => { | ||
isShareYourProgressEnabled.value = await getShareYourProgressEnabled(); | ||
}); | ||
|
||
const canSeeShare = computed( | ||
() => isShareYourProgressEnabled.value && metrics.submitted >= 2 | ||
); | ||
const shouldShowSubmittedAnimation = computed( | ||
() => canSeeShare.value && metrics.submitted % 10 === 0 | ||
); | ||
|
||
onBeforeMount(() => { | ||
useEvents(UpdateMetricsEventHandler); | ||
}); | ||
|
||
return { | ||
metrics, | ||
canSeeShare, | ||
shouldShowSubmittedAnimation, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.