|
|
@@ -1,89 +1,8 @@
|
|
|
import React, { useEffect } from 'react'
|
|
|
import ShareProjectModal from '../js/features/share-project-modal/components/share-project-modal'
|
|
|
+import { ContextRoot } from '../js/shared/context/root-context'
|
|
|
import useFetchMock from './hooks/use-fetch-mock'
|
|
|
|
|
|
-const contacts = [
|
|
|
- // user with edited name
|
|
|
- {
|
|
|
- type: 'user',
|
|
|
- email: 'test-user@example.com',
|
|
|
- first_name: 'Test',
|
|
|
- last_name: 'User',
|
|
|
- name: 'Test User',
|
|
|
- },
|
|
|
- // user with default name (email prefix)
|
|
|
- {
|
|
|
- type: 'user',
|
|
|
- email: 'test@example.com',
|
|
|
- first_name: 'test',
|
|
|
- },
|
|
|
- // no last name
|
|
|
- {
|
|
|
- type: 'user',
|
|
|
- first_name: 'Eratosthenes',
|
|
|
- email: 'eratosthenes@example.com',
|
|
|
- },
|
|
|
- // more users
|
|
|
- {
|
|
|
- type: 'user',
|
|
|
- first_name: 'Claudius',
|
|
|
- last_name: 'Ptolemy',
|
|
|
- email: 'ptolemy@example.com',
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'user',
|
|
|
- first_name: 'Abd al-Rahman',
|
|
|
- last_name: 'Al-Sufi',
|
|
|
- email: 'al-sufi@example.com',
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'user',
|
|
|
- first_name: 'Nicolaus',
|
|
|
- last_name: 'Copernicus',
|
|
|
- email: 'copernicus@example.com',
|
|
|
- },
|
|
|
-]
|
|
|
-
|
|
|
-const setupFetchMock = fetchMock => {
|
|
|
- const delay = 1000
|
|
|
-
|
|
|
- fetchMock
|
|
|
- // list contacts
|
|
|
- .get('express:/user/contacts', { contacts }, { delay })
|
|
|
- // change privacy setting
|
|
|
- .post('express:/project/:projectId/settings/admin', 200, { delay })
|
|
|
- // update project member (e.g. set privilege level)
|
|
|
- .put('express:/project/:projectId/users/:userId', 200, { delay })
|
|
|
- // remove project member
|
|
|
- .delete('express:/project/:projectId/users/:userId', 200, { delay })
|
|
|
- // transfer ownership
|
|
|
- .post('express:/project/:projectId/transfer-ownership', 200, {
|
|
|
- delay,
|
|
|
- })
|
|
|
- // send invite
|
|
|
- .post('express:/project/:projectId/invite', 200, { delay })
|
|
|
- // delete invite
|
|
|
- .delete('express:/project/:projectId/invite/:inviteId', 204, {
|
|
|
- delay,
|
|
|
- })
|
|
|
- // resend invite
|
|
|
- .post('express:/project/:projectId/invite/:inviteId/resend', 200, {
|
|
|
- delay,
|
|
|
- })
|
|
|
- // send analytics event
|
|
|
- .post('express:/event/:key', 200)
|
|
|
-}
|
|
|
-
|
|
|
-const ideWithProject = project => {
|
|
|
- return {
|
|
|
- $scope: {
|
|
|
- $watch: () => () => {},
|
|
|
- $applyAsync: () => {},
|
|
|
- project,
|
|
|
- },
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
export const LinkSharingOff = args => {
|
|
|
useFetchMock(setupFetchMock)
|
|
|
|
|
|
@@ -92,7 +11,9 @@ export const LinkSharingOff = args => {
|
|
|
publicAccesLevel: 'private',
|
|
|
}
|
|
|
|
|
|
- return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ return renderWithContext(
|
|
|
+ <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
export const LinkSharingOn = args => {
|
|
|
@@ -103,7 +24,9 @@ export const LinkSharingOn = args => {
|
|
|
publicAccesLevel: 'tokenBased',
|
|
|
}
|
|
|
|
|
|
- return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ return renderWithContext(
|
|
|
+ <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
export const LinkSharingLoading = args => {
|
|
|
@@ -115,7 +38,9 @@ export const LinkSharingLoading = args => {
|
|
|
tokens: undefined,
|
|
|
}
|
|
|
|
|
|
- return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ return renderWithContext(
|
|
|
+ <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
export const NonAdminLinkSharingOff = args => {
|
|
|
@@ -124,7 +49,7 @@ export const NonAdminLinkSharingOff = args => {
|
|
|
publicAccesLevel: 'private',
|
|
|
}
|
|
|
|
|
|
- return (
|
|
|
+ return renderWithContext(
|
|
|
<ShareProjectModal
|
|
|
{...args}
|
|
|
isAdmin={false}
|
|
|
@@ -139,7 +64,7 @@ export const NonAdminLinkSharingOn = args => {
|
|
|
publicAccesLevel: 'tokenBased',
|
|
|
}
|
|
|
|
|
|
- return (
|
|
|
+ return renderWithContext(
|
|
|
<ShareProjectModal
|
|
|
{...args}
|
|
|
isAdmin={false}
|
|
|
@@ -149,20 +74,26 @@ export const NonAdminLinkSharingOn = args => {
|
|
|
}
|
|
|
|
|
|
export const RestrictedTokenMember = args => {
|
|
|
+ // Override isRestrictedTokenMember to be true, then revert it back to the
|
|
|
+ // original value on unmount
|
|
|
+ // Currently this is necessary because the context value is set from window,
|
|
|
+ // however in the future we should change this to set via props
|
|
|
+ const originalIsRestrictedTokenMember = window.isRestrictedTokenMember
|
|
|
window.isRestrictedTokenMember = true
|
|
|
-
|
|
|
useEffect(() => {
|
|
|
return () => {
|
|
|
- window.isRestrictedTokenMember = false
|
|
|
+ window.isRestrictedTokenMember = originalIsRestrictedTokenMember
|
|
|
}
|
|
|
- }, [])
|
|
|
+ })
|
|
|
|
|
|
const project = {
|
|
|
...args.project,
|
|
|
publicAccesLevel: 'tokenBased',
|
|
|
}
|
|
|
|
|
|
- return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ return renderWithContext(
|
|
|
+ <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
export const LegacyLinkSharingReadAndWrite = args => {
|
|
|
@@ -173,7 +104,9 @@ export const LegacyLinkSharingReadAndWrite = args => {
|
|
|
publicAccesLevel: 'readAndWrite',
|
|
|
}
|
|
|
|
|
|
- return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ return renderWithContext(
|
|
|
+ <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
export const LegacyLinkSharingReadOnly = args => {
|
|
|
@@ -184,7 +117,9 @@ export const LegacyLinkSharingReadOnly = args => {
|
|
|
publicAccesLevel: 'readOnly',
|
|
|
}
|
|
|
|
|
|
- return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ return renderWithContext(
|
|
|
+ <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
export const LimitedCollaborators = args => {
|
|
|
@@ -198,7 +133,9 @@ export const LimitedCollaborators = args => {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- return <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ return renderWithContext(
|
|
|
+ <ShareProjectModal {...args} ide={ideWithProject(project)} />
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
const project = {
|
|
|
@@ -261,3 +198,97 @@ export default {
|
|
|
handleHide: { action: 'hide' },
|
|
|
},
|
|
|
}
|
|
|
+
|
|
|
+// Unfortunately, we cannot currently use decorators here, since we need to
|
|
|
+// set a value on window, before the contexts are rendered.
|
|
|
+// When using decorators, the contexts are rendered before the story, so we
|
|
|
+// don't have the opportunity to set the window value first.
|
|
|
+function renderWithContext(Story) {
|
|
|
+ return (
|
|
|
+ <ContextRoot ide={window._ide} settings={{}}>
|
|
|
+ {Story}
|
|
|
+ </ContextRoot>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const contacts = [
|
|
|
+ // user with edited name
|
|
|
+ {
|
|
|
+ type: 'user',
|
|
|
+ email: 'test-user@example.com',
|
|
|
+ first_name: 'Test',
|
|
|
+ last_name: 'User',
|
|
|
+ name: 'Test User',
|
|
|
+ },
|
|
|
+ // user with default name (email prefix)
|
|
|
+ {
|
|
|
+ type: 'user',
|
|
|
+ email: 'test@example.com',
|
|
|
+ first_name: 'test',
|
|
|
+ },
|
|
|
+ // no last name
|
|
|
+ {
|
|
|
+ type: 'user',
|
|
|
+ first_name: 'Eratosthenes',
|
|
|
+ email: 'eratosthenes@example.com',
|
|
|
+ },
|
|
|
+ // more users
|
|
|
+ {
|
|
|
+ type: 'user',
|
|
|
+ first_name: 'Claudius',
|
|
|
+ last_name: 'Ptolemy',
|
|
|
+ email: 'ptolemy@example.com',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'user',
|
|
|
+ first_name: 'Abd al-Rahman',
|
|
|
+ last_name: 'Al-Sufi',
|
|
|
+ email: 'al-sufi@example.com',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'user',
|
|
|
+ first_name: 'Nicolaus',
|
|
|
+ last_name: 'Copernicus',
|
|
|
+ email: 'copernicus@example.com',
|
|
|
+ },
|
|
|
+]
|
|
|
+
|
|
|
+function setupFetchMock(fetchMock) {
|
|
|
+ const delay = 1000
|
|
|
+
|
|
|
+ fetchMock
|
|
|
+ // list contacts
|
|
|
+ .get('express:/user/contacts', { contacts }, { delay })
|
|
|
+ // change privacy setting
|
|
|
+ .post('express:/project/:projectId/settings/admin', 200, { delay })
|
|
|
+ // update project member (e.g. set privilege level)
|
|
|
+ .put('express:/project/:projectId/users/:userId', 200, { delay })
|
|
|
+ // remove project member
|
|
|
+ .delete('express:/project/:projectId/users/:userId', 200, { delay })
|
|
|
+ // transfer ownership
|
|
|
+ .post('express:/project/:projectId/transfer-ownership', 200, {
|
|
|
+ delay,
|
|
|
+ })
|
|
|
+ // send invite
|
|
|
+ .post('express:/project/:projectId/invite', 200, { delay })
|
|
|
+ // delete invite
|
|
|
+ .delete('express:/project/:projectId/invite/:inviteId', 204, {
|
|
|
+ delay,
|
|
|
+ })
|
|
|
+ // resend invite
|
|
|
+ .post('express:/project/:projectId/invite/:inviteId/resend', 200, {
|
|
|
+ delay,
|
|
|
+ })
|
|
|
+ // send analytics event
|
|
|
+ .post('express:/event/:key', 200)
|
|
|
+}
|
|
|
+
|
|
|
+function ideWithProject(project) {
|
|
|
+ return {
|
|
|
+ $scope: {
|
|
|
+ $watch: () => () => {},
|
|
|
+ $applyAsync: () => {},
|
|
|
+ project,
|
|
|
+ },
|
|
|
+ }
|
|
|
+}
|