Skip to content

Commit

Permalink
[#100] Add docs for luck (and other menu items at the same time)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-At-Home committed Jul 17, 2020
1 parent e71e020 commit 972eba8
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/components/LineupStatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ type Props = {

const LineupStatsTable: React.FunctionComponent<Props> = ({lineupStats, teamStats, rosterStats, startingState, onChangeState}) => {

const server = (typeof window === `undefined`) ? //(ensures SSR code still compiles)
"server" : window.location.hostname

/** Only show help for diagnstic on/off on main page */
const showHelp = !_.startsWith(server, "cbb-on-off-analyzer");

// 1] Data Model

// 2] State
Expand Down Expand Up @@ -270,6 +276,7 @@ const LineupStatsTable: React.FunctionComponent<Props> = ({lineupStats, teamStat
offLuck={luckAdj[0]}
defLuck={luckAdj[1]}
baseline={luckConfig.base}
showHelp={showHelp}
/>, "small pt-2"
) ] : [] ,
[ GenericTableOps.buildRowSeparator() ]
Expand Down Expand Up @@ -382,6 +389,7 @@ const LineupStatsTable: React.FunctionComponent<Props> = ({lineupStats, teamStat
onHide={() => setShowLuckConfig(false)}
onSave={(l: LuckParams) => setLuckConfig(l)}
luck={luckConfig}
showHelp={showHelp}
/>
<Form.Row>
<Form.Group as={Col} sm="8">
Expand Down Expand Up @@ -414,6 +422,7 @@ const LineupStatsTable: React.FunctionComponent<Props> = ({lineupStats, teamStat
text="Adjust for Luck"
truthVal={adjustForLuck}
onSelect={() => setAdjustForLuck(!adjustForLuck)}
helpLink={showHelp ? "https://hoop-explorer.blogspot.com/2020/07/luck-adjustment-details.html" : undefined}
/>
<Dropdown.Divider />
<GenericTogglingMenuItem
Expand Down
1 change: 1 addition & 0 deletions src/components/RosterStatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ const RosterStatsTable: React.FunctionComponent<Props> = ({gameFilterParams, tea
text="Show Positional diagnostics"
truthVal={showPositionDiags}
onSelect={() => setShowPositionDiags(!showPositionDiags)}
helpLink={showHelp ? "https://hoop-explorer.blogspot.com/2020/05/classifying-college-basketball.html" : undefined}
/>
</GenericTogglingMenu>
</Form.Group>
Expand Down
2 changes: 2 additions & 0 deletions src/components/TeamReportStatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,13 @@ const TeamReportStatsTable: React.FunctionComponent<Props> = ({lineupReport, sta
text={<span>Show replacement On-Off <span className="badge badge-pill badge-info">alpha!</span></span>}
truthVal={incReplacementOnOff}
onSelect={() => setIncReplacementOnOff(!incReplacementOnOff)}
helpLink={showHelp ? "https://hoop-explorer.blogspot.com/2020/04/replacement-on-off-heres-elevator-pitch.html" : undefined}
/>
<GenericTogglingMenuItem
text={<span>Show RAPM <span className="badge badge-pill badge-info">experimental!</span></span>}
truthVal={incRapm}
onSelect={() => setIncRapm(!incRapm)}
helpLink={showHelp ? "https://hoop-explorer.blogspot.com/2020/03/understanding-team-report-onoff-page.html#RAPM" : undefined}
/>
<Dropdown.Divider />
<GenericTogglingMenuItem
Expand Down
11 changes: 11 additions & 0 deletions src/components/TeamStatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ type Props = {

const TeamStatsTable: React.FunctionComponent<Props> = ({gameFilterParams, teamStats, rosterStats, onChangeState}) => {

const server = (typeof window === `undefined`) ? //(ensures SSR code still compiles)
"server" : window.location.hostname

/** Only show help for diagnstic on/off on main page */
const showHelp = !_.startsWith(server, "cbb-on-off-analyzer");

// 1] Data Model

const [ adjustForLuck, setAdjustForLuck ] = useState(_.isNil(gameFilterParams.onOffLuck) ?
Expand Down Expand Up @@ -145,6 +151,7 @@ const TeamStatsTable: React.FunctionComponent<Props> = ({gameFilterParams, teamS
offLuck={luckAdjustment.on[0]}
defLuck={luckAdjustment.on[1]}
baseline={luckConfig.base}
showHelp={showHelp}
/>, "small pt-2"
) ] : [] ,
[ GenericTableOps.buildRowSeparator() ]
Expand All @@ -158,6 +165,7 @@ const TeamStatsTable: React.FunctionComponent<Props> = ({gameFilterParams, teamS
offLuck={luckAdjustment.off[0]}
defLuck={luckAdjustment.off[1]}
baseline={luckConfig.base}
showHelp={showHelp}
/>, "small pt-2"
) ] : [] ,
[ GenericTableOps.buildRowSeparator() ]
Expand All @@ -171,6 +179,7 @@ const TeamStatsTable: React.FunctionComponent<Props> = ({gameFilterParams, teamS
offLuck={luckAdjustment.baseline[0]}
defLuck={luckAdjustment.baseline[1]}
baseline={luckConfig.base}
showHelp={showHelp}
/>, "small pt-2"
) ] : [] ,
[ GenericTableOps.buildRowSeparator() ]
Expand Down Expand Up @@ -200,6 +209,7 @@ const TeamStatsTable: React.FunctionComponent<Props> = ({gameFilterParams, teamS
onHide={() => setShowLuckConfig(false)}
onSave={(l: LuckParams) => setLuckConfig(l)}
luck={luckConfig}
showHelp={showHelp}
/>
<Form.Row>
<Col sm="11"/>
Expand All @@ -209,6 +219,7 @@ const TeamStatsTable: React.FunctionComponent<Props> = ({gameFilterParams, teamS
text="Adjust for Luck"
truthVal={adjustForLuck}
onSelect={() => setAdjustForLuck(!adjustForLuck)}
helpLink={showHelp ? "https://hoop-explorer.blogspot.com/2020/07/luck-adjustment-details.html" : undefined}
/>
<Dropdown.Divider />
<GenericTogglingMenuItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (no individu
onHide={[Function]}
onSave={[Function]}
show={false}
showHelp={true}
/>
<FormRow>
<FormGroup
Expand Down Expand Up @@ -70,6 +71,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (no individu
truthVal={false}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/07/luck-adjustment-details.html"
onSelect={[Function]}
text="Adjust for Luck"
truthVal={false}
Expand Down Expand Up @@ -5578,6 +5580,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (with indivi
onHide={[Function]}
onSave={[Function]}
show={false}
showHelp={true}
/>
<FormRow>
<FormGroup
Expand Down Expand Up @@ -5631,6 +5634,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (with indivi
truthVal={false}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/07/luck-adjustment-details.html"
onSelect={[Function]}
text="Adjust for Luck"
truthVal={true}
Expand Down Expand Up @@ -6850,6 +6854,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (with indivi
"samplePoss": 196,
}
}
showHelp={true}
/>,
},
GenericTableSeparator {
Expand Down Expand Up @@ -7562,6 +7567,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (with indivi
"samplePoss": 111,
}
}
showHelp={true}
/>,
},
GenericTableSeparator {
Expand Down Expand Up @@ -8274,6 +8280,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (with indivi
"samplePoss": 102,
}
}
showHelp={true}
/>,
},
GenericTableSeparator {
Expand Down Expand Up @@ -8562,6 +8569,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (with indivi
onHide={[Function]}
onSave={[Function]}
show={false}
showHelp={true}
/>
<FormRow>
<FormGroup
Expand Down Expand Up @@ -8615,6 +8623,7 @@ exports[`LineupStatsTable LineupStatsTable - should create snapshot (with indivi
truthVal={false}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/07/luck-adjustment-details.html"
onSelect={[Function]}
text="Adjust for Luck"
truthVal={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ exports[`RosterStatsTable RosterStatsTable (!expanded) - should create snapshot
truthVal={false}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/05/classifying-college-basketball.html"
onSelect={[Function]}
text="Show Positional diagnostics"
truthVal={false}
Expand Down Expand Up @@ -2654,6 +2655,7 @@ exports[`RosterStatsTable RosterStatsTable (baseline only, !expanded) - should c
truthVal={false}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/05/classifying-college-basketball.html"
onSelect={[Function]}
text="Show Positional diagnostics"
truthVal={false}
Expand Down Expand Up @@ -4109,6 +4111,7 @@ exports[`RosterStatsTable RosterStatsTable (baseline only, expanded) - should cr
truthVal={false}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/05/classifying-college-basketball.html"
onSelect={[Function]}
text="Show Positional diagnostics"
truthVal={false}
Expand Down Expand Up @@ -6074,6 +6077,7 @@ exports[`RosterStatsTable RosterStatsTable (expanded) - should create snapshot 1
truthVal={false}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/05/classifying-college-basketball.html"
onSelect={[Function]}
text="Show Positional diagnostics"
truthVal={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ exports[`TeamReportStatsTable TeamReportStatsTable - should create snapshot (all
truthVal={true}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/04/replacement-on-off-heres-elevator-pitch.html"
onSelect={[Function]}
text={
<span>
Expand All @@ -1651,6 +1652,7 @@ exports[`TeamReportStatsTable TeamReportStatsTable - should create snapshot (all
truthVal={true}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/03/understanding-team-report-onoff-page.html#RAPM"
onSelect={[Function]}
text={
<span>
Expand Down Expand Up @@ -16148,6 +16150,7 @@ exports[`TeamReportStatsTable TeamReportStatsTable - should create snapshot (rep
truthVal={true}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/04/replacement-on-off-heres-elevator-pitch.html"
onSelect={[Function]}
text={
<span>
Expand All @@ -16162,6 +16165,7 @@ exports[`TeamReportStatsTable TeamReportStatsTable - should create snapshot (rep
truthVal={true}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/03/understanding-team-report-onoff-page.html#RAPM"
onSelect={[Function]}
text={
<span>
Expand Down Expand Up @@ -53453,6 +53457,7 @@ exports[`TeamReportStatsTable TeamReportStatsTable - should create snapshot (rep
truthVal={true}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/04/replacement-on-off-heres-elevator-pitch.html"
onSelect={[Function]}
text={
<span>
Expand All @@ -53467,6 +53472,7 @@ exports[`TeamReportStatsTable TeamReportStatsTable - should create snapshot (rep
truthVal={true}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/03/understanding-team-report-onoff-page.html#RAPM"
onSelect={[Function]}
text={
<span>
Expand Down Expand Up @@ -57508,6 +57514,7 @@ exports[`TeamReportStatsTable TeamReportStatsTable - should create snapshot 1`]
truthVal={true}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/04/replacement-on-off-heres-elevator-pitch.html"
onSelect={[Function]}
text={
<span>
Expand All @@ -57522,6 +57529,7 @@ exports[`TeamReportStatsTable TeamReportStatsTable - should create snapshot 1`]
truthVal={false}
/>
<GenericTogglingMenuItem
helpLink="https://hoop-explorer.blogspot.com/2020/03/understanding-team-report-onoff-page.html#RAPM"
onSelect={[Function]}
text={
<span>
Expand Down
4 changes: 3 additions & 1 deletion src/components/diags/LuckAdjDiagView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ type Props = {
offLuck: OffLuckAdjustmentDiags,
defLuck: DefLuckAdjustmentDiags,
baseline: LuckAdjustmentBaseline,
showHelp: boolean,
showDetailsOverride?: boolean
};
const LuckAdjDiagView: React.FunctionComponent<Props> = ({name, offLuck, defLuck, baseline, showDetailsOverride}) => {
const LuckAdjDiagView: React.FunctionComponent<Props> = ({name, offLuck, defLuck, baseline, showHelp, showDetailsOverride}) => {

const topRef = React.createRef<HTMLDivElement>();

Expand All @@ -45,6 +46,7 @@ const LuckAdjDiagView: React.FunctionComponent<Props> = ({name, offLuck, defLuck
return <span ref={topRef}>
<span>
<b>Luck Adjustment diagnostics [{name}]</b>
{showHelp ? <span> <a target="_blank" href="https://hoop-explorer.blogspot.com/2020/07/luck-adjustment-details.html">(?)</a></span> : null}
&nbsp;off=[<b>{o.deltaOffAdjEff.toFixed(1)}</b>], def=[<b>{d.deltaDefAdjEff.toFixed(1)}</b>], margin=[<b>{(o.deltaOffAdjEff - d.deltaDefAdjEff).toFixed(1)}</b>] pts/100
&nbsp;(<a href="#" onClick={(event) => { event.preventDefault(); setShowDetails(!showDetails) }}>show {showDetails ? "less" : "more"}</a>)
</span>
Expand Down
2 changes: 2 additions & 0 deletions src/components/diags/__tests__/LuckAdjDiagView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe("LuckAdjDiagView", () => {
offLuck={sampleOffOnOffLuckDiagnostics}
defLuck={sampleDefOnOffLuckDiagnostics}
baseline="season"
showHelp={false}
/>
);
expect(toJson(wrapper)).toMatchSnapshot();
Expand All @@ -26,6 +27,7 @@ describe("LuckAdjDiagView", () => {
offLuck={sampleOffOnOffLuckDiagnostics}
defLuck={sampleDefOnOffLuckDiagnostics}
baseline="baseline"
showHelp={true}
showDetailsOverride={true}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ exports[`LuckAdjDiagView LuckAdjDiagView - should create snapshot (baseline, ove
Test2
]
</b>
<span>
<a
href="https://hoop-explorer.blogspot.com/2020/07/luck-adjustment-details.html"
target="_blank"
>
(?)
</a>
</span>
 off=[
<b>
-1.8
Expand Down
8 changes: 5 additions & 3 deletions src/components/shared/GenericTogglingMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ import { faCheck } from '@fortawesome/free-solid-svg-icons'
type Props = {
readonly text: string | React.ReactNode,
readonly truthVal: boolean,
readonly onSelect: () => void
readonly onSelect: () => void,
readonly helpLink?: string
};

const GenericTogglingMenuItem: React.FunctionComponent<Props> = ({text, truthVal, onSelect}) => {
const GenericTogglingMenuItem: React.FunctionComponent<Props> = ({text, truthVal, onSelect, helpLink}) => {

return <Dropdown.Item as={Button}>
<div onClick={() => onSelect()}>
<div onClick={(e: any) => { if (!e.target.href) onSelect() }}>
{_.isString(text) ? <span>{text}</span> : text}
{helpLink ? <span>&nbsp;<a target="_blank" href={helpLink}>(?)</a></span> : null}
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
{truthVal ? <FontAwesomeIcon icon={faCheck}/> : null}
</div>
Expand Down
9 changes: 6 additions & 3 deletions src/components/shared/LuckConfigModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ type Props = {
show: boolean,
onHide: () => void,
onSave: (luck: LuckParams) => void,
luck: LuckParams
luck: LuckParams,
showHelp: boolean
};
const LuckConfigModal: React.FunctionComponent<Props> = ({onSave, luck, ...props}) => {
const LuckConfigModal: React.FunctionComponent<Props> = ({onSave, luck, showHelp, ...props}) => {

// State decomposition:
const [ generalLuckBase, setGeneralLuckBase ] = useState(luck.base as "baseline" | "season");
return <Modal {...props}>
<Modal.Header closeButton>
<Modal.Title>Luck Adjustment Config</Modal.Title>
<Modal.Title>Luck Adjustment Config</Modal.Title>&nbsp;{showHelp ?
<a target="_blank" href="https://hoop-explorer.blogspot.com/2020/07/luck-adjustment-details.html">(?)</a> : null
}
</Modal.Header>
<Modal.Body>
<Card className="w-100">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe("GenericTogglingMenu", () => {
text="Test2"
truthVal={true}
onSelect={() => ""}
helpLink="https://test.com"
/>
<GenericTogglingMenuItem
text={<span>Test3</span>}
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/__tests__/LuckConfigModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("LuckConfigModal", () => {
onHide={() => {}}
onSave={(l: LuckParams) => {}}
luck={{base: "baseline"}}
showHelp={true}
/>
</div>
);
Expand Down
Loading

1 comment on commit 972eba8

@vercel
Copy link

@vercel vercel bot commented on 972eba8 Jul 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.