sanity-plugin-workflow 1.0.0-beta.8 → 1.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-workflow",
3
- "version": "1.0.0-beta.8",
3
+ "version": "1.0.0-beta.9",
4
4
  "description": "A demonstration of a custom content publishing workflow using Sanity.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -85,8 +85,8 @@
85
85
  "react-dom": "^18.2.0",
86
86
  "react-is": "^18.2.0",
87
87
  "rimraf": "^4.1.2",
88
- "sanity": "^3.3.1",
89
- "semantic-release": "^20.1.0",
88
+ "sanity": "^3.9.1",
89
+ "semantic-release": "^20.1.3",
90
90
  "typescript": "^5.0.0"
91
91
  },
92
92
  "peerDependencies": {
@@ -141,10 +141,8 @@ export function DocumentCard(props: DocumentCardProps) {
141
141
  <Flex align="center" justify="space-between" gap={1}>
142
142
  <Box flex={1}>
143
143
  <Preview
144
- // Like as in desk lists, except it has an intermittent loading state
145
- // layout="default"
146
- // Like in the PTE, with no loading state
147
- layout="block"
144
+ layout="default"
145
+ skipVisibilityCheck
148
146
  value={item}
149
147
  schemaType={schema.get(item._type) as SchemaType}
150
148
  />
@@ -1,6 +1,6 @@
1
- import {Draggable} from '@hello-pangea/dnd'
2
- import {useVirtualizer} from '@tanstack/react-virtual'
3
- import {useMemo, useRef} from 'react'
1
+ import {Draggable, DraggableStyle} from '@hello-pangea/dnd'
2
+ import {useVirtualizer, VirtualItem} from '@tanstack/react-virtual'
3
+ import {CSSProperties, useMemo, useRef} from 'react'
4
4
  import {CurrentUser} from 'sanity'
5
5
  import {UserExtended} from 'sanity-plugin-utils'
6
6
 
@@ -25,6 +25,35 @@ type DocumentListProps = {
25
25
  userRoleCanDrop: boolean
26
26
  }
27
27
 
28
+ function getStyle(
29
+ draggableStyle: DraggableStyle | undefined,
30
+ virtualItem: VirtualItem
31
+ ): CSSProperties {
32
+ // Default transform required by tanstack virtual for positioning
33
+ let transform = `translateY(${virtualItem.start}px)`
34
+
35
+ // If a card is being dragged over, this card needs to move up or down
36
+ if (draggableStyle && draggableStyle.transform) {
37
+ // So get the transform value from beautiful-dnd
38
+ const draggableTransformY = parseInt(
39
+ draggableStyle.transform.split(',')[1].split('px')[0],
40
+ 10
41
+ )
42
+
43
+ // And apply it to the card
44
+ transform = `translateY(${virtualItem.start + draggableTransformY}px)`
45
+ }
46
+
47
+ return {
48
+ position: 'absolute',
49
+ top: 0,
50
+ left: 0,
51
+ width: '100%',
52
+ height: `${virtualItem.size}px`,
53
+ transform,
54
+ }
55
+ }
56
+
28
57
  export default function DocumentList(props: DocumentListProps) {
29
58
  const {
30
59
  data = [],
@@ -48,15 +77,18 @@ export default function DocumentList(props: DocumentListProps) {
48
77
 
49
78
  const parentRef = useRef(null)
50
79
 
51
- const rowVirtualizer = useVirtualizer({
52
- count: data.length,
80
+ const virtualizer = useVirtualizer({
81
+ count: dataFiltered.length,
53
82
  getScrollElement: () => parentRef.current,
54
83
  getItemKey: (index) => dataFiltered[index]?._metadata?.documentId ?? index,
55
- estimateSize: () => 113,
56
- overscan: 10,
84
+ estimateSize: () => 115,
85
+ overscan: 7,
86
+ measureElement: (element) => {
87
+ return element.getBoundingClientRect().height || 115
88
+ },
57
89
  })
58
90
 
59
- if (!data.length) {
91
+ if (!data.length || !dataFiltered.length) {
60
92
  return null
61
93
  }
62
94
 
@@ -66,61 +98,72 @@ export default function DocumentList(props: DocumentListProps) {
66
98
  style={{
67
99
  height: `100%`,
68
100
  overflow: 'auto',
69
- paddingTop: 1,
70
101
  // Smooths scrollbar behaviour
71
102
  overflowAnchor: 'none',
72
103
  scrollBehavior: 'auto',
104
+ paddingTop: 1,
73
105
  }}
74
106
  >
75
- {rowVirtualizer.getVirtualItems().map((virtualItem) => {
76
- const item = dataFiltered[virtualItem.index]
77
-
78
- const {documentId, assignees} = item?._metadata ?? {}
107
+ <div
108
+ style={{
109
+ height: `${virtualizer.getTotalSize()}px`,
110
+ width: '100%',
111
+ position: 'relative',
112
+ }}
113
+ >
114
+ {virtualizer.getVirtualItems().map((virtualItem) => {
115
+ const item = dataFiltered[virtualItem.index]
79
116
 
80
- if (!documentId) {
81
- return null
82
- }
117
+ const {documentId, assignees} = item?._metadata ?? {}
83
118
 
84
- const isInvalid = invalidDocumentIds.includes(documentId)
85
- const meInAssignees = user?.id ? assignees?.includes(user.id) : false
86
- const isDragDisabled =
87
- patchingIds.includes(documentId) ||
88
- !userRoleCanDrop ||
89
- isInvalid ||
90
- !(state.requireAssignment
91
- ? state.requireAssignment && meInAssignees
92
- : true)
119
+ const isInvalid = invalidDocumentIds.includes(documentId)
120
+ const meInAssignees = user?.id ? assignees?.includes(user.id) : false
121
+ const isDragDisabled =
122
+ patchingIds.includes(documentId) ||
123
+ !userRoleCanDrop ||
124
+ isInvalid ||
125
+ !(state.requireAssignment
126
+ ? state.requireAssignment && meInAssignees
127
+ : true)
93
128
 
94
- return (
95
- <Draggable
96
- // The metadata's documentId is always the published one to avoid rerendering
97
- // key={documentId}
98
- key={virtualItem.key}
99
- draggableId={documentId}
100
- index={virtualItem.index}
101
- isDragDisabled={isDragDisabled}
102
- >
103
- {(draggableProvided, draggableSnapshot) => (
104
- <div
105
- ref={draggableProvided.innerRef}
106
- {...draggableProvided.draggableProps}
107
- {...draggableProvided.dragHandleProps}
108
- >
109
- <DocumentCard
110
- userRoleCanDrop={userRoleCanDrop}
111
- isDragDisabled={isDragDisabled}
112
- isPatching={patchingIds.includes(documentId)}
113
- isDragging={draggableSnapshot.isDragging}
114
- item={item}
115
- toggleInvalidDocumentId={toggleInvalidDocumentId}
116
- userList={userList}
117
- states={states}
118
- />
119
- </div>
120
- )}
121
- </Draggable>
122
- )
123
- })}
129
+ return (
130
+ <Draggable
131
+ key={virtualItem.key}
132
+ draggableId={documentId}
133
+ index={virtualItem.index}
134
+ isDragDisabled={isDragDisabled}
135
+ >
136
+ {(draggableProvided, draggableSnapshot) => (
137
+ <div
138
+ ref={draggableProvided.innerRef}
139
+ {...draggableProvided.draggableProps}
140
+ {...draggableProvided.dragHandleProps}
141
+ style={getStyle(
142
+ draggableProvided.draggableProps.style,
143
+ virtualItem
144
+ )}
145
+ >
146
+ <div
147
+ ref={virtualizer.measureElement}
148
+ data-index={virtualItem.index}
149
+ >
150
+ <DocumentCard
151
+ userRoleCanDrop={userRoleCanDrop}
152
+ isDragDisabled={isDragDisabled}
153
+ isPatching={patchingIds.includes(documentId)}
154
+ isDragging={draggableSnapshot.isDragging}
155
+ item={item}
156
+ toggleInvalidDocumentId={toggleInvalidDocumentId}
157
+ userList={userList}
158
+ states={states}
159
+ />
160
+ </div>
161
+ </div>
162
+ )}
163
+ </Draggable>
164
+ )
165
+ })}
166
+ </div>
124
167
  </div>
125
168
  )
126
169
  }
@@ -401,7 +401,6 @@ export default function WorkflowTool(props: WorkflowToolProps) {
401
401
  : defaultCardTone
402
402
  }
403
403
  height="fill"
404
- paddingTop={1}
405
404
  >
406
405
  {loading ? (
407
406
  <Flex padding={5} align="center" justify="center">