2020-11-26 09:22:30 -05:00
|
|
|
import { rootFolderBase } from './fixtures/file-tree-base'
|
|
|
|
import { rootFolderLimit } from './fixtures/file-tree-limit'
|
|
|
|
import FileTreeRoot from '../js/features/file-tree/components/file-tree-root'
|
|
|
|
import FileTreeError from '../js/features/file-tree/components/file-tree-error'
|
2021-05-11 10:25:22 -04:00
|
|
|
import useFetchMock from './hooks/use-fetch-mock'
|
2022-05-16 05:38:20 -04:00
|
|
|
import { ScopeDecorator } from './decorators/scope'
|
|
|
|
import { useScope } from './hooks/use-scope'
|
2024-05-08 11:04:20 -04:00
|
|
|
import { useIdeContext } from '@/shared/context/ide-context'
|
2024-10-10 03:26:18 -04:00
|
|
|
import { bsVersionDecorator } from '../../.storybook/utils/with-bootstrap-switcher'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
const MOCK_DELAY = 2000
|
|
|
|
|
2022-01-10 10:46:46 -05:00
|
|
|
const DEFAULT_PROJECT = {
|
|
|
|
_id: '123abc',
|
|
|
|
name: 'Some Project',
|
|
|
|
rootDocId: '5e74f1a7ce17ae0041dfd056',
|
|
|
|
rootFolder: rootFolderBase,
|
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2024-05-08 11:04:20 -04:00
|
|
|
function defaultSetupMocks(fetchMock, socket) {
|
2020-11-26 09:22:30 -05:00
|
|
|
fetchMock
|
|
|
|
.post(
|
|
|
|
/\/project\/\w+\/(file|doc|folder)\/\w+\/rename/,
|
|
|
|
(path, req) => {
|
|
|
|
const body = JSON.parse(req.body)
|
|
|
|
const entityId = path.match(/([^/]+)\/rename$/)[1]
|
2024-05-08 11:04:20 -04:00
|
|
|
socket.emitToClient('reciveEntityRename', entityId, body.name)
|
2020-11-26 09:22:30 -05:00
|
|
|
return 204
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
delay: MOCK_DELAY,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
.post(
|
|
|
|
/\/project\/\w+\/folder/,
|
|
|
|
(_path, req) => {
|
|
|
|
const body = JSON.parse(req.body)
|
|
|
|
const newFolder = {
|
|
|
|
folders: [],
|
|
|
|
fileRefs: [],
|
|
|
|
docs: [],
|
2021-04-14 09:17:21 -04:00
|
|
|
_id: Math.random().toString(16).replace(/0\./, 'random-test-id-'),
|
2021-04-27 03:52:58 -04:00
|
|
|
name: body.name,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
2024-05-08 11:04:20 -04:00
|
|
|
socket.emitToClient('reciveNewFolder', body.parent_folder_id, newFolder)
|
2020-11-26 09:22:30 -05:00
|
|
|
return newFolder
|
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
delay: MOCK_DELAY,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
.delete(
|
|
|
|
/\/project\/\w+\/(file|doc|folder)\/\w+/,
|
|
|
|
path => {
|
|
|
|
const entityId = path.match(/[^/]+$/)[0]
|
2024-05-08 11:04:20 -04:00
|
|
|
socket.emitToClient('removeEntity', entityId)
|
2020-11-26 09:22:30 -05:00
|
|
|
return 204
|
|
|
|
},
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
delay: MOCK_DELAY,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
.post(/\/project\/\w+\/(file|doc|folder)\/\w+\/move/, (path, req) => {
|
|
|
|
const body = JSON.parse(req.body)
|
|
|
|
const entityId = path.match(/([^/]+)\/move/)[1]
|
2024-05-08 11:04:20 -04:00
|
|
|
socket.emitToClient('reciveEntityMove', entityId, body.folder_id)
|
2020-11-26 09:22:30 -05:00
|
|
|
return 204
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-11 10:25:22 -04:00
|
|
|
export const FullTree = args => {
|
2024-05-08 11:04:20 -04:00
|
|
|
const { socket } = useIdeContext()
|
|
|
|
useFetchMock(fetchMock => defaultSetupMocks(fetchMock, socket))
|
2021-05-11 10:25:22 -04:00
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
useScope({
|
2022-01-10 10:46:46 -05:00
|
|
|
project: DEFAULT_PROJECT,
|
|
|
|
permissionsLevel: 'owner',
|
|
|
|
})
|
2022-05-16 05:38:20 -04:00
|
|
|
|
|
|
|
return <FileTreeRoot {...args} />
|
2021-05-11 10:25:22 -04:00
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2022-01-10 10:46:46 -05:00
|
|
|
export const ReadOnly = args => {
|
2022-05-16 05:38:20 -04:00
|
|
|
useScope({
|
2022-01-10 10:46:46 -05:00
|
|
|
project: DEFAULT_PROJECT,
|
|
|
|
permissionsLevel: 'readOnly',
|
|
|
|
})
|
2022-05-16 05:38:20 -04:00
|
|
|
|
|
|
|
return <FileTreeRoot {...args} />
|
2022-01-10 10:46:46 -05:00
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2022-01-10 10:46:46 -05:00
|
|
|
export const Disconnected = args => {
|
2022-05-16 05:38:20 -04:00
|
|
|
useScope({
|
2022-01-10 10:46:46 -05:00
|
|
|
project: DEFAULT_PROJECT,
|
|
|
|
permissionsLevel: 'owner',
|
|
|
|
})
|
2022-05-16 05:38:20 -04:00
|
|
|
|
|
|
|
return <FileTreeRoot {...args} />
|
2022-01-10 10:46:46 -05:00
|
|
|
}
|
2021-01-14 08:57:33 -05:00
|
|
|
Disconnected.args = { isConnected: false }
|
|
|
|
|
2021-05-11 10:25:22 -04:00
|
|
|
export const NetworkErrors = args => {
|
|
|
|
useFetchMock(fetchMock => {
|
2020-11-26 09:22:30 -05:00
|
|
|
fetchMock
|
|
|
|
.post(/\/project\/\w+\/folder/, 500, {
|
2021-04-27 03:52:58 -04:00
|
|
|
delay: MOCK_DELAY,
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|
|
|
|
.post(/\/project\/\w+\/(file|doc|folder)\/\w+\/rename/, 500, {
|
2021-04-27 03:52:58 -04:00
|
|
|
delay: MOCK_DELAY,
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|
2021-05-11 10:25:22 -04:00
|
|
|
.post(/\/project\/\w+\/(file|doc|folder)\/\w+\/move/, 500, {
|
|
|
|
delay: MOCK_DELAY,
|
|
|
|
})
|
2020-11-26 09:22:30 -05:00
|
|
|
.delete(/\/project\/\w+\/(file|doc|folder)\/\w+/, 500, {
|
2021-04-27 03:52:58 -04:00
|
|
|
delay: MOCK_DELAY,
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|
2021-05-11 10:25:22 -04:00
|
|
|
})
|
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
useScope({
|
2022-01-10 10:46:46 -05:00
|
|
|
project: DEFAULT_PROJECT,
|
|
|
|
permissionsLevel: 'owner',
|
|
|
|
})
|
2022-05-16 05:38:20 -04:00
|
|
|
|
|
|
|
return <FileTreeRoot {...args} />
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
|
2022-01-10 10:46:46 -05:00
|
|
|
export const FallbackError = args => {
|
2022-05-16 05:38:20 -04:00
|
|
|
useScope({
|
2022-01-10 10:46:46 -05:00
|
|
|
project: DEFAULT_PROJECT,
|
|
|
|
})
|
2022-05-16 05:38:20 -04:00
|
|
|
|
|
|
|
return <FileTreeError {...args} />
|
2022-01-10 10:46:46 -05:00
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-05-11 10:25:22 -04:00
|
|
|
export const FilesLimit = args => {
|
2024-05-08 11:04:20 -04:00
|
|
|
const { socket } = useIdeContext()
|
|
|
|
useFetchMock(fetchMock => defaultSetupMocks(fetchMock, socket))
|
2021-05-11 10:25:22 -04:00
|
|
|
|
2022-05-16 05:38:20 -04:00
|
|
|
useScope({
|
|
|
|
project: {
|
|
|
|
...DEFAULT_PROJECT,
|
|
|
|
rootFolder: rootFolderLimit,
|
|
|
|
},
|
2022-01-10 10:46:46 -05:00
|
|
|
permissionsLevel: 'owner',
|
|
|
|
})
|
2022-05-16 05:38:20 -04:00
|
|
|
|
|
|
|
return <FileTreeRoot {...args} />
|
2021-05-11 10:25:22 -04:00
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
export default {
|
2022-03-28 06:23:21 -04:00
|
|
|
title: 'Editor / File Tree',
|
2020-11-26 09:22:30 -05:00
|
|
|
component: FileTreeRoot,
|
|
|
|
args: {
|
2021-03-25 06:12:13 -04:00
|
|
|
setStartedFreeTrial: () => {
|
|
|
|
console.log('started free trial')
|
|
|
|
},
|
|
|
|
refProviders: {},
|
|
|
|
setRefProviderEnabled: provider => {
|
|
|
|
console.log(`ref provider ${provider} enabled`)
|
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
isConnected: true,
|
2020-11-26 09:22:30 -05:00
|
|
|
},
|
|
|
|
argTypes: {
|
2020-12-09 06:56:02 -05:00
|
|
|
onInit: { action: 'onInit' },
|
2021-04-27 03:52:58 -04:00
|
|
|
onSelect: { action: 'onSelect' },
|
2024-10-10 03:26:18 -04:00
|
|
|
...bsVersionDecorator.argTypes,
|
2020-11-26 09:22:30 -05:00
|
|
|
},
|
|
|
|
decorators: [
|
2022-05-16 05:38:20 -04:00
|
|
|
ScopeDecorator,
|
2020-11-26 09:22:30 -05:00
|
|
|
Story => (
|
|
|
|
<>
|
|
|
|
<style>{'html, body, .file-tree { height: 100%; width: 100%; }'}</style>
|
|
|
|
<div className="editor-sidebar full-size">
|
|
|
|
<div className="file-tree">
|
2022-01-10 10:46:46 -05:00
|
|
|
<Story />
|
2020-11-26 09:22:30 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
2021-04-27 03:52:58 -04:00
|
|
|
),
|
|
|
|
],
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|