Skip to content
Merged
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
8 changes: 6 additions & 2 deletions src-tauri/src/commands/url_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,17 @@ pub fn url_watcher(app: AppHandle, name: String, origin: String) {
let license_valid = if xpack_message.status == 200 && xpack_message.success {
serde_json::from_str::<Value>(&xpack_message.data)
.ok()
.and_then(|value| value.get("XPACK_LICENSE_IS_VALID").and_then(|v| v.as_bool()))
.and_then(|value| {
value
.get("XPACK_LICENSE_IS_VALID")
.and_then(|v| v.as_bool())
})
.unwrap_or(false)
} else {
false
};

let user_data = user_service.init(profile, license_valid).await;
let user_data = user_service.init(profile).await;

let _ = app.emit(
"login-success-detected",
Expand Down
50 changes: 7 additions & 43 deletions src-tauri/src/service/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,50 +51,14 @@ impl UserService {
get_with_response(&url, &self.cookie_header).await
}

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

UserProfileData {
profile,
current_org,
permission_orgs,
}
} else {
let permission_orgs = ApiResponse {
status: 200,
data: json!({
"pam_orgs": [],
"audit_orgs": [],
"console_orgs": [],
"workbench_orgs": [],
"id": "",
"username": "",
})
.to_string(),
success: true,
};

let current_org = ApiResponse {
status: 200,
data: json!({
"id": "",
"name": "",
"is_root": false,
"is_default": false,
"is_system": false,
"comment": "",
})
.to_string(),
success: true,
};

UserProfileData {
profile,
current_org,
permission_orgs,
}
UserProfileData {
profile,
current_org,
permission_orgs,
}
}
}
32 changes: 28 additions & 4 deletions ui/components/Card/TableCard/tableCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ interface MenuItem {
children?: MenuItem[];
}

const ASSET_NAME_TOOLTIP_THRESHOLD = 20;

const UButton = resolveComponent("UButton");
const UTooltip = resolveComponent("UTooltip");
const UCheckbox = resolveComponent("UCheckbox");
const UFieldGroup = resolveComponent("UFieldGroup");
const UDropdownMenu = resolveComponent("UDropdownMenu");
Expand Down Expand Up @@ -183,6 +186,11 @@ function cancelRename() {
renamingId.value = null;
}

const shouldShowTooltip = (text: string | undefined | null) => {
if (!text) return false;
return text.length > ASSET_NAME_TOOLTIP_THRESHOLD;
};

const columns: TableColumn<AssetItem>[] = [
{
id: "select",
Expand Down Expand Up @@ -222,13 +230,29 @@ const columns: TableColumn<AssetItem>[] = [
});
}

return h(
const assetName = row.original.name || "-";

const textNode = h(
"div",
{
class: "truncate",
title: row.original.name
class: "truncate"
},
row.original.name
assetName
);

if (!shouldShowTooltip(assetName) || assetName === "-") {
return textNode;
}

return h(
UTooltip,
{
arrow: true,
text: assetName
},
{
default: () => textNode
}
);
},
meta: { class: { th: "max-w-[300px]", td: "max-w-[300px]" } }
Expand Down
4 changes: 2 additions & 2 deletions ui/components/SideBar/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ onMounted(async () => {
const resolvedSite = resolved_site || normalizedSite;

if (status === "success" && profileData) {
const language = resolveLanguageFromCookies(cookies);
const language = await resolveLanguageFromCookies();

if (vStatus !== "incompatible" && !vMatch) {
useEventBus().emit("versionAlert", { type: "noMatch", version: versionMessage[versionMessage.length - 1] });
Expand All @@ -500,7 +500,7 @@ onMounted(async () => {
org: currentOrgData,
system_roles: profileData.system_roles,
availableOrgs,
xpackLicenseValid: xpack_license_valid ?? false,
xpackLicenseValid: xpack_license_valid ?? true,
language,
connectionInfo: {
protocol: "",
Expand Down
27 changes: 14 additions & 13 deletions ui/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ export function transformAssetsData(rawDataArray: RawAssetData[]): AssetItem[] {
}

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

const langEntry = cookies
.split(";")
.map((chunk) => chunk.trim())
.find((chunk) => chunk.toLowerCase().startsWith("django_language="));

if (!langEntry) return "en";
const normalized = lang.toLowerCase();
if (normalized.includes("zh")) return "zh" as const;
return "en" as const;
};

const value = langEntry.split("=")[1]?.trim().toLowerCase();
const locale = await useTauriOsLocale();
if (locale) {
return normalize(locale);
}

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

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