bitflicker64 commented on code in PR #505:
URL: https://github.com/apache/hugegraph-doc/pull/505#discussion_r4156709332
##########
layouts/_partials/hooks/body-end.html:
##########
@@ -25,31 +25,38 @@
"description" (T "ui_ask_ai_description")
"latest" (T "ui_ask_ai_latest")
"error" (T "ui_ai_error")
+ "community" (T "ui_ai_community")
-}}
+ {{- $questions := slice -}}
+ {{- range hugo.Data.ai.questions -}}
+ {{- $questions = $questions | append (index . $lang) -}}
+ {{- end -}}
{{- $clientConfig := dict
"websiteId" $ai.websiteID
"sourceGroupId" $sourceGroup
"locale" (cond (eq $lang "cn") "zh" "en")
"themeColor" $themeColor
"historical" $historical
"labels" $labels
+ "exampleQuestions" $questions
+ "communityURL" "https://github.com/apache/hugegraph/discussions"
-}}
<script type="application/json" id="hg-ai-config">{{ $clientConfig | jsonify |
safeJS }}</script>
<button type="button" class="hg-ask-ai-launcher d-print-none" data-hg-ask-ai
- data-hg-ai-submit="false" aria-haspopup="dialog"{{ if $historical }}
aria-label="{{ index $labels "ask" }} — {{ index $labels "latest" }}"{{ end }}>
+ data-hg-ai-submit="false" hidden aria-haspopup="dialog"{{ if $historical }}
aria-label="{{ index $labels "ask" }} — {{ index $labels "latest" }}"{{ end }}>
<i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i>
<span>{{ index $labels "ask" }}</span>
</button>
-<dialog class="hg-ai-consent" data-hg-ai-consent
aria-labelledby="hg-ai-consent-title" aria-describedby="hg-ai-disclosure">
- <h2 id="hg-ai-consent-title">{{ index $labels "ask" }}</h2>
+<section class="hg-ai-consent d-print-none" data-hg-ai-consent
aria-labelledby="hg-ai-consent-title" aria-describedby="hg-ai-disclosure">
Review Comment:
Minor: The notice is visible in the HTML, and the launcher is rendered
`hidden`. The adapter fixes both only after `DOMContentLoaded`.
The adapter is a separate external script at the end of the body, and
`init()` waits for `DOMContentLoaded`. A browser can paint the parsed page
before that, so readers who already agreed can see the notice flash on each
navigation. If the adapter does not run (an extension blocking it, an SRI
mismatch, or a script error), the notice stays on screen with buttons that do
nothing and the launcher never appears.
Requested change: render the section with `hidden` and let
`createController()` unhide it when no grant is stored. Keeping the launcher
hidden by default is fine once the notice is also hidden by default.
##########
assets/js/kapa-adapter.js:
##########
@@ -104,14 +116,46 @@
'data-exit-feedback-enabled': 'false',
'data-user-satisfaction-feedback-enabled': 'false',
'data-bot-protection-mechanism': 'hcaptcha',
+ 'data-example-questions': (config.exampleQuestions || []).join(','),
+ 'data-example-questions-col-span': '12',
+ 'data-answer-cta-button-enabled': 'true',
+ 'data-answer-cta-button-text': config.labels.community,
+ 'data-answer-cta-button-link': config.communityURL,
+ 'data-answer-cta-button-background-color': 'transparent',
+ 'data-answer-cta-button-border': 'none',
+ 'data-answer-cta-button-font-weight': '400',
+ 'data-answer-cta-button-font-size': '.8rem',
};
}
function createController(windowObject, documentObject, config) {
var state = 'idle';
+ var widgetConfig = Object.assign({}, config, {
+ exampleQuestions: pickExampleQuestions(config.exampleQuestions),
+ });
+ var consentKey = 'hg-ai-consent:v2:' + config.websiteId;
var consented = false;
+ try {
+ consented = windowObject.localStorage.getItem(consentKey) === 'granted';
+ } catch (_) {
+ // Storage may be disabled; consent still works for this page only.
+ }
var pending = null;
var consent = documentObject.querySelector('[data-hg-ai-consent]');
+ var launcher = documentObject.querySelector('.hg-ask-ai-launcher');
+ if (consent) consent.hidden = consented;
Review Comment:
Important: A visitor who clicks "Not now" sees the notice again on the next
page and on every page after that.
This line shows the notice whenever no grant is stored. `cancelConsent()`
(line 306) only hides it for the current document and writes nothing to
`localStorage`, so the decline is lost on navigation. Before this PR nothing
appeared until the reader clicked the launcher. Now every reader who has not
agreed gets a fixed panel in the bottom corner of every docs page (`max-width:
22rem`, and `100% - 2rem` wide on phones), and declining does not make it go
away. The test "initial inline dismissal saves no permission" asserts
`storage.size === 0` after cancel, so this is the coded behaviour. It conflicts
with the PR description, which calls this a first-use notice and says the old
flow interrupted users.
Requested change: remember the dismissal, for example by storing `dismissed`
under a separate key and starting with the notice hidden and the launcher
visible when it is set. Clicking the launcher or the search row would still
show the notice, so consent stays explicit. Please add a browser test that
clicks "Not now", navigates, and expects the notice hidden and the launcher
visible with no Kapa request.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]