-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new custom settings: state captions, search help
- Loading branch information
Showing
16 changed files
with
246 additions
and
176 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
49 changes: 49 additions & 0 deletions
49
cassandra-distributed-task-queue-ui/src/CustomSettingsContext.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { createContext, PropsWithChildren, useContext } from "react"; | ||
import type { JSX } from "react"; | ||
|
||
import { TaskState } from "./Domain/Api/TaskState"; | ||
import { CustomRenderer, ICustomRenderer } from "./Domain/CustomRenderer"; | ||
|
||
const TaskStateCaptions = { | ||
[TaskState.Unknown]: "Unknown", | ||
[TaskState.New]: "New", | ||
[TaskState.WaitingForRerun]: "Waiting for rerun", | ||
[TaskState.WaitingForRerunAfterError]: "Waiting for rerun after error", | ||
[TaskState.Finished]: "Finished", | ||
[TaskState.InProcess]: "In process", | ||
[TaskState.Fatal]: "Fatal", | ||
[TaskState.Canceled]: "Canceled", | ||
}; | ||
|
||
export type TaskStateDict = Partial<Record<TaskState, string>>; | ||
|
||
export interface ICustomSettings { | ||
customDetailRenderer: ICustomRenderer; | ||
customStateCaptions: TaskStateDict; | ||
customSearchHelp?: JSX.Element; | ||
} | ||
|
||
const defaultValue: ICustomSettings = { | ||
customStateCaptions: TaskStateCaptions, | ||
customDetailRenderer: new CustomRenderer(), | ||
}; | ||
|
||
const CustomSettingsContext = createContext<ICustomSettings>(defaultValue); | ||
|
||
export const CustomSettingsProvider = ({ | ||
customStateCaptions, | ||
customSearchHelp, | ||
customDetailRenderer, | ||
children, | ||
}: PropsWithChildren<Partial<ICustomSettings>>) => { | ||
const stateCaptions = customStateCaptions || TaskStateCaptions; | ||
const renderer = customDetailRenderer || new CustomRenderer(); | ||
return ( | ||
<CustomSettingsContext.Provider | ||
value={{ customStateCaptions: stateCaptions, customDetailRenderer: renderer, customSearchHelp }}> | ||
{children} | ||
</CustomSettingsContext.Provider> | ||
); | ||
}; | ||
|
||
export const useCustomSettings = () => useContext(CustomSettingsContext); |
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
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.