Skip to content

Commit

Permalink
Default boolean config's to opposite of database default when enabling (
Browse files Browse the repository at this point in the history
Fixes #329)
  • Loading branch information
jaclarke committed Feb 23, 2024
1 parent 5baed33 commit a80ac78
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions shared/studio/state/sessionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,28 @@ import {
newPrimitiveValue,
parseEditorValue,
PrimitiveType,
valueToEditorValue,
} from "../components/dataEditor/utils";
import {fetchSessionState, storeSessionState} from "../idbStore";
import {connCtx} from "./connection";
import {dbCtx} from "./database";
import {instanceCtx} from "./instance";

type DraftStateItem = {
interface DraftStateItem {
active: boolean;
type: Frozen<SchemaType>;
description?: string;
value: Frozen<EditorValue | null>;
value: Frozen<EditorValue>;
error: boolean;
};
}

interface DraftStateGlobalItem extends Omit<DraftStateItem, "value"> {
value: Frozen<EditorValue | null>;
}

type DraftState = {
globals: {
[key: string]: DraftStateItem;
[key: string]: DraftStateGlobalItem;
};
config: {
[key: string]: DraftStateItem;
Expand Down Expand Up @@ -346,11 +351,18 @@ export class SessionState extends Model({
const values = result.result![0];
runInAction(() => (this.configValues = values));
for (const configName of this.configNames) {
if (this.draftState?.config[configName].value === null) {
const config = this.draftState?.config[configName];
if (config?.active === false) {
let value = values[configName];
if (typeof value === "boolean") {
value = !value;
}
objectActions.set(
this.draftState.config[configName],
this.draftState!.config[configName],
"value",
values[configName].toString()
frozen(
valueToEditorValue(value, config.type.data as PrimitiveType)
)
);
}
}
Expand Down

0 comments on commit a80ac78

Please sign in to comment.