Skip to content
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

Merged
merged 8 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@
"build": "yarn build:clean && yarn typescript:build",
"prepublishOnly": "yarn build"
}
}
}
34 changes: 34 additions & 0 deletions src/panel/file-system.ts
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);
}
};
}
}
34 changes: 34 additions & 0 deletions src/panel/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type MachineEvents =
| { type: 'FINISH'; results: TaskGroupResult[] }
| { type: 'PIN' }
| { type: 'UNPIN' }
| { type: 'SAVE' }
Copy link
Collaborator

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 with LOAD_FROM_FILE ? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep

| { type: 'LOAD_FROM_FILE'; storyName: string; pinned: Nullable<RunContext> }
| { type: 'SET_VALUES'; copies: number; samples: number };

export type RunContext = {
Expand Down Expand Up @@ -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: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are effectively re-implementing the PIN event right? Maybe the PIN event could include a message value so that we could simply reuse the PIN event rather than created another event just so we can have a different message

Copy link
Collaborator

Choose a reason for hiding this comment

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

Open to your thoughts though

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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',
Expand Down
55 changes: 33 additions & 22 deletions src/panel/task-result/parts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export const Section = styled.div`
border-bottom-left-radius: var(--result-border-radius);
border-bottom-right-radius: var(--result-border-radius);
}
` as any;
`;

export const Heading = styled.h4`
font-weight: bold;
` as any;
`;

export const Content = styled.div`` as any;
export const Content = styled.div``;

// @ts-ignore
export const Note = styled.div`
Expand All @@ -32,46 +32,57 @@ export const Note = styled.div`
margin-right: 1ch;
content: 'ℹ️';
}
` as any;
`;
DarkPurple141 marked this conversation as resolved.
Show resolved Hide resolved

export const ResultValue = styled.code`
/* font-family: 'Courier'; */
` as any;
`;

export const ResultScale = styled.code`
/* slightly smaller margin that other elements */
margin-left: var(--halfGrid);
` as any;
`;

export const ValueLozenge = styled.code<{
hasWarningIcon?: boolean;
type: 'positive' | 'negative' | 'warning' | 'info' | 'faint' | 'raw';
width?: 'fill' | 'inherit';
}>`
${({ hasWarningIcon = true }) =>
!hasWarningIcon &&
`&:before {
content: '⚠️';
DarkPurple141 marked this conversation as resolved.
Show resolved Hide resolved
margin-right: 1ch;
}`};
padding: calc(var(--grid) / 2) var(--grid);
border-radius: var(--result-border-radius);
color: ${(props) => props.theme.color.light};
font-weight: bold;
font-size: small;
background-color: ${({ type, theme }) =>
type === 'positive'
? theme.color.positive
: type === 'negative'
? theme.color.negative
: type === 'warning'
? theme.color.warning
: type === 'info'
? theme.color.seafoam
: type === 'faint'
? theme.color.medium
: theme.color.purple};
` as any;
background-color: ${({ type, theme }) => {
switch (type) {
case 'positive':
return theme.color.positive;
case 'negative':
return theme.color.negative;
case 'faint':
return theme.color.medium;
case 'warning':
return theme.color.warning;
case 'info':
return theme.color.seafoam;
default:
return theme.color.purple;
}
}};
`;

export const Table = styled.table`
width: 100%;
` as any;
`;

export const TitleCell = styled.td`` as any;
export const TitleCell = styled.td``;

export const ValueCell = styled.td`
text-align: right;
` as any;
`;
8 changes: 4 additions & 4 deletions src/panel/task-result/timed-result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { ExpandingResult } from './expanding-result';
import * as Parts from './parts';
import getChange from '../../util/get-change';

const warningIcon = <span>⚠️</span>;

function getDiff({ result, pinned }: { result: TimedResult; pinned: Nullable<TimedResult> }) {
if (!pinned) {
return 0;
Expand Down Expand Up @@ -79,8 +77,10 @@ function Variance({ result }: { result: TimedResult }) {
<tr>
<Parts.TitleCell>Standard deviation</Parts.TitleCell>
<Parts.ValueCell>
<Parts.ValueLozenge type={wasStable ? 'positive' : 'negative'}>
{wasStable ? null : warningIcon}
<Parts.ValueLozenge
hasWarningIcon={wasStable}
type={wasStable ? 'positive' : 'negative'}
>
{toFixed(result.variance.standardDeviation)}
</Parts.ValueLozenge>
</Parts.ValueCell>
Expand Down
Loading