mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-26 19:00:02 +00:00
ui: use global state for applications data (#18250)
* add check for MetaPilot - Limits * code refactor * move applications call from store to component * fix:set value of applications from provider inside store * update store inside provider * fix failing tests
This commit is contained in:
parent
8a05ba5d0d
commit
2b21d114f5
@ -22,6 +22,7 @@ import React, {
|
|||||||
} from 'react';
|
} from 'react';
|
||||||
import { usePermissionProvider } from '../../../../context/PermissionProvider/PermissionProvider';
|
import { usePermissionProvider } from '../../../../context/PermissionProvider/PermissionProvider';
|
||||||
import { App } from '../../../../generated/entity/applications/app';
|
import { App } from '../../../../generated/entity/applications/app';
|
||||||
|
import { useApplicationStore } from '../../../../hooks/useApplicationStore';
|
||||||
import { getApplicationList } from '../../../../rest/applicationAPI';
|
import { getApplicationList } from '../../../../rest/applicationAPI';
|
||||||
import { ApplicationsContextType } from './ApplicationsProvider.interface';
|
import { ApplicationsContextType } from './ApplicationsProvider.interface';
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ export const ApplicationsProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
const [applications, setApplications] = useState<App[]>([]);
|
const [applications, setApplications] = useState<App[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { permissions } = usePermissionProvider();
|
const { permissions } = usePermissionProvider();
|
||||||
|
const { setApplicationsName } = useApplicationStore();
|
||||||
|
|
||||||
const fetchApplicationList = useCallback(async () => {
|
const fetchApplicationList = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
@ -40,6 +42,8 @@ export const ApplicationsProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setApplications(data);
|
setApplications(data);
|
||||||
|
const applicationsNameList = data.map((app) => app.name);
|
||||||
|
setApplicationsName(applicationsNameList);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// do not handle error
|
// do not handle error
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -51,6 +51,7 @@ export const useApplicationStore = create<ApplicationStore>()(
|
|||||||
refreshTokenKey: '',
|
refreshTokenKey: '',
|
||||||
searchCriteria: '',
|
searchCriteria: '',
|
||||||
inlineAlertDetails: undefined,
|
inlineAlertDetails: undefined,
|
||||||
|
applications: [],
|
||||||
|
|
||||||
setInlineAlertDetails: (inlineAlertDetails) => {
|
setInlineAlertDetails: (inlineAlertDetails) => {
|
||||||
set({ inlineAlertDetails });
|
set({ inlineAlertDetails });
|
||||||
@ -164,6 +165,9 @@ export const useApplicationStore = create<ApplicationStore>()(
|
|||||||
updateSearchCriteria: (criteria) => {
|
updateSearchCriteria: (criteria) => {
|
||||||
set({ searchCriteria: criteria });
|
set({ searchCriteria: criteria });
|
||||||
},
|
},
|
||||||
|
setApplicationsName: (applications: string[]) => {
|
||||||
|
set({ applications: applications });
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: OM_SESSION_KEY, // name of item in the storage (must be unique)
|
name: OM_SESSION_KEY, // name of item in the storage (must be unique)
|
||||||
|
@ -55,6 +55,7 @@ export interface ApplicationStore
|
|||||||
searchCriteria: ExploreSearchIndex | '';
|
searchCriteria: ExploreSearchIndex | '';
|
||||||
theme: UIThemePreference['customTheme'];
|
theme: UIThemePreference['customTheme'];
|
||||||
inlineAlertDetails?: InlineAlertProps;
|
inlineAlertDetails?: InlineAlertProps;
|
||||||
|
applications: string[];
|
||||||
setInlineAlertDetails: (alertDetails?: InlineAlertProps) => void;
|
setInlineAlertDetails: (alertDetails?: InlineAlertProps) => void;
|
||||||
setSelectedPersona: (persona: EntityReference) => void;
|
setSelectedPersona: (persona: EntityReference) => void;
|
||||||
setApplicationConfig: (config: UIThemePreference) => void;
|
setApplicationConfig: (config: UIThemePreference) => void;
|
||||||
@ -82,6 +83,7 @@ export interface ApplicationStore
|
|||||||
removeRefreshToken: () => void;
|
removeRefreshToken: () => void;
|
||||||
updateSearchCriteria: (criteria: ExploreSearchIndex | '') => void;
|
updateSearchCriteria: (criteria: ExploreSearchIndex | '') => void;
|
||||||
trySilentSignIn: (forceLogout?: boolean) => void;
|
trySilentSignIn: (forceLogout?: boolean) => void;
|
||||||
|
setApplicationsName: (applications: string[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DomainStore {
|
export interface DomainStore {
|
||||||
|
@ -19,6 +19,7 @@ import { useHistory } from 'react-router-dom';
|
|||||||
import ErrorPlaceHolder from '../../components/common/ErrorWithPlaceholder/ErrorPlaceHolder';
|
import ErrorPlaceHolder from '../../components/common/ErrorWithPlaceholder/ErrorPlaceHolder';
|
||||||
import PageHeader from '../../components/PageHeader/PageHeader.component';
|
import PageHeader from '../../components/PageHeader/PageHeader.component';
|
||||||
import PageLayoutV1 from '../../components/PageLayoutV1/PageLayoutV1';
|
import PageLayoutV1 from '../../components/PageLayoutV1/PageLayoutV1';
|
||||||
|
import { useApplicationsProvider } from '../../components/Settings/Applications/ApplicationsProvider/ApplicationsProvider';
|
||||||
import SettingItemCard from '../../components/Settings/SettingItemCard/SettingItemCard.component';
|
import SettingItemCard from '../../components/Settings/SettingItemCard/SettingItemCard.component';
|
||||||
import { PAGE_HEADERS } from '../../constants/PageHeaders.constant';
|
import { PAGE_HEADERS } from '../../constants/PageHeaders.constant';
|
||||||
import { usePermissionProvider } from '../../context/PermissionProvider/PermissionProvider';
|
import { usePermissionProvider } from '../../context/PermissionProvider/PermissionProvider';
|
||||||
@ -38,6 +39,7 @@ const GlobalSettingPage = () => {
|
|||||||
|
|
||||||
const { permissions } = usePermissionProvider();
|
const { permissions } = usePermissionProvider();
|
||||||
const { isAdminUser } = useAuth();
|
const { isAdminUser } = useAuth();
|
||||||
|
const { loading } = useApplicationsProvider();
|
||||||
|
|
||||||
const [settings, setSettings] = useState<SettingMenuItem[]>([]);
|
const [settings, setSettings] = useState<SettingMenuItem[]>([]);
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ const GlobalSettingPage = () => {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}),
|
}),
|
||||||
[permissions, isAdminUser]
|
[permissions, isAdminUser, loading]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSettingItemClick = useCallback((category: string) => {
|
const handleSettingItemClick = useCallback((category: string) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user