Skip to content

Icons, Fonts & Notifications #102

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

Merged
merged 12 commits into from
Feb 2, 2020
Prev Previous commit
Next Next commit
setup test notify
  • Loading branch information
ShMcK committed Feb 2, 2020
commit 8dc00aa2b653c57992cbd2dd0782707754a090e6
7 changes: 7 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ export interface ErrorMessage {
description?: string
}

export interface TestStatus {
type: 'success' | 'warning' | 'error' | 'loading'
title: string
content?: string
}

export interface MachineContext {
env: Environment
error: ErrorMessage | null
tutorial: G.Tutorial | null
position: Position
progress: Progress
processes: ProcessEvent[]
testStatus: TestStatus | null
}

export interface MachineEvent {
Expand Down
10 changes: 9 additions & 1 deletion web-app/src/components/ProcessMessages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as T from 'typings'
import { css, jsx } from '@emotion/core'

interface Props {
testStatus: T.TestStatus | null
processes: T.ProcessEvent[]
}

Expand All @@ -15,7 +16,14 @@ const styles = {
}

// display a list of active processes
const ProcessMessages = ({ processes }: Props) => {
const ProcessMessages = ({ processes, testStatus }: Props) => {
if (testStatus) {
return (
<Message key={testStatus.title} type={testStatus.type} title={testStatus.title} size="medium">
{testStatus.content}
</Message>
)
}
if (!processes.length) {
return null
}
Expand Down
4 changes: 3 additions & 1 deletion web-app/src/containers/LoadingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const LoadingPage = ({ text, context }: Props) => {
if (error) {
return (
<div css={styles.page}>
<Message type="error" title={error.title} description={error.description} />
<Message type="error" title={error.title}>
{error.description}
</Message>
</div>
)
}
Expand Down
5 changes: 3 additions & 2 deletions web-app/src/containers/Tutorial/LevelPage/Level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ const styles = {
interface Props {
level: G.Level & { status: T.ProgressStatus; index: number; steps: Array<G.Step & { status: T.ProgressStatus }> }
processes: T.ProcessEvent[]
testStatus: T.TestStatus | null
onContinue(): void
onLoadSolution(): void
}

const Level = ({ level, onContinue, onLoadSolution, processes }: Props) => {
const Level = ({ level, onContinue, onLoadSolution, processes, testStatus }: Props) => {
if (!level.steps) {
throw new Error('No Stage steps found')
}
Expand Down Expand Up @@ -109,7 +110,7 @@ const Level = ({ level, onContinue, onLoadSolution, processes }: Props) => {

{processes.length > 0 && (
<div css={styles.processes}>
<ProcessMessages processes={processes} />
<ProcessMessages processes={processes} testStatus={testStatus} />
</div>
)}

Expand Down
12 changes: 10 additions & 2 deletions web-app/src/containers/Tutorial/LevelPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface PageProps {
}

const LevelSummaryPageContainer = (props: PageProps) => {
const { position, progress, processes, error } = props.context
const { position, progress, processes, testStatus, error } = props.context

const version = selectors.currentVersion(props.context)
const levelData: G.Level = selectors.currentLevel(props.context)
Expand Down Expand Up @@ -48,7 +48,15 @@ const LevelSummaryPageContainer = (props: PageProps) => {
}),
}

return <Level level={level} onContinue={onContinue} onLoadSolution={onLoadSolution} processes={processes} />
return (
<Level
level={level}
onContinue={onContinue}
onLoadSolution={onLoadSolution}
processes={processes}
testStatus={testStatus}
/>
)
}

export default LevelSummaryPageContainer
26 changes: 0 additions & 26 deletions web-app/src/services/notify/index.tsx

This file was deleted.

39 changes: 22 additions & 17 deletions web-app/src/services/state/actions/test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import * as CR from 'typings'
import { ActionFunctionMap } from 'xstate'
import notify from '../../notify'
import { assign, ActionFunctionMap } from 'xstate'

const testActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
testPass() {
notify({
key: 'test',
// @ts-ignore
testStart: assign({
testStatus: () => ({
type: 'loading',
title: 'Test running...',
}),
}),
// @ts-ignore
testPass: assign({
testStatus: () => ({
type: 'success',
title: 'Success!',
content: '',
duration: 1500,
})
},
testFail(context, event) {
notify({
key: 'test',
title: 'Fail',
content: '',
duration: 3000,
})
},
}),
}),
// @ts-ignore
testFail: assign({
testStatus: () => ({
type: 'warning',
title: 'Fail!',
content: 'Test failed for some reason',
}),
}),
}

export default testActions
1 change: 1 addition & 0 deletions web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const createMachine = (options: any) => {
complete: false,
},
processes: [],
testStatus: null,
},
states: {
Start: {
Expand Down
29 changes: 29 additions & 0 deletions web-app/stories/Commands.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ storiesOf('Components', module)
.addDecorator(SideBarDecorator)
.add('Processes', () => (
<ProcessMessages
testStatus={null}
processes={[
{
title: 'npm install',
Expand All @@ -26,3 +27,31 @@ storiesOf('Components', module)
]}
/>
))
.add('Test Start', () => (
<ProcessMessages
testStatus={{
type: 'loading',
title: 'Test running...',
}}
processes={[]}
/>
))
.add('Test Pass', () => (
<ProcessMessages
testStatus={{
type: 'success',
title: 'Success!',
}}
processes={[]}
/>
))
.add('Test Fail', () => (
<ProcessMessages
testStatus={{
type: 'warning',
title: 'Fail!',
content: 'Test failed for some reason',
}}
processes={[]}
/>
))
22 changes: 0 additions & 22 deletions web-app/stories/TestNotify.stories.tsx

This file was deleted.