-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] Load user interfaces on demand
- Loading branch information
1 parent
9b9ba63
commit ec46b7c
Showing
13 changed files
with
228 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { ReactNode, createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'; | ||
import { | ||
ProjectConfig, | ||
UserInterfaceOutputSettings, | ||
UserInterfaceWithOutputSettings, | ||
defaultOutputSettings, | ||
} from '../../types/types'; | ||
import { IOutputSettingsContext } from './OutputSettingsContext.types'; | ||
import { useAppContext } from '../../contexts/AppProvider'; | ||
import { OutputType } from '../../utils/ApiTypes'; | ||
|
||
export const OutputSettingsContextDefaultValues: IOutputSettingsContext = { | ||
selectedUserInterfaceId: '', | ||
outputSettings: defaultOutputSettings, | ||
userInterfaceOutputSettings: null, | ||
onUserInterfaceChange: () => null, | ||
}; | ||
|
||
export const OutputSettingsContext = createContext<IOutputSettingsContext>(OutputSettingsContextDefaultValues); | ||
|
||
export const useOutputSettingsContext = () => { | ||
return useContext(OutputSettingsContext); | ||
}; | ||
|
||
export function OutputSettingsContextProvider({ | ||
projectConfig, | ||
layoutIntent, | ||
children, | ||
}: { | ||
projectConfig: ProjectConfig; | ||
layoutIntent: string | null; | ||
children: ReactNode; | ||
}) { | ||
const { dataSource } = useAppContext(); | ||
|
||
const [selectedUserInterfaceId, setSelectedUserInterfaceId] = useState<string | null>( | ||
projectConfig.userInterfaceID || null, | ||
); | ||
const [userInterfaceOutputSettings, setUserInterfaceOutputSettings] = useState< | ||
UserInterfaceOutputSettings[] | null | ||
>([]); | ||
|
||
const fetchOutputSettings = useCallback( | ||
async (userInterfaceId?: string) => { | ||
if (projectConfig.onFetchOutputSettings) { | ||
projectConfig | ||
.onFetchOutputSettings(userInterfaceId) | ||
.then((res: UserInterfaceWithOutputSettings | null) => { | ||
let settings = res?.outputSettings?.filter((val) => | ||
val.layoutIntents.includes(layoutIntent ?? ''), | ||
); | ||
|
||
settings = dataSource ? settings : settings?.filter((s) => s.outputType !== OutputType.Batch); | ||
setUserInterfaceOutputSettings(settings ?? null); | ||
setSelectedUserInterfaceId(res?.userInterface?.id || null); | ||
}); | ||
} | ||
}, | ||
[layoutIntent, projectConfig, dataSource], | ||
); | ||
|
||
useEffect(() => { | ||
fetchOutputSettings(selectedUserInterfaceId || undefined); | ||
}, [selectedUserInterfaceId, fetchOutputSettings]); | ||
|
||
const data = useMemo( | ||
() => ({ | ||
selectedUserInterfaceId, | ||
outputSettings: projectConfig.outputSettings, | ||
userInterfaceOutputSettings, | ||
onUserInterfaceChange: setSelectedUserInterfaceId, | ||
}), | ||
[ | ||
selectedUserInterfaceId, | ||
userInterfaceOutputSettings, | ||
projectConfig.outputSettings, | ||
setSelectedUserInterfaceId, | ||
], | ||
); | ||
|
||
return <OutputSettingsContext.Provider value={data}>{children}</OutputSettingsContext.Provider>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { OutputSettings, UserInterfaceOutputSettings } from '../../types/types'; | ||
|
||
export interface IOutputSettingsContext { | ||
outputSettings: OutputSettings; | ||
userInterfaceOutputSettings: UserInterfaceOutputSettings[] | null; | ||
selectedUserInterfaceId: string | null; | ||
onUserInterfaceChange: (_: string) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
src/components/navbar/navbarItems/useUserInterfaceSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
import { OutputSettings, UiOptions, UserInterface, UserInterfaceOutputSettings } from '../types/types'; | ||
import { ProjectConfig, UiOptions } from '../types/types'; | ||
|
||
export interface IUiConfigContext { | ||
projectConfig: ProjectConfig; | ||
|
||
uiOptions: UiOptions; | ||
outputSettings: OutputSettings; | ||
userInterfaceOutputSettings: UserInterfaceOutputSettings[] | null; | ||
isDownloadBtnVisible: boolean; | ||
isBackBtnVisible: boolean; | ||
graFxStudioEnvironmentApiBaseUrl: string; | ||
|
||
userInterfaces: UserInterface[]; | ||
selectedUserInterfaceId: string | null; | ||
onUserInterfaceChange: (_: string) => void; | ||
onVariableFocus?: (id: string) => void; | ||
onVariableBlur?: (id: string) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.