2021-01-06 10:38:25 +00:00
|
|
|
import React from 'react'
|
2021-03-05 13:00:21 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2021-01-06 10:38:25 +00:00
|
|
|
|
2021-03-05 13:00:21 +00:00
|
|
|
import WordCountModal from '../js/features/word-count-modal/components/word-count-modal'
|
2021-05-11 14:25:22 +00:00
|
|
|
import useFetchMock from './hooks/use-fetch-mock'
|
2021-01-06 10:38:25 +00:00
|
|
|
|
2021-03-05 13:00:21 +00:00
|
|
|
export const Interactive = ({
|
|
|
|
mockResponse = 200,
|
|
|
|
mockResponseDelay = 500,
|
|
|
|
...args
|
|
|
|
}) => {
|
2021-05-11 14:25:22 +00:00
|
|
|
useFetchMock(fetchMock => {
|
|
|
|
fetchMock.get(
|
|
|
|
'express:/project/:projectId/wordcount',
|
|
|
|
() => {
|
|
|
|
switch (mockResponse) {
|
|
|
|
case 400:
|
|
|
|
return { status: 400, body: 'The project id is not valid' }
|
2021-01-06 10:38:25 +00:00
|
|
|
|
2021-05-11 14:25:22 +00:00
|
|
|
case 200:
|
|
|
|
return {
|
|
|
|
texcount: {
|
|
|
|
headers: 4,
|
|
|
|
mathDisplay: 40,
|
|
|
|
mathInline: 400,
|
|
|
|
textWords: 4000,
|
|
|
|
},
|
|
|
|
}
|
2021-01-06 10:38:25 +00:00
|
|
|
|
2021-05-11 14:25:22 +00:00
|
|
|
default:
|
|
|
|
return mockResponse
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ delay: mockResponseDelay }
|
|
|
|
)
|
|
|
|
})
|
2021-01-06 10:38:25 +00:00
|
|
|
|
2021-03-05 13:00:21 +00:00
|
|
|
return <WordCountModal {...args} />
|
2021-01-06 10:38:25 +00:00
|
|
|
}
|
2021-03-05 13:00:21 +00:00
|
|
|
Interactive.propTypes = {
|
|
|
|
mockResponse: PropTypes.number,
|
2021-04-27 07:52:58 +00:00
|
|
|
mockResponseDelay: PropTypes.number,
|
2021-01-06 10:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2021-03-25 10:11:45 +00:00
|
|
|
title: 'Modals / Word Count',
|
2021-03-05 13:00:21 +00:00
|
|
|
component: WordCountModal,
|
|
|
|
args: {
|
|
|
|
clsiServerId: 'server-id',
|
|
|
|
projectId: 'project-id',
|
2021-04-27 07:52:58 +00:00
|
|
|
show: true,
|
2021-03-05 13:00:21 +00:00
|
|
|
},
|
2021-01-06 10:38:25 +00:00
|
|
|
argTypes: {
|
2021-03-05 13:00:21 +00:00
|
|
|
handleHide: { action: 'handleHide' },
|
|
|
|
mockResponse: {
|
|
|
|
name: 'Mock Response Status',
|
|
|
|
type: { name: 'number', required: false },
|
|
|
|
description: 'The status code that should be returned by the mock server',
|
|
|
|
defaultValue: 200,
|
|
|
|
control: {
|
|
|
|
type: 'radio',
|
2021-04-27 07:52:58 +00:00
|
|
|
options: [200, 500, 400],
|
|
|
|
},
|
2021-03-05 13:00:21 +00:00
|
|
|
},
|
|
|
|
mockResponseDelay: {
|
|
|
|
name: 'Mock Response Delay',
|
|
|
|
type: { name: 'number', required: false },
|
|
|
|
description: 'The delay before returning a response from the mock server',
|
|
|
|
defaultValue: 500,
|
|
|
|
control: {
|
|
|
|
type: 'range',
|
|
|
|
min: 0,
|
|
|
|
max: 2500,
|
2021-04-27 07:52:58 +00:00
|
|
|
step: 250,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-01-06 10:38:25 +00:00
|
|
|
}
|