Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Align marketplace update card actions https://github.com/siyuan-note/siyuan/issues/20772

Daniel2d5e6b2d0b1b
diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts
index 8f7ee77ae9..4b177fa2b8 100644
--- a/app/src/config/bazaar.ts
+++ b/app/src/config/bazaar.ts
@@ -662,6 +662,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}
</div>
</div>
<div class="b3-card__actions b3-card__actions--right">
+ ${genRatePackageActionHTML(ratingLoaded, bazaar._data.userRatings.get(ratingKey))}
${bazaar._genIncompatibleChipHTML(available, "bazaar", bazaarType)}
${bazaar._genDeprecatedChipHTML(available)}
${bazaar._genFundingHTML(installed.preferredFunding, false)}
@@ -670,7 +671,6 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}
</span>
${bazaar._genOpenStorageHTML(installed, bazaarType)}
${bazaar._genUpdateButtonHTML(available, bazaarType)}
- ${genRatePackageActionHTML(ratingLoaded, bazaar._data.userRatings.get(ratingKey))}
</div>
</div>`;
},
diff --git a/app/tests/settingsBazaar.test.js b/app/tests/settingsBazaar.test.js
index fead30c7cb..d26e629506 100644
--- a/app/tests/settingsBazaar.test.js
+++ b/app/tests/settingsBazaar.test.js
@@ -13,6 +13,34 @@ const compiled = ts.transpileModule(`export const bazaar = {${render.getText(sou
compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021},
}).outputText;
+test("update cards keep rating before funding and updating as the final action", () => {
+ const method = object.properties.find(property => property.name?.getText(source) === "_genUpdateItemHTML");
+ const code = ts.transpileModule(`export const bazaar = {${method.getText(source)}};`, {
+ compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021},
+ }).outputText;
+ for (const type of ["plugins", "themes", "icons", "templates", "widgets"]) {
+ for (const localFileSystem of [false, true]) {
+ const exports = {};
+ runInNewContext(code, {exports, escapeAttr: value => value, escapeHtml: value => value,
+ getRatingKey: () => "package", isBazaarPackageRatingLoaded: () => true,
+ genRatePackageActionHTML: () => '<span data-type="rate-package"></span>',
+ isBrowser: () => !localFileSystem, getHostCapabilities: () => ({localFileSystem}),
+ window: {siyuan: {languages: {showInFolder: "Show in folder"}}},
+ });
+ Object.assign(exports.bazaar, {
+ _data: {downloadedRatingKeys: new Set(), userRatings: new Map()},
+ _genPackageIconHTML: () => "", _genIncompatibleChipHTML: () => "", _genDeprecatedChipHTML: () => "",
+ _genFundingHTML: () => '<span data-type="funding"></span>',
+ _genOpenStorageHTML: () => '<span data-type="open-storage"></span>',
+ _genUpdateButtonHTML: () => '<span data-type="install-t"></span>',
+ });
+ const html = exports.bazaar._genUpdateItemHTML({installed: {name: "package"}, available: {}}, type);
+ assert.deepEqual(Array.from(html.matchAll(/data-type="([^"]+)"/g), match => match[1]),
+ ["rate-package", "funding", "open", "open-storage", "install-t"]);
+ }
+ }
+});
+
test("directory actions delegate to the owner and preserve installed-package and storage eligibility", () => {
const events = ts.createSourceFile("events.ts", readFileSync("src/config/bazaar/events.ts", "utf8"), ts.ScriptTarget.ES2021, true);
const handlers = events.statements.find(statement => ts.isVariableStatement(statement) &&