back-testing-react 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/cjs/index.js +21 -21
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/index.js +21 -21
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/index.d.ts +11 -1
  6. package/package.json +5 -1
  7. package/src/components/back-testing-cat-legend/back-testing-cat-legend.css +1 -1
  8. package/src/components/back-testing-cat-legend/back-testing-cat-legend.tsx +7 -7
  9. package/src/components/back-testing-map/back-testing-map.css +1 -1
  10. package/src/components/back-testing-map/back-testing-map.service.ts +19 -4
  11. package/src/components/back-testing-map/back-testing-map.tsx +51 -18
  12. package/src/components/back-testing-map/back-testing-map.types.ts +68 -10
  13. package/src/components/back-testing-payout-info/back-testing-payout-info.css +112 -0
  14. package/src/components/back-testing-payout-info/back-testing-payout-info.tsx +371 -0
  15. package/src/components/back-testing-payout-info/back-testing-payout-info.types.ts +9 -0
  16. package/src/components/back-testing-stepper/back-testing-stepper.css +30 -0
  17. package/src/components/back-testing-stepper/back-testing-stepper.tsx +322 -0
  18. package/src/components/back-testing-stepper/back-testing-stepper.types.ts +41 -0
  19. package/src/components/back-testing-stepper/inputs/distance-input/distance-input.css +57 -0
  20. package/src/components/back-testing-stepper/inputs/distance-input/distance-input.stories.tsx +20 -0
  21. package/src/components/back-testing-stepper/inputs/distance-input/distance-input.tsx +93 -0
  22. package/src/components/back-testing-stepper/inputs/distance-input/distance-input.types.ts +41 -0
  23. package/src/components/back-testing-stepper/inputs/file-input/file-input.css +26 -0
  24. package/src/components/back-testing-stepper/inputs/file-input/file-input.stories.tsx +20 -0
  25. package/src/components/back-testing-stepper/inputs/file-input/file-input.tsx +43 -0
  26. package/src/components/back-testing-stepper/inputs/file-input/file-input.types.ts +10 -0
  27. package/src/components/back-testing-stepper/inputs/number-input/number-input.css +48 -0
  28. package/src/components/back-testing-stepper/inputs/number-input/number-input.stories.tsx +20 -0
  29. package/src/components/back-testing-stepper/inputs/number-input/number-input.tsx +55 -0
  30. package/src/components/back-testing-stepper/inputs/number-input/number-input.types.ts +12 -0
  31. package/src/components/back-testing-stepper/inputs/select-input/select-input.css +13 -0
  32. package/src/components/back-testing-stepper/inputs/select-input/select-input.stories.tsx +27 -0
  33. package/src/components/back-testing-stepper/inputs/select-input/select-input.tsx +63 -0
  34. package/src/components/back-testing-stepper/inputs/select-input/select-input.types.ts +8 -0
  35. package/src/components/back-testing-stepper/inputs/text-input/text-input.css +35 -0
  36. package/src/components/back-testing-stepper/inputs/text-input/text-input.stories.tsx +18 -0
  37. package/src/components/back-testing-stepper/inputs/text-input/text-input.tsx +32 -0
  38. package/src/components/back-testing-stepper/inputs/text-input/text-input.types.ts +6 -0
  39. package/src/components/back-testing-stepper/inputs/worldmap-search/worldmap-search.css +16 -0
  40. package/src/components/back-testing-stepper/inputs/worldmap-search/worldmap-search.stories.tsx +20 -0
  41. package/src/components/back-testing-stepper/inputs/worldmap-search/worldmap-search.tsx +151 -0
  42. package/src/components/back-testing-stepper/inputs/worldmap-search/worldmap-search.types.ts +11 -0
  43. package/src/components/back-testing-stepper/steps/input-anemometer/input-anemometer.css +0 -0
  44. package/src/components/back-testing-stepper/steps/input-anemometer/input-anemometer.tsx +188 -0
  45. package/src/components/back-testing-stepper/steps/input-anemometer/input-anemometer.types.ts +16 -0
  46. package/src/components/back-testing-stepper/steps/input-ciac/input-ciac.scss +0 -0
  47. package/src/components/back-testing-stepper/steps/input-ciac/input-ciac.tsx +225 -0
  48. package/src/components/back-testing-stepper/steps/input-ciac/input-ciac.types.ts +17 -0
  49. package/src/components/back-testing-stepper/steps/input-location/input-location.css +0 -0
  50. package/src/components/back-testing-stepper/steps/input-location/input-location.tsx +135 -0
  51. package/src/components/back-testing-stepper/steps/input-location/input-location.types.ts +16 -0
  52. package/src/components/back-testing-stepper/steps/input-proxy/input-proxy.css +0 -0
  53. package/src/components/back-testing-stepper/steps/input-proxy/input-proxy.tsx +173 -0
  54. package/src/components/back-testing-stepper/steps/input-proxy/input-proxy.types.ts +16 -0
  55. package/src/components/back-testing-stepper/steps/step.types.ts +58 -0
  56. package/src/components/back-testing-wizard/back-testing-wizard.css +36 -0
  57. package/src/components/back-testing-wizard/back-testing-wizard.stories.tsx +735 -0
  58. package/src/components/back-testing-wizard/back-testing-wizard.tsx +103 -0
  59. package/src/components/back-testing-wizard/back-testing-wizard.types.ts +13 -0
@@ -0,0 +1,173 @@
1
+ "use client"
2
+
3
+ import { MediaType, Payout, PayoutOption, PayoutWizardStepType, RadioChoice, WizardStep } from "../step.types";
4
+ import { LngLatLike } from "@mapbox/search-js-core";
5
+ import React, { forwardRef, useImperativeHandle } from "react";
6
+ import { FormControl, FormControlLabel, Radio, RadioGroup } from "@mui/material";
7
+ import InputFile from "../../inputs/file-input/file-input";
8
+ import Papa from 'papaparse';
9
+ import SelectInput from "../../inputs/select-input/select-input";
10
+ import { generateProxyRequest, PayoutRequest, ProxyRequest } from "../../../back-testing-map/back-testing-map.types";
11
+ import { InputProxyStepProps } from "./input-proxy.types";
12
+
13
+ const InputProxyStep = forwardRef<WizardStep, InputProxyStepProps>((props,ref) => {
14
+
15
+ const [payoutRequest] = React.useState<PayoutRequest>(props.request);
16
+ const [proxy] = React.useState<ProxyRequest>(payoutRequest.proxy);
17
+
18
+ const [latLng] = React.useState<LngLatLike | undefined>(payoutRequest.longitude != undefined && payoutRequest.latitude != undefined ? [payoutRequest.longitude,payoutRequest.latitude] : undefined);
19
+ const [proxyChoice, setProxyChoice] = React.useState<RadioChoice>(props.proxyChoice);
20
+
21
+ const [file, setFile] = React.useState<File | undefined>(undefined)
22
+ const [customPayouts, setCustomPayouts] = React.useState<Payout[] | undefined>(proxy.payouts)
23
+ const [payoutOption, setPayoutOption] = React.useState<number>(props.selectedPayoutOptionIndex);
24
+
25
+ const [fileError, setFileError] = React.useState<boolean>(false);
26
+ const [fileErrorMsg, setFileErrorMsg] = React.useState<string>("");
27
+ const FILE_ERROR = "Must upload a valid payout CSV or JSON";
28
+
29
+ function handleChoiceSelection(e: RadioChoice){
30
+ setFileError(false);
31
+ setFileErrorMsg("");
32
+ setCustomPayouts(undefined);
33
+ setFile(undefined);
34
+ setProxyChoice(e);
35
+ }
36
+
37
+ function saveState(){
38
+ if(latLng != undefined){
39
+ let newProxy = undefined
40
+ if(proxyChoice == RadioChoice.DEFAULT){
41
+ newProxy = generateProxyRequest(latLng as [number,number], 1000, props.payoutOptions[props.selectedPayoutOptionIndex].value, payoutRequest.proxy.enabled);
42
+ } else {
43
+ newProxy = generateProxyRequest(latLng as [number,number], 1000, customPayouts, payoutRequest.proxy.enabled);
44
+ }
45
+ props.onProxyRequestChange(newProxy);
46
+ props.onProxyChoiceChange(proxyChoice);
47
+ props.onPayoutOptionChange(payoutOption);
48
+ }
49
+ }
50
+
51
+ async function handleFileSelection(e:File){
52
+ setFileError(false);
53
+ setFileErrorMsg("");
54
+ if(e){
55
+ let data : Payout[] = [];
56
+ if(e.type == MediaType.JSON){
57
+ readJSONFile(e).then((json) => {return json});
58
+ } else if (e.type == MediaType.CSV){
59
+ readCSVFile(e);
60
+ } else {
61
+ console.log("UNSUPPORTED file");
62
+ }
63
+ }
64
+ }
65
+
66
+ const parseJSONFile = (file: Blob) =>
67
+ new Promise<Payout[]>((resolve, reject) => {
68
+ const fileReader = new FileReader()
69
+ fileReader.onload = event => {
70
+ if (event.target) {
71
+ resolve(JSON.parse(event.target.result as string) as Payout[])
72
+ }
73
+ }
74
+ fileReader.onerror = error => reject(error)
75
+ fileReader.readAsText(file)
76
+ })
77
+
78
+ async function readJSONFile(file: Blob) {
79
+ const data = await parseJSONFile(file);
80
+ setCustomPayouts(data);
81
+ };
82
+
83
+ function readCSVFile(file: any) {
84
+ Papa.parse<Payout>(file, {
85
+ complete: (result) => {
86
+ setCustomPayouts(result.data);
87
+ },
88
+ header: true,
89
+ dynamicTyping: true
90
+ });
91
+ };
92
+
93
+ function validateStep() : boolean {
94
+ let isProxyChoiceError = (proxyChoice == RadioChoice.CUSTOM && customPayouts == undefined)
95
+ if(isProxyChoiceError){
96
+ setFileError(true);
97
+ setFileErrorMsg(FILE_ERROR);
98
+ } else {
99
+ setFileError(false);
100
+ setFileErrorMsg("");
101
+ }
102
+ return !isProxyChoiceError;
103
+ }
104
+
105
+ useImperativeHandle(ref, () => ({
106
+ handleNext(){
107
+ const isValid = validateStep();
108
+ if(isValid){
109
+ if(latLng != undefined){
110
+ saveState();
111
+ props.onStepChange(PayoutWizardStepType.INPUT_ANEMOMETER_DETAILS);
112
+ props.onActiveStepChange(props.activeStep + 1)
113
+ }
114
+ }
115
+ },
116
+
117
+ handleBack(){
118
+ if(latLng != undefined){
119
+ saveState();
120
+ props.onStepChange(PayoutWizardStepType.INPUT_LOCATION);
121
+ props.onActiveStepChange(props.activeStep - 1)
122
+ }
123
+ }
124
+ }));
125
+
126
+ function updatePayoutOption(index: number){
127
+ setPayoutOption(index);
128
+ }
129
+
130
+ return (
131
+ <div>
132
+ <FormControl sx={{width:'100%'}}>
133
+ <RadioGroup
134
+ aria-labelledby="demo-radio-buttons-group-label"
135
+ sx={{width:'100%'}}
136
+ value={proxyChoice}
137
+ onChange={(e) => handleChoiceSelection((e.target as HTMLInputElement).value as RadioChoice)}
138
+ name="radio-buttons-group">
139
+ <FormControlLabel
140
+ value={RadioChoice.DEFAULT}
141
+ sx={{pt:2}}
142
+ control={<Radio />}
143
+ label="Preconfigured Table" />
144
+ <div className="">
145
+ <SelectInput
146
+ disabled={proxyChoice != RadioChoice.DEFAULT}
147
+ onLoad={(e:PayoutOption) => updatePayoutOption(e)}
148
+ onChange={(e:PayoutOption) => updatePayoutOption(e)}
149
+ defaultValue={payoutOption}
150
+ items={props.payoutOptions.map((option, index) => {return {key:option.key, value:index}})}>
151
+ </SelectInput>
152
+ </div>
153
+ <FormControlLabel
154
+ value={RadioChoice.CUSTOM}
155
+ control={<Radio />}
156
+ label="Upload table" />
157
+ </RadioGroup>
158
+ </FormControl>
159
+ <div className="ptop-10 pbot-10">
160
+ <InputFile
161
+ disabled={proxyChoice != RadioChoice.CUSTOM}
162
+ value={file}
163
+ error={fileError}
164
+ errorMessage={fileErrorMsg}
165
+ onChange={handleFileSelection}
166
+ isFileSelected={proxyChoice == RadioChoice.CUSTOM && customPayouts != undefined}
167
+ accept=".csv,.json"/>
168
+ </div>
169
+ </div>
170
+ );
171
+ })
172
+
173
+ export default InputProxyStep
@@ -0,0 +1,16 @@
1
+ import { PayoutRequest, ProxyRequest } from "../../../back-testing-map/back-testing-map.types"
2
+ import { Payout, PayoutOption, PayoutWizardStepType, RadioChoice } from "../step.types"
3
+
4
+ export interface InputProxyStepProps {
5
+ mapInstanceRef: React.MutableRefObject<any>,
6
+ activeStep: number,
7
+ onActiveStepChange: (e: number) => void
8
+ onStepChange: (e: PayoutWizardStepType) => void,
9
+ onProxyChoiceChange: (e:RadioChoice) => void,
10
+ onPayoutOptionChange: (e:number) => void,
11
+ onProxyRequestChange: (e:ProxyRequest) => void,
12
+ request: PayoutRequest,
13
+ selectedPayoutOptionIndex: number
14
+ payoutOptions: {key:string,value: Payout[]}[]
15
+ proxyChoice: RadioChoice
16
+ }
@@ -0,0 +1,58 @@
1
+ import { AnemometerRequest, CIACRequest, ProxyRequest } from "../../back-testing-map/back-testing-map.types";
2
+
3
+ export interface WizardStep {
4
+ handleBack: () => void,
5
+ handleNext: () => void
6
+ }
7
+
8
+ export enum PayoutWizardStepType {
9
+ INPUT_LOCATION = '__input_location',
10
+ INPUT_PROXY_DETAILS = '__input_proxy_details',
11
+ INPUT_ANEMOMETER_DETAILS = '__input_anemometer_details',
12
+ INPUT_CIAC_DETAILS = '__input_ciac_details',
13
+ CALCULATE_PAYOUTS = '__calc_payouts',
14
+ DISPLAY_PAYOUTS = '__display_payouts',
15
+
16
+ // Simplified Steps
17
+ SIMPLIFIED_INPUT_LOCATION = '__simplified_input_location',
18
+ }
19
+
20
+ export interface PayoutWizardStep {
21
+ step: PayoutWizardStepType
22
+ label: string
23
+ description: string
24
+ componentRef: React.RefObject<WizardStep>
25
+ istoggable:boolean,
26
+ enabled: [boolean, React.Dispatch<React.SetStateAction<boolean>>]
27
+ }
28
+
29
+ export enum RadioChoice {
30
+ DEFAULT = '__default',
31
+ CUSTOM = '__custom'
32
+ }
33
+
34
+ export enum PayoutOption {
35
+ STANDARD_74_119 = 234875,
36
+ RESIDENTIAL_65_110 = 481734,
37
+ RESIDENTIAL_65_130 = 598652,
38
+ CIAC_10_25_50_75_100 = 861543,
39
+ CIAC_30_60_100_100_100 = 329134,
40
+ }
41
+
42
+ export enum MediaType {
43
+ JSON = 'application/json',
44
+ CSV = 'text/csv'
45
+ }
46
+
47
+ export interface Payout {
48
+ category: number,
49
+ payout: number
50
+ }
51
+
52
+ export function getConfiguredPayoutTable(index:number, options: Payout[][]) : Payout[] {
53
+ return options[index];
54
+ }
55
+
56
+ export function getPayouts(){
57
+
58
+ }
@@ -0,0 +1,36 @@
1
+ body{
2
+ padding: 0;
3
+ margin: 0;
4
+ }
5
+
6
+ .wizard-container{
7
+
8
+ --side-panel-width: 400px;
9
+ --side-panel-bg-color: rgb(244,246,248);
10
+
11
+ --primary-color-blue: rgb(30,39,88);
12
+ --primary-color-red: rgb(153,27,30);
13
+ --accent-color-blue: rgb(68,114,196);
14
+ --accent-color-red: rgb(231,29,44);
15
+ --accent-color-gray: rgb(190,192,194);
16
+
17
+ font-family: system-ui, sans-serif;
18
+ width: var(--page-width);
19
+ height: inherit;
20
+ padding: 0;
21
+ margin: 0;
22
+ display:grid;
23
+ grid-template-columns: var(--side-panel-width) auto;
24
+ }
25
+
26
+ .wizard-container > .side-panel{
27
+ height: inherit;
28
+ width: var(--side-panel-width);
29
+ background-color: var(--side-panel-bg-color);
30
+ border-right: 1px solid lightgray;
31
+ }
32
+
33
+ .wizard-container > .main-panel{
34
+ height: inherit;
35
+ width: 100%;
36
+ }