Skip to content

Commit

Permalink
feat(corel): update releases detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin authored and juice49 committed Oct 15, 2024
1 parent e10f67b commit 1ae631d
Show file tree
Hide file tree
Showing 18 changed files with 604 additions and 379 deletions.
25 changes: 25 additions & 0 deletions packages/sanity/src/core/releases/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ const releasesLocaleStrings = {
/** Text for when a release / document was created */
'created': 'Created <RelativeTime/>',

/** Text for the releases detail screen when a release was published */
'dashboard.details.published-on': 'Published on {{date}}',

/** Text for the releases detail screen in the pin release button. */
'dashboard.details.pin-release': 'Pin release',

/** Activity inspector button text */
'dashboard.details.activity': 'Activity',
/** Warning for deleting a release that it will delete one document version */
'delete.warning_one': 'This will also delete one document version.',
/** Warning for deleting a release that it will delete multiple document version */
Expand All @@ -60,6 +68,14 @@ const releasesLocaleStrings = {

/** Title text when error during release update */
'failed-edit-title': 'Failed to save changes',
/**The text that will be shown in the footer to indicate the time the release was archived */
'footer.status.archived': 'Archived',
/**The text that will be shown in the footer to indicate the time the release was created */
'footer.status.created': 'Created',
/**The text that will be shown in the footer to indicate the time the release was created */
'footer.status.edited': 'Edited',
/**The text that will be shown in the footer to indicate the time the release was published */
'footer.status.published': 'Published',

/** Label text for the loading state whilst release is being loaded */
'loading-release': 'Loading release',
Expand Down Expand Up @@ -118,10 +134,19 @@ const releasesLocaleStrings = {
/** Text for when the release is composed of multiple documents */
'summary.document-count_other': '{{count}} documents',

/** add action type that will be shown in the table*/
'table-body.action.add': 'Add',
/** Change action type that will be shown in the table*/
'table-body.action.change': 'Change',

/** Header for the document table in the release tool - contributors */
'table-header.contributors': 'Contributors',
/** Header for the document table in the release tool - created */
'table-header.created': 'Created',
/** Header for the document table in the release tool - type */
'table-header.type': 'Type',
/** Header for the document table in the release tool - action */
'table-header.action': 'Action',
/** Header for the document table in the release tool - title */
'table-header.documents': 'Documents',
/** Header for the document table in the release tool - edited */
Expand Down
13 changes: 13 additions & 0 deletions packages/sanity/src/core/releases/tool/components/BadgeIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {type IconComponent} from '@sanity/icons'
import {type BadgeTone} from '@sanity/ui'
import {createElement, type CSSProperties} from 'react'

export function BadgeIcon(props: {icon: IconComponent; tone: BadgeTone}) {
const {icon, tone} = props

return createElement(icon, {
style: {
'--card-icon-color': `var(--card-badge-${tone}-icon-color)`,
} as CSSProperties,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {DotIcon} from '@sanity/icons'
import {type BundleDocument} from 'sanity'

import {getReleaseTone} from '../../util/getReleaseTone'
import {VersionAvatar} from './VersionAvatar'

export function ReleaseAvatar({
fontSize,
padding,
release,
}: {
fontSize?: number
padding?: number
release: BundleDocument
}) {
return (
<VersionAvatar
fontSize={fontSize}
padding={padding}
icon={DotIcon}
tone={getReleaseTone(release)}
/>
)
}
23 changes: 23 additions & 0 deletions packages/sanity/src/core/releases/tool/components/StatusItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Box, Card, Flex, Text} from '@sanity/ui'
import {type ReactNode} from 'react'

export function StatusItem(props: {avatar?: ReactNode; text: ReactNode}) {
const {avatar, text} = props

return (
<Card>
<Flex>
{avatar && (
<Box padding={1}>
<div style={{margin: -1}}>{avatar}</div>
</Box>
)}
<Box padding={2} paddingLeft={avatar ? 1 : undefined}>
<Text muted size={1}>
{text}
</Text>
</Box>
</Flex>
</Card>
)
}
69 changes: 33 additions & 36 deletions packages/sanity/src/core/releases/tool/components/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Box, Card, type CardProps, Flex, Stack, Text} from '@sanity/ui'
import {Box, Card, type CardProps, Container, Flex, Stack, Text} from '@sanity/ui'
import {
defaultRangeExtractor,
type Range,
Expand Down Expand Up @@ -52,19 +52,17 @@ export interface TableProps<TableData, AdditionalRowTableData> {
scrollContainerRef: MutableRefObject<HTMLDivElement | null>
}

const RowStack = styled(Stack)({
'& > *:not([first-child])': {
borderTopLeftRadius: 0,
borderTopRightRadius: 0,
marginTop: -1,
},

'& > *:not([last-child])': {
borderBottomLeftRadius: 0,
borderBottomRightRadius: 0,
},
})

const CustomCard = styled(Card)`
display: flex;
max-width: 1200px;
margin: 0 auto;
::before {
content: '';
display: block;
border: 1px solid red;
position: absolute;
}
`
const ITEM_HEIGHT = 59

/**
Expand Down Expand Up @@ -112,6 +110,7 @@ const TableInner = <TableData, AdditionalRowTableData>({
if (!sort) return filteredResult

return [...filteredResult].sort((a, b) => {
// TODO: Update this tos support sorting not only by date but also by string
const parseDate = (dateString: unknown) =>
typeof dateString === 'string' ? Date.parse(dateString) : 0

Expand Down Expand Up @@ -178,12 +177,8 @@ const TableInner = <TableData, AdditionalRowTableData>({
key={String(get(datum, rowId))}
data-testid="table-row"
as="tr"
border
radius={3}
borderBottom
display="flex"
first-child={datum.isFirst ? '' : undefined}
last-child={datum.isLast ? '' : undefined}
margin={-1}
style={{
height: `${datum.virtualRow.size}px`,
transform: `translateY(${datum.virtualRow.start - datum.index * datum.virtualRow.size}px)`,
Expand Down Expand Up @@ -251,23 +246,25 @@ const TableInner = <TableData, AdditionalRowTableData>({
position: 'relative',
}}
>
<Stack as="table" space={1}>
<TableHeader headers={headers} searchDisabled={!searchTerm && !data.length} />
<RowStack as="tbody">
{filteredData.length === 0
? emptyContent
: rowVirtualizer.getVirtualItems().map((virtualRow, index) => {
const datum = filteredData[virtualRow.index]
return renderRow({
...datum,
virtualRow,
index,
isFirst: virtualRow.index === 0,
isLast: virtualRow.index === filteredData.length - 1,
})
})}
</RowStack>
</Stack>
<Container width={3} paddingX={3}>
<Stack as="table">
<TableHeader headers={headers} searchDisabled={!searchTerm && !data.length} />
<Stack as="tbody">
{filteredData.length === 0
? emptyContent
: rowVirtualizer.getVirtualItems().map((virtualRow, index) => {
const datum = filteredData[virtualRow.index]
return renderRow({
...datum,
virtualRow,
index,
isFirst: virtualRow.index === 0,
isLast: virtualRow.index === filteredData.length - 1,
})
})}
</Stack>
</Stack>
</Container>
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const TableHeaderSearch = ({
*/
export const TableHeader = ({headers, searchDisabled}: TableHeaderProps) => {
return (
<Card as="thead" radius={3}>
<Card as="thead" borderTop borderBottom>
<Flex as="tr">
{headers.map(({header: Header, width, id, sorting}) => (
<Header
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {type IconComponent} from '@sanity/icons'
import {type BadgeTone, Box, Text} from '@sanity/ui'

import {BadgeIcon} from './BadgeIcon'

export function VersionAvatar({
fontSize = 1,
icon,
padding = 3,
tone = 'default',
}: {
fontSize?: number
padding?: number
icon: IconComponent
tone?: BadgeTone
}) {
return (
<Box flex="none" padding={padding} style={{borderRadius: 3}}>
<Text size={fontSize}>
<BadgeIcon icon={icon} tone={tone} />
</Text>
</Box>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Stack, Text} from '@sanity/ui'

export function ReleaseDashboardActivityPanel() {
return (
<Stack space={3} padding={3}>
<Text size={1} weight="semibold">
{'Activity'}
</Text>
<Text muted size={0}>
{'🚧 Under construction 🚧'}
</Text>
</Stack>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {PinFilledIcon, PinIcon} from '@sanity/icons'
import {
Box,
// Custom button with full radius used here
// eslint-disable-next-line no-restricted-imports
Button,
Card,
Container,
Flex,
Stack,
Text,
} from '@sanity/ui'
import {format} from 'date-fns'
import {useCallback} from 'react'
import {type BundleDocument, usePerspective, useTranslation} from 'sanity'

import {releasesLocaleNamespace} from '../../i18n'
import {getReleaseTone} from '../../util/getReleaseTone'
import {ReleaseAvatar} from '../components/ReleaseAvatar'
import {ReleaseDetailsEditor} from './ReleaseDetailsEditor'

export function ReleaseDashboardDetails({release}: {release: BundleDocument}) {
const {archived, _id, publishedAt} = release
const {t} = useTranslation(releasesLocaleNamespace)

const {currentGlobalBundle, setPerspective} = usePerspective()

const handlePinRelease = useCallback(() => {
if (_id === currentGlobalBundle._id) {
setPerspective('drafts')
} else {
setPerspective(_id)
}
}, [_id, currentGlobalBundle._id, setPerspective])

return (
<Container width={3}>
<Stack padding={3} paddingY={[4, 4, 5, 6]} space={[3, 3, 4, 5]}>
<Flex gap={1}>
<Button
disabled={publishedAt !== undefined || archived}
icon={_id === currentGlobalBundle._id ? PinFilledIcon : PinIcon}
mode="bleed"
onClick={handlePinRelease}
padding={2}
radius="full"
selected={_id === currentGlobalBundle._id}
space={2}
text={t('dashboard.details.pin-release')}
tone={getReleaseTone(release)}
/>

{
publishedAt ? (
<Card padding={2} radius={2} tone="positive">
<Flex flex={1} gap={2}>
<ReleaseAvatar padding={0} release={release} />
<Text muted size={1} weight="medium">
{t('dashboard.details.published-on', {
date: format(new Date(publishedAt), `MMM d, yyyy`),
})}
</Text>
</Flex>
</Card>
) : null
// TODO: Add the release time field here
// <ReleaseTimeField onChange={handleTimeChange} release={release} value={timeValue} />
}
</Flex>

<Box padding={2}>
<ReleaseDetailsEditor description={release.description} title={release.title} />
</Box>
</Stack>
</Container>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {Card, Flex} from '@sanity/ui'
import {type BundleDocument} from 'sanity'

import {ReleaseMenuButton} from '../components/ReleaseMenuButton/ReleaseMenuButton'
import {ReleasePublishAllButton} from '../components/ReleasePublishAllButton/ReleasePublishAllButton'
import {ReleaseStatusItems} from './ReleaseStatusItems'
import {type DocumentInBundleResult} from './useBundleDocuments'

export function ReleaseDashboardFooter(props: {
documents: DocumentInBundleResult[]
release: BundleDocument
isBundleDeleted: boolean
}) {
const {documents, release, isBundleDeleted} = props

return (
<Card flex="none">
<Card borderTop marginX={2} style={{opacity: 0.6}} />

<Flex padding={3}>
<Flex flex={1} gap={1}>
<ReleaseStatusItems release={release} />
</Flex>

<Flex flex="none" gap={1}>
{/* TODO: Replace this with the real actions. */}
{!isBundleDeleted && !release.publishedAt && (
<ReleasePublishAllButton
bundle={release}
bundleDocuments={documents}
disabled={!documents.length}
/>
)}
<ReleaseMenuButton disabled={isBundleDeleted} bundle={release} />
</Flex>
</Flex>
</Card>
)
}
Loading

0 comments on commit 1ae631d

Please sign in to comment.