Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1451a49da2 |
@@ -1,3 +1,4 @@
|
|||||||
|
import { nsLocalJSONStorage } from '@gpustack/core-ui/utils';
|
||||||
import { getDefaultStore } from 'jotai';
|
import { getDefaultStore } from 'jotai';
|
||||||
import { atomWithStorage } from 'jotai/utils';
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@ export interface PaginationState {
|
|||||||
export const paginationAtom = atomWithStorage<Record<string, any>>(
|
export const paginationAtom = atomWithStorage<Record<string, any>>(
|
||||||
'paginationStatus',
|
'paginationStatus',
|
||||||
{},
|
{},
|
||||||
undefined,
|
nsLocalJSONStorage,
|
||||||
{ getOnInit: true }
|
{ getOnInit: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { COLOR_PRIMARY } from '@/config/theme';
|
import { COLOR_PRIMARY } from '@/config/theme';
|
||||||
|
import { nsLocal, nsLocalJSONStorage } from '@gpustack/core-ui/utils';
|
||||||
import { atom } from 'jotai';
|
import { atom } from 'jotai';
|
||||||
import { atomWithStorage } from 'jotai/utils';
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
@@ -23,9 +24,7 @@ export const defaultSettings: UserSettings = {
|
|||||||
export const getStorageUserSettings = () => {
|
export const getStorageUserSettings = () => {
|
||||||
if (typeof window === 'undefined') return defaultSettings;
|
if (typeof window === 'undefined') return defaultSettings;
|
||||||
try {
|
try {
|
||||||
const savedSettings = JSON.parse(
|
const savedSettings = JSON.parse(nsLocal.get('userSettings') || '{}');
|
||||||
localStorage.getItem('userSettings') || '{}'
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
...defaultSettings,
|
...defaultSettings,
|
||||||
...savedSettings
|
...savedSettings
|
||||||
@@ -35,9 +34,13 @@ export const getStorageUserSettings = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const userSettingsAtom = atomWithStorage<UserSettings>('userSettings', {
|
export const userSettingsAtom = atomWithStorage<UserSettings>(
|
||||||
|
'userSettings',
|
||||||
|
{
|
||||||
...getStorageUserSettings()
|
...getStorageUserSettings()
|
||||||
});
|
},
|
||||||
|
nsLocalJSONStorage
|
||||||
|
);
|
||||||
|
|
||||||
export const userSettingsHelperAtom = atom(
|
export const userSettingsHelperAtom = atom(
|
||||||
(get) => get(userSettingsAtom),
|
(get) => get(userSettingsAtom),
|
||||||
@@ -59,6 +62,6 @@ export const hideModalTemporarilyAtom = atom<boolean>(false);
|
|||||||
export const collapsedMenuGroupsAtom = atomWithStorage<string[]>(
|
export const collapsedMenuGroupsAtom = atomWithStorage<string[]>(
|
||||||
'collapsedMenuGroups',
|
'collapsedMenuGroups',
|
||||||
[],
|
[],
|
||||||
undefined,
|
nsLocalJSONStorage,
|
||||||
{ getOnInit: true }
|
{ getOnInit: true }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import { nsLocalJSONStorage } from '@gpustack/core-ui/utils';
|
||||||
import { getDefaultStore } from 'jotai';
|
import { getDefaultStore } from 'jotai';
|
||||||
import { atomWithStorage } from 'jotai/utils';
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
export const tabActiveAtom = atomWithStorage<Map<string, any>>(
|
export const tabActiveAtom = atomWithStorage<Map<string, any>>(
|
||||||
'tabActiveStatus',
|
'tabActiveStatus',
|
||||||
new Map()
|
new Map(),
|
||||||
|
nsLocalJSONStorage
|
||||||
);
|
);
|
||||||
|
|
||||||
export const setActiveStatus = (key: string, value: any) => {
|
export const setActiveStatus = (key: string, value: any) => {
|
||||||
|
|||||||
+10
-4
@@ -1,7 +1,12 @@
|
|||||||
|
import { nsLocal, nsLocalJSONStorage } from '@gpustack/core-ui/utils';
|
||||||
import { atom } from 'jotai';
|
import { atom } from 'jotai';
|
||||||
import { atomWithStorage } from 'jotai/utils';
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
export const userAtom = atomWithStorage<any>('userInfo', null);
|
export const userAtom = atomWithStorage<any>(
|
||||||
|
'userInfo',
|
||||||
|
null,
|
||||||
|
nsLocalJSONStorage
|
||||||
|
);
|
||||||
|
|
||||||
// Backs the `currentOrganizationId` localStorage key. Stays null in
|
// Backs the `currentOrganizationId` localStorage key. Stays null in
|
||||||
// builds with no Org context (single-tenant), and is shared with any
|
// builds with no Org context (single-tenant), and is shared with any
|
||||||
@@ -9,7 +14,8 @@ export const userAtom = atomWithStorage<any>('userInfo', null);
|
|||||||
// without one side having to import from the other.
|
// without one side having to import from the other.
|
||||||
export const currentOrganizationIdAtom = atomWithStorage<number | null>(
|
export const currentOrganizationIdAtom = atomWithStorage<number | null>(
|
||||||
'currentOrganizationId',
|
'currentOrganizationId',
|
||||||
null
|
null,
|
||||||
|
nsLocalJSONStorage
|
||||||
);
|
);
|
||||||
|
|
||||||
export const GPUStackVersionAtom = atom<{
|
export const GPUStackVersionAtom = atom<{
|
||||||
@@ -70,7 +76,7 @@ export const getCurrentOrgNamespace = (
|
|||||||
|
|
||||||
const getStoredCurrentOrgId = (): number | null => {
|
const getStoredCurrentOrgId = (): number | null => {
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem('currentOrganizationId');
|
const raw = nsLocal.get('currentOrganizationId');
|
||||||
if (!raw) return null;
|
if (!raw) return null;
|
||||||
const value = JSON.parse(raw);
|
const value = JSON.parse(raw);
|
||||||
return typeof value === 'number' ? value : null;
|
return typeof value === 'number' ? value : null;
|
||||||
@@ -108,7 +114,7 @@ export const getOrgById = (
|
|||||||
const target = String(id);
|
const target = String(id);
|
||||||
for (const key of ORG_CACHE_KEYS) {
|
for (const key of ORG_CACHE_KEYS) {
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(key);
|
const raw = nsLocal.get(key);
|
||||||
if (!raw) continue;
|
if (!raw) continue;
|
||||||
const list = JSON.parse(raw) as CachedOrg[];
|
const list = JSON.parse(raw) as CachedOrg[];
|
||||||
if (!Array.isArray(list)) continue;
|
if (!Array.isArray(list)) continue;
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import { defaultSettings } from '@/atoms/settings';
|
import { defaultSettings } from '@/atoms/settings';
|
||||||
|
import { nsLocal } from '@gpustack/core-ui/utils';
|
||||||
import { getDefaultStore } from 'jotai';
|
import { getDefaultStore } from 'jotai';
|
||||||
|
|
||||||
export const clearStorageUserSettings = () => {
|
export const clearStorageUserSettings = () => {
|
||||||
try {
|
try {
|
||||||
const savedSettings = JSON.parse(
|
const savedSettings = JSON.parse(nsLocal.get('userSettings') || '{}');
|
||||||
localStorage.getItem('userSettings') || '{}'
|
|
||||||
);
|
|
||||||
// colorPrimary is an enterprise-wide branding setting (set by admins
|
// colorPrimary is an enterprise-wide branding setting (set by admins
|
||||||
// and applied by `onAppInit` from /enterprise/settings), not a per-user
|
// and applied by `onAppInit` from /enterprise/settings), not a per-user
|
||||||
// preference. Preserve it across login — otherwise the next layout
|
// preference. Preserve it across login — otherwise the next layout
|
||||||
// mount triggers `atomWithStorage.onMount`, re-reads localStorage,
|
// mount triggers `atomWithStorage.onMount`, re-reads localStorage,
|
||||||
// and falls back to the default color until a full page refresh
|
// and falls back to the default color until a full page refresh
|
||||||
// re-runs `applyEnterpriseSettings`.
|
// re-runs `applyEnterpriseSettings`.
|
||||||
localStorage.setItem(
|
nsLocal.set(
|
||||||
'userSettings',
|
'userSettings',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
...savedSettings,
|
...savedSettings,
|
||||||
@@ -26,7 +25,7 @@ export const clearStorageUserSettings = () => {
|
|||||||
|
|
||||||
export const resetStorageUserSettings = () => {
|
export const resetStorageUserSettings = () => {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(
|
nsLocal.set(
|
||||||
'userSettings',
|
'userSettings',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
...defaultSettings,
|
...defaultSettings,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import externalLinks from '@/constants/external-links';
|
import externalLinks from '@/constants/external-links';
|
||||||
import { GithubFilled } from '@ant-design/icons';
|
import { GithubFilled } from '@ant-design/icons';
|
||||||
|
import { nsLocal } from '@gpustack/core-ui/utils';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Tooltip } from 'antd';
|
import { Tooltip } from 'antd';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
@@ -66,7 +67,7 @@ type CacheEntry = { value: number; time: number };
|
|||||||
|
|
||||||
const readCache = (): CacheEntry | null => {
|
const readCache = (): CacheEntry | null => {
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(CACHE_KEY);
|
const raw = nsLocal.get(CACHE_KEY);
|
||||||
if (!raw) return null;
|
if (!raw) return null;
|
||||||
const parsed = JSON.parse(raw);
|
const parsed = JSON.parse(raw);
|
||||||
if (typeof parsed?.value !== 'number' || typeof parsed?.time !== 'number') {
|
if (typeof parsed?.value !== 'number' || typeof parsed?.time !== 'number') {
|
||||||
@@ -80,10 +81,7 @@ const readCache = (): CacheEntry | null => {
|
|||||||
|
|
||||||
const writeCache = (value: number) => {
|
const writeCache = (value: number) => {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(
|
nsLocal.set(CACHE_KEY, JSON.stringify({ value, time: Date.now() }));
|
||||||
CACHE_KEY,
|
|
||||||
JSON.stringify({ value, time: Date.now() })
|
|
||||||
);
|
|
||||||
} catch {
|
} catch {
|
||||||
// ignore quota errors
|
// ignore quota errors
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
import { queryClusterList } from '@/pages/cluster-management/apis';
|
import { queryClusterList } from '@/pages/cluster-management/apis';
|
||||||
import { ProviderValueMap } from '@/pages/cluster-management/config';
|
import { ProviderValueMap } from '@/pages/cluster-management/config';
|
||||||
import { queryResourceEvents } from '@/pages/usage/apis/resource';
|
import { queryResourceEvents } from '@/pages/usage/apis/resource';
|
||||||
|
import { nsSession } from '@gpustack/core-ui/utils';
|
||||||
|
|
||||||
// Probes the caller's cluster list once so access predicates can gate
|
// Probes the caller's cluster list once so access predicates can gate
|
||||||
// GPU Service (Kubernetes-only). Cheap (one list request) and never
|
// GPU Service (Kubernetes-only). Cheap (one list request) and never
|
||||||
@@ -33,20 +34,13 @@ export const probeHasKubernetesCluster = async (): Promise<
|
|||||||
const value = (res?.items ?? []).some(
|
const value = (res?.items ?? []).some(
|
||||||
(c) => c?.provider === ProviderValueMap.Kubernetes
|
(c) => c?.provider === ProviderValueMap.Kubernetes
|
||||||
);
|
);
|
||||||
try {
|
// nsSession swallows write errors (Safari private mode); the access
|
||||||
window.sessionStorage.setItem(HAS_K8S_CLUSTER_KEY, JSON.stringify(value));
|
// predicate already handles a missing value as "unknown".
|
||||||
} catch {
|
nsSession.set(HAS_K8S_CLUSTER_KEY, JSON.stringify(value));
|
||||||
// sessionStorage may be unavailable (Safari private mode); the
|
|
||||||
// access predicate already handles a missing value as "unknown".
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('probeHasKubernetesCluster error', error);
|
console.error('probeHasKubernetesCluster error', error);
|
||||||
try {
|
nsSession.remove(HAS_K8S_CLUSTER_KEY);
|
||||||
window.sessionStorage.removeItem(HAS_K8S_CLUSTER_KEY);
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -69,22 +63,12 @@ export const probeHasResourceEvents = async (): Promise<
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
const value = (res?.pagination?.total ?? 0) > 0;
|
const value = (res?.pagination?.total ?? 0) > 0;
|
||||||
try {
|
// nsSession swallows write errors; predicate treats missing as unknown.
|
||||||
window.sessionStorage.setItem(
|
nsSession.set(HAS_RESOURCE_EVENTS_KEY, JSON.stringify(value));
|
||||||
HAS_RESOURCE_EVENTS_KEY,
|
|
||||||
JSON.stringify(value)
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
// sessionStorage may be unavailable; predicate treats missing as unknown.
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('probeHasResourceEvents error', error);
|
console.error('probeHasResourceEvents error', error);
|
||||||
try {
|
nsSession.remove(HAS_RESOURCE_EVENTS_KEY);
|
||||||
window.sessionStorage.removeItem(HAS_RESOURCE_EVENTS_KEY);
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { NS_STORE_NAME } from '@gpustack/core-ui/utils';
|
||||||
import localStore from './store';
|
import localStore from './store';
|
||||||
|
|
||||||
const IS_FIRST_LOGIN = 'is_first_login';
|
const IS_FIRST_LOGIN = 'is_first_login';
|
||||||
@@ -5,7 +6,7 @@ const IS_FIRST_LOGIN = 'is_first_login';
|
|||||||
const REMEMBER_ME_KEY = 'r_m';
|
const REMEMBER_ME_KEY = 'r_m';
|
||||||
const CRYPT_TEXT = 'seal';
|
const CRYPT_TEXT = 'seal';
|
||||||
|
|
||||||
const store = localStore.createInstance({ name: '_xWXJKJ_S1Sna_' });
|
const store = localStore.createInstance({ name: NS_STORE_NAME });
|
||||||
|
|
||||||
// Kept to remove credentials saved by the old "remember me" feature.
|
// Kept to remove credentials saved by the old "remember me" feature.
|
||||||
const removeRememberMe = (key: string) => {
|
const removeRememberMe = (key: string) => {
|
||||||
@@ -37,9 +38,9 @@ const writeColumnSettings = (key: string, data: any) => {
|
|||||||
export {
|
export {
|
||||||
CRYPT_TEXT,
|
CRYPT_TEXT,
|
||||||
IS_FIRST_LOGIN,
|
IS_FIRST_LOGIN,
|
||||||
REMEMBER_ME_KEY,
|
|
||||||
readColumnSettings,
|
readColumnSettings,
|
||||||
readState,
|
readState,
|
||||||
|
REMEMBER_ME_KEY,
|
||||||
removeRememberMe,
|
removeRememberMe,
|
||||||
writeColumnSettings,
|
writeColumnSettings,
|
||||||
writeState
|
writeState
|
||||||
|
|||||||
Reference in New Issue
Block a user