-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added some additional linting rules to autofix prettier related… #59
Changes from all commits
5c7601d
1fb9557
08bc4d3
a66bab1
6392951
dc202c1
d728554
012ce71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,4 @@ | |
"build": "yarn build:clean && yarn typescript:build", | ||
"prepublishOnly": "yarn build" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { hiddenFileAnchorId } from '../selectors'; | ||
import { RunContext } from './machine'; | ||
|
||
export function saveFile(storyName: string, current: RunContext) { | ||
const anchor = document.getElementById(hiddenFileAnchorId); | ||
|
||
if (anchor) { | ||
anchor.setAttribute( | ||
'href', | ||
'data:text/json,' + encodeURIComponent(JSON.stringify(current, null, 2)), | ||
); | ||
anchor.setAttribute('download', `${storyName}.json`); | ||
anchor.click(); | ||
} | ||
} | ||
|
||
export function readFile( | ||
e: React.FormEvent<HTMLInputElement>, | ||
callback: (context: RunContext, storyFile: string) => void, | ||
) { | ||
const reader = new FileReader(); | ||
const { files } = e.currentTarget; | ||
|
||
if (files && files.length) { | ||
reader.readAsText(files[0]); | ||
reader.onload = ({ target }) => { | ||
if (target) { | ||
const context: RunContext = JSON.parse(target.result as string); | ||
const [storyName] = files[0].name.split('.json'); | ||
callback(context, storyName); | ||
} | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ export type MachineEvents = | |
| { type: 'FINISH'; results: TaskGroupResult[] } | ||
| { type: 'PIN' } | ||
| { type: 'UNPIN' } | ||
| { type: 'SAVE' } | ||
| { type: 'LOAD_FROM_FILE'; storyName: string; pinned: Nullable<RunContext> } | ||
| { type: 'SET_VALUES'; copies: number; samples: number }; | ||
|
||
export type RunContext = { | ||
|
@@ -134,6 +136,38 @@ const machine: MachineType = Machine<MachineContext, MachineSchema, MachineEvent | |
}; | ||
}), | ||
}, | ||
SAVE: { | ||
internal: true, | ||
target: 'idle', | ||
// Only allow saving when there are results | ||
cond: (context): boolean => { | ||
return context.current.results != null; | ||
}, | ||
actions: assign((context) => { | ||
return { | ||
...context, | ||
message: 'Result saved', | ||
}; | ||
}), | ||
}, | ||
LOAD_FROM_FILE: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are effectively re-implementing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open to your thoughts though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may have been an artefact of how I was wrapping the way the state machine worked and so it was seperated. But yeah more or less, that would make sense ya. |
||
internal: true, | ||
target: 'idle', | ||
actions: assign( | ||
(context, event): MachineContext => { | ||
const message: Nullable<string> = event.pinned | ||
? `Loaded pinned result: ${event.storyName}` | ||
: null; | ||
return { | ||
...context, | ||
message, | ||
pinned: event.pinned, | ||
storyName: event.storyName, | ||
current: event.pinned || context.current, | ||
}; | ||
}, | ||
), | ||
}, | ||
UNPIN: { | ||
internal: true, | ||
target: 'idle', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this event to
SAVE_TO_FILE
so that is nicely paired withLOAD_FROM_FILE
? :DThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep