Skip to content

Commit 4694484

Browse files
committed
Merge branch 'milestone3m' of https://github.com/solidos/solid-ui into milestone3m
2 parents acd6b3a + e6f496f commit 4694484

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/utils/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ function genUuid () {
120120
* @param {DomElement} table - will have a tr for each thing
121121
* @param {Array<NamedNode>} things - ORDERED array of NamedNode objects
122122
* @param {function({NamedNode})} createNewRow(thing) returns a TR table row for a new thing
123+
* @param {function(DomElement, NamedNode)} updateExistingRow(row, thing) optional hook for refreshing matched rows
123124
*
124125
* Tolerates out of order elements but puts new ones in order.
125126
* Can be used for any element type; does not have to be a table and tr.
126127
*/
127-
function syncTableToArray (table, things, createNewRow) {
128+
function syncTableToArray (table, things, createNewRow, updateExistingRow) {
128129
let foundOne
129130
let row
130131
let i
@@ -141,6 +142,14 @@ function syncTableToArray (table, things, createNewRow) {
141142
for (i = 0; i < table.children.length; i++) {
142143
row = table.children[i]
143144
if (row.subject && row.subject.sameTerm(thing)) {
145+
if (updateExistingRow) {
146+
const replacement = updateExistingRow(row, thing)
147+
if (replacement && replacement !== row) {
148+
row.parentNode.replaceChild(replacement, row)
149+
replacement.subject = thing
150+
row = replacement
151+
}
152+
}
144153
row.trashMe = false
145154
foundOne = true
146155
break

src/widgets/buttons.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ export type attachmentListOptions = {
891891
export function attachmentList (dom: HTMLDocument, subject: NamedNode, div: HTMLElement, options: attachmentListOptions = {}) {
892892
// options = options || {}
893893
const docsWaitingForRowRefresh = new Set<string>()
894+
const hasAsyncEnrichedRowOptions = !!(options.renderSupportingInfo || options.renderNameSuffix)
894895

895896
const deleteAttachment = function (target) {
896897
if (!kb.updater) {
@@ -917,9 +918,11 @@ export function attachmentList (dom: HTMLDocument, subject: NamedNode, div: HTML
917918
opt.renderSupportingInfo = options.renderSupportingInfo
918919
opt.renderNameSuffix = options.renderNameSuffix
919920

920-
if ((options.renderSupportingInfo || options.renderNameSuffix) && target?.uri && kb.fetcher) {
921+
if (hasAsyncEnrichedRowOptions && target?.uri && kb.fetcher) {
921922
const targetDoc = target.doc()
922-
if (targetDoc?.uri && !docsWaitingForRowRefresh.has(targetDoc.uri)) {
923+
const requestState = targetDoc?.uri ? kb.fetcher.requested?.[targetDoc.uri] : undefined
924+
const shouldWaitForFetch = requestState !== 'done' && requestState !== 'failed'
925+
if (targetDoc?.uri && shouldWaitForFetch && !docsWaitingForRowRefresh.has(targetDoc.uri)) {
923926
docsWaitingForRowRefresh.add(targetDoc.uri)
924927
// Root fix: these row options can depend on async profile data, so rerender once fetch completes.
925928
kb.fetcher.nowOrWhenFetched(targetDoc, undefined, () => {
@@ -940,7 +943,18 @@ export function attachmentList (dom: HTMLDocument, subject: NamedNode, div: HTML
940943
const refresh = function () {
941944
const things = kb.each(subject, predicate)
942945
things.sort()
943-
utils.syncTableToArray(attachmentTable, things, createNewRow)
946+
utils.syncTableToArray(
947+
attachmentTable,
948+
things,
949+
createNewRow,
950+
hasAsyncEnrichedRowOptions
951+
? function (row, thing) {
952+
// When row content depends on async profile data, recreate matched rows on refresh.
953+
const replacement = createNewRow(thing)
954+
return replacement
955+
}
956+
: undefined
957+
)
944958
}
945959

946960
function droppedURIHandler (uris) {

0 commit comments

Comments
 (0)