Update uiSlice.ts
This commit is contained in:
parent
d571744659
commit
a1e1ecf093
1 changed files with 31 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { Tool } from "core";
|
||||
import { RuleWithSource, Tool } from "core";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "core/tools/builtIn";
|
||||
import {
|
||||
defaultOnboardingCardState,
|
||||
|
|
@ -12,9 +12,12 @@ export type ToolPolicy =
|
|||
| "allowedWithoutPermission"
|
||||
| "disabled";
|
||||
|
||||
export type RulePolicy = "always" | "auto" | "never";
|
||||
|
||||
export type ToolGroupPolicy = "include" | "exclude";
|
||||
|
||||
export type ToolPolicies = { [toolName: string]: ToolPolicy };
|
||||
export type RulePolicies = { [ruleName: string]: RulePolicy };
|
||||
export type ToolGroupPolicies = { [toolGroupName: string]: ToolGroupPolicy };
|
||||
|
||||
type UIState = {
|
||||
|
|
@ -27,10 +30,12 @@ type UIState = {
|
|||
shouldAddFileForEditing: boolean;
|
||||
toolSettings: ToolPolicies;
|
||||
toolGroupSettings: ToolGroupPolicies;
|
||||
ruleSettings: RulePolicies;
|
||||
ttsActive: boolean;
|
||||
};
|
||||
|
||||
export const DEFAULT_TOOL_SETTING: ToolPolicy = "allowedWithPermission";
|
||||
export const DEFAULT_RULE_SETTING: RulePolicy = "auto";
|
||||
|
||||
export const uiSlice = createSlice({
|
||||
name: "ui",
|
||||
|
|
@ -62,6 +67,7 @@ export const uiSlice = createSlice({
|
|||
toolGroupSettings: {
|
||||
[BUILT_IN_GROUP_NAME]: "include",
|
||||
},
|
||||
ruleSettings: {},
|
||||
} as UIState,
|
||||
reducers: {
|
||||
setOnboardingCard: (
|
||||
|
|
@ -126,6 +132,28 @@ export const uiSlice = createSlice({
|
|||
state.toolGroupSettings[action.payload] = "include";
|
||||
}
|
||||
},
|
||||
// Rules
|
||||
addRule: (state, action: PayloadAction<RuleWithSource>) => {
|
||||
state.ruleSettings[action.payload.name] = DEFAULT_RULE_SETTING;
|
||||
},
|
||||
toggleRuleSetting: (state, action: PayloadAction<string>) => {
|
||||
const setting = state.ruleSettings[action.payload];
|
||||
|
||||
switch (setting) {
|
||||
case "auto":
|
||||
state.ruleSettings[action.payload] = "always";
|
||||
break;
|
||||
case "always":
|
||||
state.ruleSettings[action.payload] = "never";
|
||||
break;
|
||||
case "never":
|
||||
state.ruleSettings[action.payload] = "auto";
|
||||
break;
|
||||
default:
|
||||
state.ruleSettings[action.payload] = DEFAULT_RULE_SETTING;
|
||||
break;
|
||||
}
|
||||
},
|
||||
setTTSActive: (state, { payload }: PayloadAction<boolean>) => {
|
||||
state.ttsActive = payload;
|
||||
},
|
||||
|
|
@ -142,6 +170,8 @@ export const {
|
|||
toggleToolSetting,
|
||||
toggleToolGroupSetting,
|
||||
addTool,
|
||||
addRule,
|
||||
toggleRuleSetting,
|
||||
setTTSActive,
|
||||
} = uiSlice.actions;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue