Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: use global state for applications data #18250

Merged
merged 11 commits into from
Oct 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import React, {
} from 'react';
import { usePermissionProvider } from '../../../../context/PermissionProvider/PermissionProvider';
import { App } from '../../../../generated/entity/applications/app';
import { useApplicationStore } from '../../../../hooks/useApplicationStore';
import { getApplicationList } from '../../../../rest/applicationAPI';
import { ApplicationsContextType } from './ApplicationsProvider.interface';

Expand All @@ -31,6 +32,7 @@ export const ApplicationsProvider = ({ children }: { children: ReactNode }) => {
const [applications, setApplications] = useState<App[]>([]);
const [loading, setLoading] = useState(false);
const { permissions } = usePermissionProvider();
const { setApplicationsName } = useApplicationStore();

const fetchApplicationList = useCallback(async () => {
try {
Expand All @@ -40,6 +42,8 @@ export const ApplicationsProvider = ({ children }: { children: ReactNode }) => {
});

setApplications(data);
const applicationsNameList = data.map((app) => app.name);
setApplicationsName(applicationsNameList);
} catch (err) {
// do not handle error
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const useApplicationStore = create<ApplicationStore>()(
refreshTokenKey: '',
searchCriteria: '',
inlineAlertDetails: undefined,
applications: [],

setInlineAlertDetails: (inlineAlertDetails) => {
set({ inlineAlertDetails });
Expand Down Expand Up @@ -164,6 +165,9 @@ export const useApplicationStore = create<ApplicationStore>()(
updateSearchCriteria: (criteria) => {
set({ searchCriteria: criteria });
},
setApplicationsName: (applications: string[]) => {
set({ applications: applications });
},
}),
{
name: OM_SESSION_KEY, // name of item in the storage (must be unique)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface ApplicationStore
searchCriteria: ExploreSearchIndex | '';
theme: UIThemePreference['customTheme'];
inlineAlertDetails?: InlineAlertProps;
applications: string[];
setInlineAlertDetails: (alertDetails?: InlineAlertProps) => void;
setSelectedPersona: (persona: EntityReference) => void;
setApplicationConfig: (config: UIThemePreference) => void;
Expand Down Expand Up @@ -82,6 +83,7 @@ export interface ApplicationStore
removeRefreshToken: () => void;
updateSearchCriteria: (criteria: ExploreSearchIndex | '') => void;
trySilentSignIn: (forceLogout?: boolean) => void;
setApplicationsName: (applications: string[]) => void;
}

export interface DomainStore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useHistory } from 'react-router-dom';
import ErrorPlaceHolder from '../../components/common/ErrorWithPlaceholder/ErrorPlaceHolder';
import PageHeader from '../../components/PageHeader/PageHeader.component';
import PageLayoutV1 from '../../components/PageLayoutV1/PageLayoutV1';
import { useApplicationsProvider } from '../../components/Settings/Applications/ApplicationsProvider/ApplicationsProvider';
import SettingItemCard from '../../components/Settings/SettingItemCard/SettingItemCard.component';
import { PAGE_HEADERS } from '../../constants/PageHeaders.constant';
import { usePermissionProvider } from '../../context/PermissionProvider/PermissionProvider';
Expand All @@ -38,6 +39,7 @@ const GlobalSettingPage = () => {

const { permissions } = usePermissionProvider();
const { isAdminUser } = useAuth();
const { loading } = useApplicationsProvider();

const [settings, setSettings] = useState<SettingMenuItem[]>([]);

Expand All @@ -58,7 +60,7 @@ const GlobalSettingPage = () => {

return false;
}),
[permissions, isAdminUser]
[permissions, isAdminUser, loading]
);

const handleSettingItemClick = useCallback((category: string) => {
Expand Down
Loading