Skip to content

Commit e91bcb9

Browse files
✨ Improve docs (#5094)
- [x] Add doc reference file into frontend project - [x] Refactor user entity - [x] Change documentation dinamically depends if runninng locally or running in HF env. - [x] Fix copy button because was changing the padding --------- Co-authored-by: burtenshaw <[email protected]>
1 parent 97a67ec commit e91bcb9

File tree

15 files changed

+259
-187
lines changed

15 files changed

+259
-187
lines changed

argilla-frontend/components/features/datasets/datasets-empty/DatasetsEmpty.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
</template>
1111

1212
<script>
13+
import { useDatasetEmptyViewModel } from "./useDatasetEmptyViewModel";
14+
1315
export default {
1416
data() {
1517
return {
@@ -20,20 +22,25 @@ export default {
2022
},
2123
async fetch() {
2224
const folderContent = require.context(
23-
`../../../../../docs/_source/_common/snippets`,
25+
`../../../../docs/snippets`,
2426
false,
2527
/.start_page.md/,
2628
"lazy"
2729
);
2830
2931
const startPage = await folderContent("./start_page.md");
3032
33+
const content = await this.preFillData(startPage);
34+
3135
this.content.tabs.push({
3236
id: "start-page",
3337
name: "Start page",
34-
markdown: startPage.body,
38+
markdown: content,
3539
});
3640
},
41+
setup() {
42+
return useDatasetEmptyViewModel();
43+
},
3744
};
3845
</script>
3946
<style lang="scss" scoped>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { useRunningEnvironment } from "~/v1/infrastructure/services/useRunningEnvironment";
2+
import { useUser } from "~/v1/infrastructure/services/useUser";
3+
4+
const HF_PREFIX = "[hf_]";
5+
const LOCAL_PREFIX = "[local_]";
6+
const HF_OWNER = "[HF_OWNER]";
7+
const HF_SPACE_NAME = "[HF_SPACE_NAME]";
8+
const USER_API_KEY = "[USER_API_KEY]";
9+
const LOCAL_HOST = "[LOCAL_HOST]";
10+
11+
export const useDatasetEmptyViewModel = () => {
12+
const { isRunningOnHuggingFace, getHuggingFaceSpace } =
13+
useRunningEnvironment();
14+
const { getUser } = useUser();
15+
16+
const replaceLocalData = (rows) => {
17+
const content = [];
18+
const user = getUser();
19+
20+
for (const row of rows) {
21+
if (row.includes(HF_PREFIX)) continue;
22+
23+
if (row.includes(LOCAL_PREFIX)) {
24+
content.push(
25+
row
26+
.replace(LOCAL_PREFIX, "")
27+
.replace(LOCAL_HOST, window.location.origin)
28+
);
29+
continue;
30+
}
31+
32+
if (row.includes(USER_API_KEY)) {
33+
content.push(row.replace(USER_API_KEY, user.apiKey));
34+
continue;
35+
}
36+
37+
content.push(row);
38+
}
39+
40+
return Promise.resolve(content.join("\n"));
41+
};
42+
43+
const replaceHFData = async (rows) => {
44+
const user = getUser();
45+
const hfEnvironment = await getHuggingFaceSpace();
46+
47+
const content = [];
48+
49+
for (const row of rows) {
50+
if (row.includes(LOCAL_PREFIX)) continue;
51+
52+
if (row.includes(HF_PREFIX)) {
53+
content.push(
54+
row
55+
.replace(HF_PREFIX, "")
56+
.replace(HF_OWNER, hfEnvironment.user)
57+
.replace(HF_SPACE_NAME, hfEnvironment.space)
58+
);
59+
60+
continue;
61+
}
62+
63+
if (row.includes(USER_API_KEY)) {
64+
content.push(row.replace(USER_API_KEY, user.apiKey));
65+
continue;
66+
}
67+
68+
content.push(row);
69+
}
70+
71+
return content.join("\n");
72+
};
73+
74+
const preFillData = (startPage) => {
75+
const rows = startPage.body.split("\n");
76+
77+
if (isRunningOnHuggingFace()) return replaceHFData(rows);
78+
79+
return replaceLocalData(rows);
80+
};
81+
82+
return {
83+
preFillData,
84+
};
85+
};

argilla-frontend/components/features/global/AppHeader.vue

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ export default {
4242
type: Array,
4343
},
4444
},
45-
computed: {
46-
/**
47-
* @deprecated Replace with useRole
48-
*/
49-
isAdminOrOwnerRole() {
50-
const role = this.$auth.user.role;
51-
return role === "admin" || role === "owner";
52-
},
53-
},
5445
methods: {
5546
onBreadcrumbAction(action) {
5647
this.$emit("breadcrumb-action", action);

argilla-frontend/components/features/global/appHeader.vue

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ export default {
4242
type: Array,
4343
},
4444
},
45-
computed: {
46-
/**
47-
* @deprecated Replace with useRole
48-
*/
49-
isAdminOrOwnerRole() {
50-
const role = this.$auth.user.role;
51-
return role === "admin" || role === "owner";
52-
},
53-
},
5445
methods: {
5546
onBreadcrumbAction(action) {
5647
this.$emit("breadcrumb-action", action);

argilla-frontend/components/features/global/user/UserAvatarTooltip.vue

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<template>
22
<div v-if="$auth.loggedIn" v-click-outside="close" class="user">
33
<a class="user__button" @click.prevent="showSelector">
4-
{{ firstChar(user.username) }}
4+
{{ user.avatar }}
55
</a>
66
<div v-if="visibleSelector && user" class="user__content">
77
<div class="head">
88
<div class="left-head">
9-
<span v-circle v-text="firstChar(user.username)" />
9+
<span v-circle v-text="user.avatar" />
1010
</div>
1111
<div class="right-head">
1212
<div class="item">
13-
<span v-text="user.username" />
13+
<span v-text="user.userName" />
1414
</div>
1515
<div class="item" v-if="user.email">
1616
<span v-text="user.email" />
@@ -44,7 +44,7 @@
4444
import "assets/icons/external";
4545
import "assets/icons/log-out";
4646
47-
import { useRoutes } from "~/v1/infrastructure/services/useRoutes";
47+
import { useAvatarTooltipViewModel } from "./userAvatarTooltipViewModel";
4848
4949
export default {
5050
data: () => {
@@ -54,20 +54,11 @@ export default {
5454
};
5555
},
5656
computed: {
57-
user() {
58-
return this.$auth.user;
59-
},
6057
currentYear() {
61-
return this.currentDate.getFullYear();
62-
},
63-
currentDate() {
64-
return new Date();
58+
return new Date().getFullYear();
6559
},
6660
},
6761
methods: {
68-
firstChar(name) {
69-
return name.slice(0, 2);
70-
},
7162
showSelector() {
7263
this.visibleSelector = !this.visibleSelector;
7364
},
@@ -81,7 +72,7 @@ export default {
8172
},
8273
},
8374
setup() {
84-
return useRoutes();
75+
return useAvatarTooltipViewModel();
8576
},
8677
};
8778
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useRoutes } from "~/v1/infrastructure/services/useRoutes";
2+
import { useUser } from "~/v1/infrastructure/services/useUser";
3+
4+
export const useAvatarTooltipViewModel = () => {
5+
const { goToSignIn } = useRoutes();
6+
const { user } = useUser();
7+
8+
return {
9+
goToSignIn,
10+
user,
11+
};
12+
};

argilla-frontend/components/features/user-settings/EditionUserInfo.vue

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)