Skip to content

Commit 04fc33e

Browse files
committed
perf: table tooltips and languange
1 parent 61811bc commit 04fc33e

5 files changed

Lines changed: 57 additions & 64 deletions

File tree

src-tauri/src/commands/url_watcher.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ pub fn url_watcher(app: AppHandle, name: String, origin: String) {
122122
let license_valid = if xpack_message.status == 200 && xpack_message.success {
123123
serde_json::from_str::<Value>(&xpack_message.data)
124124
.ok()
125-
.and_then(|value| value.get("XPACK_LICENSE_IS_VALID").and_then(|v| v.as_bool()))
125+
.and_then(|value| {
126+
value
127+
.get("XPACK_LICENSE_IS_VALID")
128+
.and_then(|v| v.as_bool())
129+
})
126130
.unwrap_or(false)
127131
} else {
128132
false
129133
};
130134

131-
let user_data = user_service.init(profile, license_valid).await;
135+
let user_data = user_service.init(profile).await;
132136

133137
let _ = app.emit(
134138
"login-success-detected",

src-tauri/src/service/user.rs

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,50 +51,14 @@ impl UserService {
5151
get_with_response(&url, &self.cookie_header).await
5252
}
5353

54-
pub async fn init(&self, profile: ApiResponse, fetch_orgs: bool) -> UserProfileData {
55-
if fetch_orgs {
56-
let (permission_orgs, current_org) =
57-
tokio::join!(self.get_permission_orgs(), self.get_current_org());
54+
pub async fn init(&self, profile: ApiResponse) -> UserProfileData {
55+
let (permission_orgs, current_org) =
56+
tokio::join!(self.get_permission_orgs(), self.get_current_org());
5857

59-
UserProfileData {
60-
profile,
61-
current_org,
62-
permission_orgs,
63-
}
64-
} else {
65-
let permission_orgs = ApiResponse {
66-
status: 200,
67-
data: json!({
68-
"pam_orgs": [],
69-
"audit_orgs": [],
70-
"console_orgs": [],
71-
"workbench_orgs": [],
72-
"id": "",
73-
"username": "",
74-
})
75-
.to_string(),
76-
success: true,
77-
};
78-
79-
let current_org = ApiResponse {
80-
status: 200,
81-
data: json!({
82-
"id": "",
83-
"name": "",
84-
"is_root": false,
85-
"is_default": false,
86-
"is_system": false,
87-
"comment": "",
88-
})
89-
.to_string(),
90-
success: true,
91-
};
92-
93-
UserProfileData {
94-
profile,
95-
current_org,
96-
permission_orgs,
97-
}
58+
UserProfileData {
59+
profile,
60+
current_org,
61+
permission_orgs,
9862
}
9963
}
10064
}

ui/components/Card/TableCard/tableCard.vue

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ interface MenuItem {
1414
children?: MenuItem[];
1515
}
1616
17+
const ASSET_NAME_TOOLTIP_THRESHOLD = 20;
18+
1719
const UButton = resolveComponent("UButton");
20+
const UTooltip = resolveComponent("UTooltip");
1821
const UCheckbox = resolveComponent("UCheckbox");
1922
const UFieldGroup = resolveComponent("UFieldGroup");
2023
const UDropdownMenu = resolveComponent("UDropdownMenu");
@@ -183,6 +186,11 @@ function cancelRename() {
183186
renamingId.value = null;
184187
}
185188
189+
const shouldShowTooltip = (text: string | undefined | null) => {
190+
if (!text) return false;
191+
return text.length > ASSET_NAME_TOOLTIP_THRESHOLD;
192+
};
193+
186194
const columns: TableColumn<AssetItem>[] = [
187195
{
188196
id: "select",
@@ -222,13 +230,29 @@ const columns: TableColumn<AssetItem>[] = [
222230
});
223231
}
224232
225-
return h(
233+
const assetName = row.original.name || "-";
234+
235+
const textNode = h(
226236
"div",
227237
{
228-
class: "truncate",
229-
title: row.original.name
238+
class: "truncate"
230239
},
231-
row.original.name
240+
assetName
241+
);
242+
243+
if (!shouldShowTooltip(assetName) || assetName === "-") {
244+
return textNode;
245+
}
246+
247+
return h(
248+
UTooltip,
249+
{
250+
arrow: true,
251+
text: assetName
252+
},
253+
{
254+
default: () => textNode
255+
}
232256
);
233257
},
234258
meta: { class: { th: "max-w-[300px]", td: "max-w-[300px]" } }

ui/components/SideBar/profile.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ onMounted(async () => {
480480
const resolvedSite = resolved_site || normalizedSite;
481481
482482
if (status === "success" && profileData) {
483-
const language = resolveLanguageFromCookies(cookies);
483+
const language = await resolveLanguageFromCookies();
484484
485485
if (vStatus !== "incompatible" && !vMatch) {
486486
useEventBus().emit("versionAlert", { type: "noMatch", version: versionMessage[versionMessage.length - 1] });
@@ -500,7 +500,7 @@ onMounted(async () => {
500500
org: currentOrgData,
501501
system_roles: profileData.system_roles,
502502
availableOrgs,
503-
xpackLicenseValid: xpack_license_valid ?? false,
503+
xpackLicenseValid: xpack_license_valid ?? true,
504504
language,
505505
connectionInfo: {
506506
protocol: "",

ui/utils/index.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,23 @@ export function transformAssetsData(rawDataArray: RawAssetData[]): AssetItem[] {
3333
}
3434

3535
/**
36-
* @description 处理 cooklies 中的 django_language
37-
* @param cookies
36+
* @description 获取操作系统的语言
3837
*/
39-
export function resolveLanguageFromCookies(cookies: string | undefined | null): "zh" | "en" {
40-
if (!cookies) return "en";
38+
export async function resolveLanguageFromCookies(): Promise<"zh" | "en"> {
39+
const normalize = (lang: string | null | undefined) => {
40+
if (!lang) return "en" as const;
4141

42-
const langEntry = cookies
43-
.split(";")
44-
.map((chunk) => chunk.trim())
45-
.find((chunk) => chunk.toLowerCase().startsWith("django_language="));
46-
47-
if (!langEntry) return "en";
42+
const normalized = lang.toLowerCase();
43+
if (normalized.includes("zh")) return "zh" as const;
44+
return "en" as const;
45+
};
4846

49-
const value = langEntry.split("=")[1]?.trim().toLowerCase();
47+
const locale = await useTauriOsLocale();
48+
if (locale) {
49+
return normalize(locale);
50+
}
5051

51-
if (!value) return "en";
52+
const fallback = (typeof navigator !== "undefined" && (navigator.language || navigator.languages?.[0])) || "";
5253

53-
return value === "zh-hans" || value.startsWith("zh") ? "zh" : "en";
54+
return normalize(fallback);
5455
}

0 commit comments

Comments
 (0)