Skip to content

Commit

Permalink
Removed unneeded vars
Browse files Browse the repository at this point in the history
  • Loading branch information
tkmcmaster committed Dec 6, 2024
1 parent 58243e9 commit cf3fbd6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 91 deletions.
48 changes: 0 additions & 48 deletions guide/results-viewer-react/src/components/YamlVars/DropDown.tsx

This file was deleted.

43 changes: 6 additions & 37 deletions guide/results-viewer-react/src/components/YamlVars/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { CSSTransition, TransitionGroup } from "react-transition-group";
import { Checkbox, Div, InputsDiv, Label, Span} from "../YamlStyles";
import {
DEV_KEY_BETA,
LOAD_TIME_DEFAULT,
PEAK_LOAD_DEFAULT,
PewPewVars,
RAMP_TIME_DEFAULT,
SESSION_ID_DEFAULT
} from "../../util/yamlwriter";
import { LogLevel, log } from "../../util/log";
import React, { useEffect, useRef, useState } from "react";
import QuestionBubble from "../YamlQuestionBubble";
import VarsDropDown from "./DropDown";
import { uniqueId } from "../../util/clientutil";

export type PewPewVarsStringType = "name" | "value";
Expand All @@ -20,20 +17,17 @@ interface DefaultVariables {
rampTime: boolean;
loadTime: boolean;
peakLoad: boolean;
devKey: boolean;
}

type DefaultVariablesType = keyof DefaultVariables;

// This is the default state of all checkboxes and drop downs when the UI is initially loaded
const defaultUI: DefaultVariables = {
devKey: false,
rampTime: true,
loadTime: true,
peakLoad: true,
sessionId: true
};
const defaultEnvironment = DEV_KEY_BETA;

export interface VarsProps {
addVar: (pewpewVar: PewPewVars) => void;
Expand All @@ -49,24 +43,21 @@ interface VarsState extends DefaultVariables {
nameReady: boolean;
valueReady: boolean;
defaultVars: boolean;
environment: string;
}
export const VARS = "vars";
const SESSION_ID = "sessionId";
const RAMP_TIME = "rampTime";
const LOAD_TIME = "loadTime";
const PEAK_LOAD = "peakLoad";
const DEV_KEY = "devKey";
const DEFAULT_VARS = "defaultVars";

export const emptyVar = (varId: string = uniqueId()): PewPewVars => ({ id: varId, name: "", value: "" });
export const devKeyVar = (environment: string): PewPewVars => ({ id: DEV_KEY, name: DEV_KEY, value: environment });
export const rampTimeVar = (): PewPewVars => ({ id: RAMP_TIME, name: RAMP_TIME, value: RAMP_TIME_DEFAULT });
export const loadTimeVar = (): PewPewVars => ({ id: LOAD_TIME, name: LOAD_TIME, value: LOAD_TIME_DEFAULT });
export const peakLoadVar = (): PewPewVars => ({ id: PEAK_LOAD, name: PEAK_LOAD, value: PEAK_LOAD_DEFAULT });
export const sessionIdVar = (): PewPewVars => ({ id: SESSION_ID, name: SESSION_ID, value: SESSION_ID_DEFAULT });

function getDefaultVar (varName: DefaultVariablesType, environment: string): PewPewVars {
function getDefaultVar (varName: DefaultVariablesType): PewPewVars {
switch (varName) {
case SESSION_ID:
return sessionIdVar();
Expand All @@ -76,18 +67,16 @@ function getDefaultVar (varName: DefaultVariablesType, environment: string): Pew
return loadTimeVar();
case PEAK_LOAD:
return peakLoadVar();
case DEV_KEY:
return devKeyVar(environment);
default:
throw new Error("getDefaultVar Invalid varName: " + varName);
}
}

export function getDefaultVars (defaultVars: DefaultVariables = defaultUI, environment: string = defaultEnvironment): PewPewVars[] {
export function getDefaultVars (defaultVars: DefaultVariables = defaultUI): PewPewVars[] {
const pewpewVars: PewPewVars[] = [];
for (const [varName, isEnabled] of Object.entries(defaultVars)) {
if (isEnabled) {
pewpewVars.push(getDefaultVar(varName as DefaultVariablesType, environment));
pewpewVars.push(getDefaultVar(varName as DefaultVariablesType));
}
}

Expand All @@ -99,8 +88,7 @@ export function Vars ({ authenticated, defaultYaml, ...props }: VarsProps) {
nameReady: false,
valueReady: false,
defaultVars: defaultYaml,
...defaultUI,
environment: defaultEnvironment
...defaultUI
};
/** Map to keep id's unique */
const varsMap = new Map(props.vars.map((pewpewVar) => ([pewpewVar.id, pewpewVar])));
Expand Down Expand Up @@ -142,7 +130,7 @@ export function Vars ({ authenticated, defaultYaml, ...props }: VarsProps) {
// Add/delete from varsMap/vars
if (newChecked && !varsMap.has(varsType)) {
// Add it (will update the map when it comes back in via props)
const defaultVar = getDefaultVar(varsType, state.environment);
const defaultVar = getDefaultVar(varsType);
props.addVar(defaultVar);
} else if (!newChecked && varsMap.has(varsType)) {
// Remove it (will update the map when it comes back in via props)
Expand All @@ -165,21 +153,10 @@ export function Vars ({ authenticated, defaultYaml, ...props }: VarsProps) {
};

const clearAllVars = () => {
updateState({ defaultVars: false, sessionId: false, rampTime: false, loadTime: false, peakLoad: false, devKey: false });
updateState({ defaultVars: false, sessionId: false, rampTime: false, loadTime: false, peakLoad: false });
props.clearAllVars();
};

const changeEnvironment = (event: React.ChangeEvent<HTMLSelectElement>) => {
updateState({ environment: event.target.value });
const devKey = varsMap.get(DEV_KEY);
if (devKey) {
devKey.value = event.target.value;
props.changeVar(devKey);
} else {
log("Environment changed without devKey variable existing", LogLevel.WARN);
}
};

// https://github.com/reactjs/react-transition-group/issues/904
// http://reactcommunity.org/react-transition-group/transition#Transition-prop-nodeRef
const nodeRef = useRef(null);
Expand Down Expand Up @@ -219,14 +196,6 @@ export function Vars ({ authenticated, defaultYaml, ...props }: VarsProps) {
<QuestionBubble text="peakLoad included"></QuestionBubble>
<Checkbox type="checkbox" id={PEAK_LOAD} onChange={(event: React.ChangeEvent<HTMLInputElement>) => switchDefault(PEAK_LOAD, event.target.checked)} checked={state.peakLoad}/>
</Span>
<div>
<Span>
<Label htmlFor={DEV_KEY}> devkey: </Label>
<QuestionBubble text="devKey included"></QuestionBubble>
<input type="checkbox" id={DEV_KEY} onChange={(event) => switchDefault(DEV_KEY, event.target.checked)} checked={state.devKey}/>
</Span>
<VarsDropDown display={state.devKey} onChange={changeEnvironment} />
</div>
</Div>
<TransitionGroup className="loadPatter-section_list" nodeRef={nodeRef}>
{Array.from(varsMap.values()).map((pewpewVar: PewPewVars) => (
Expand Down
5 changes: 2 additions & 3 deletions guide/results-viewer-react/src/components/YamlVars/story.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DEV_KEY_BETA, PewPewVars } from "../../util/yamlwriter";
import { DisplayDivBody, DisplayDivMain } from "../YamlWriterForm";
import type { Meta, StoryFn } from "@storybook/react";
import { Vars, VarsProps} from ".";
import { GlobalStyle } from "../Global";
import { PewPewVars } from "../../util/yamlwriter";
import React from "react";

const props: VarsProps = {
Expand Down Expand Up @@ -35,8 +35,7 @@ const propsLoaded: VarsProps = { ...props,
{ id: "sessionId", name: "sessionId", value: "${SESSIONID}" },
{ id: "rampTime", name: "rampTime", value: "${RAMP_TIME}" },
{ id: "loadTime", name: "loadTime", value: "${LOAD_TIME}" },
{ id: "peakLoad", name: "peakLoad", value: "${PEAK_LOAD}" },
{ id: "devKey", name: "devKey", value: DEV_KEY_BETA }
{ id: "peakLoad", name: "peakLoad", value: "${PEAK_LOAD}" }
]
};

Expand Down
3 changes: 0 additions & 3 deletions guide/results-viewer-react/src/util/yamlwriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,3 @@ export const SESSION_ID_DEFAULT = "${SESSIONID}";
export const RAMP_TIME_DEFAULT = "${RAMP_TIME}";
export const LOAD_TIME_DEFAULT = "${LOAD_TIME}";
export const PEAK_LOAD_DEFAULT = "${PEAK_LOAD}";

export const DEV_KEY_BETA = "WCQY-7J1Q-GKVV-7DNM-SQ5M-9Q5H-JX3H-CMJK";
export const DEV_KEY_PROD = "Q4JW-NBZX-TWHZ-ZZDJ-LSP9-G15N-NLC8-P1M3";

0 comments on commit cf3fbd6

Please sign in to comment.