-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from SeedCompany/feature/FE-344-Product_creat…
…e_edit FE #344 Create and Edit Product
- Loading branch information
Showing
30 changed files
with
1,642 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/components/EngagementBreadcrumb/EngagementBreadcrumb.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fragment EngagementBreadcrumb on Engagement { | ||
id | ||
... on LanguageEngagement { | ||
language { | ||
value { | ||
name { | ||
canRead | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/components/EngagementBreadcrumb/EngagementBreadcrumb.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react'; | ||
import { Except } from 'type-fest'; | ||
import { Nullable } from '../../util'; | ||
import { SecuredBreadcrumb, SecuredBreadcrumbProps } from '../Breadcrumb'; | ||
import { EngagementBreadcrumbFragment } from './EngagementBreadcrumb.generated'; | ||
|
||
export interface EngagementBreadcrumbProps | ||
extends Except<Partial<SecuredBreadcrumbProps>, 'data'> { | ||
data?: Nullable<EngagementBreadcrumbFragment>; | ||
projectId?: string; | ||
} | ||
|
||
export const EngagementBreadcrumb = ({ | ||
data, | ||
projectId, | ||
...rest | ||
}: EngagementBreadcrumbProps) => ( | ||
<SecuredBreadcrumb | ||
to={data ? `/projects/${projectId}/engagements/${data.id}` : '..'} // assume subpage until data loads | ||
data={ | ||
data?.__typename === 'LanguageEngagement' | ||
? data.language.value?.name | ||
: undefined | ||
} | ||
redacted="You don't have permission to view this project's name" | ||
loadingWidth={200} | ||
{...rest} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './EngagementBreadcrumb'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
fragment ProductCard on Product { | ||
id | ||
scriptureReferences { | ||
canRead | ||
canEdit | ||
value { | ||
start { | ||
book | ||
chapter | ||
verse | ||
} | ||
end { | ||
book | ||
chapter | ||
verse | ||
} | ||
} | ||
} | ||
mediums { | ||
canRead | ||
canEdit | ||
value | ||
} | ||
methodology { | ||
canRead | ||
canEdit | ||
value | ||
} | ||
... on DerivativeScriptureProduct { | ||
produces { | ||
canRead | ||
canEdit | ||
value { | ||
...Producible | ||
} | ||
} | ||
scriptureReferencesOverride { | ||
canRead | ||
canEdit | ||
value { | ||
start { | ||
book | ||
chapter | ||
verse | ||
} | ||
end { | ||
book | ||
chapter | ||
verse | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { number, object, select, text } from '@storybook/addon-knobs'; | ||
import { DateTime } from 'luxon'; | ||
import * as React from 'react'; | ||
import { | ||
newTestament, | ||
oldTestament, | ||
} from '../../scenes/Products/ProductForm/constants'; | ||
import { ProductCard } from './ProductCard'; | ||
import { ProductCardFragment } from './ProductCard.generated'; | ||
|
||
export default { | ||
title: 'Components', | ||
decorators: [ | ||
(Story: React.FC) => ( | ||
<div style={{ width: 300 }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
}; | ||
|
||
const derivativeScriptureProducts = [ | ||
'DirectScriptureProduct', | ||
'DerivativeScriptureProduct', | ||
'Song', | ||
'Story', | ||
'Film', | ||
'LiteracyMaterial', | ||
] as const; | ||
|
||
const getProduct = () => { | ||
const methodologyValue = select( | ||
'Methodology', | ||
[ | ||
'Paratext', | ||
'OtherWritten', | ||
'Render', | ||
'OtherOralTranslation', | ||
'BibleStories', | ||
'OneStory', | ||
'OtherOralStories', | ||
'Film', | ||
'SignLanguage', | ||
'OtherVisual', | ||
], | ||
'Paratext' | ||
); | ||
|
||
const getScriptureRange = () => { | ||
const books = [...oldTestament, ...newTestament]; | ||
const book = books[Math.floor(Math.random() * books.length)]; | ||
return { | ||
start: { | ||
book, | ||
chapter: Math.ceil(Math.random() * 20), | ||
verse: Math.ceil(Math.random() * 20), | ||
}, | ||
end: { | ||
book, | ||
chapter: Math.ceil(Math.random() * 20), | ||
verse: Math.ceil(Math.random() * 20), | ||
}, | ||
}; | ||
}; | ||
|
||
const getScriptureRangeArray = () => { | ||
const scriptureCount = number('Number of Scripture Ranges', 1, { | ||
range: true, | ||
min: 0, | ||
max: 20, | ||
step: 1, | ||
}); | ||
const scriptureRangeArray = []; | ||
for (const _ of new Array(scriptureCount)) { | ||
scriptureRangeArray.push(getScriptureRange()); | ||
} | ||
return scriptureRangeArray; | ||
}; | ||
|
||
const sharedValues: Pick< | ||
ProductCardFragment, | ||
'id' | 'scriptureReferences' | 'mediums' | 'methodology' | ||
> = { | ||
id: '0958d98477', | ||
scriptureReferences: { | ||
canRead: true, | ||
canEdit: true, | ||
value: getScriptureRangeArray(), | ||
__typename: 'SecuredScriptureRanges', | ||
}, | ||
mediums: { | ||
canRead: true, | ||
canEdit: true, | ||
value: object('Mediums', ['Print']), | ||
__typename: 'SecuredProductMediums', | ||
}, | ||
methodology: { | ||
canRead: true, | ||
canEdit: true, | ||
value: methodologyValue, | ||
__typename: 'SecuredMethodology', | ||
}, | ||
}; | ||
|
||
const directProduct: ProductCardFragment = { | ||
...sharedValues, | ||
__typename: 'DirectScriptureProduct', | ||
}; | ||
|
||
const productType = select( | ||
'Product Type', | ||
derivativeScriptureProducts, | ||
'Story' | ||
); | ||
|
||
const derivativeProduct: ProductCardFragment = { | ||
...sharedValues, | ||
__typename: 'DerivativeScriptureProduct', | ||
produces: { | ||
canRead: true, | ||
canEdit: true, | ||
value: { | ||
__typename: productType, | ||
id: '123', | ||
name: { | ||
canRead: true, | ||
canEdit: true, | ||
value: text('Producible Name', 'My Childhood Story'), | ||
}, | ||
createdAt: DateTime.local(), | ||
scriptureReferences: sharedValues.scriptureReferences, | ||
}, | ||
}, | ||
scriptureReferencesOverride: { | ||
canRead: true, | ||
canEdit: true, | ||
}, | ||
}; | ||
|
||
return derivativeScriptureProducts.includes(productType) | ||
? derivativeProduct | ||
: directProduct; | ||
}; | ||
|
||
export const Product = () => <ProductCard product={getProduct()} />; |
Oops, something went wrong.