diff --git a/.claude/rules/scratch-gui/e2e-test.md b/.claude/rules/scratch-gui/e2e-test.md index 9e43eb2a16..6f1fd1feb7 100644 --- a/.claude/rules/scratch-gui/e2e-test.md +++ b/.claude/rules/scratch-gui/e2e-test.md @@ -85,6 +85,7 @@ expect(await isActiveByTestId(driver, 'ruby-toolbar-mode-furigana')).toBe(true); | `problem-settings-modal-sentences` | div | 選んだパターンでプログラムの先頭に入る文 | | `problem-settings-modal-cancel` | button | キャンセル(何も変えない) | | `problem-settings-modal-ok` | button | 決定(選んだパターンで書く。何も選んでいないときは押せない) | +| `problem-settings-modal-request` | a | ほかの約束を頼む(確かめてから、値を入れたフィードバックのフォームを開く) | ### コンソール拡張機能 (`smalruby-console`) diff --git a/docs/dncl/README.md b/docs/dncl/README.md index d92d379653..165fde7bc3 100644 --- a/docs/dncl/README.md +++ b/docs/dncl/README.md @@ -417,7 +417,7 @@ DNCL モードは特定のブロックに紐づくものではなく、**Ruby - 説明文は手で書いてもよいし、**「問題の約束」のポップアップ**で設定のパターンから選んでもよい(日本語タブのときだけ)。 - エディタの上の緑の帯に、いまの約束を出す: 「日本語(共通テスト用プログラム表記)| 問題の約束: 添字は 0 から 変える」(`ruby-tab-problem-settings`)。冒頭の文がどちらのパターンにもちょうど合わないとき(`//` をコメントにしたときなど)は「そのほか」。帯が狭いときは、言葉の名前のほうを「…」で切って約束を残す。 - - 「変える」(`ruby-tab-problem-settings-change`)でポップアップ(`components/problem-settings-modal/`。自動置換設定と同じ大きさ・作り)を開く。中身は、説明の 2 文、パターンのカード(ラジオ。何が変わるかの小さな例つき)、選んだパターンで**プログラムの先頭に入る文**(`problem-settings-modal-sentences`。何も入らないときは「いまの約束の文は消えます」)、「ほかのコメントはそのまま残ります。」、「キャンセル」「決定」。 + - 「変える」(`ruby-tab-problem-settings-change`)でポップアップ(`components/problem-settings-modal/`。自動置換設定と同じ大きさ・作り)を開く。中身は、説明の 2 文、パターンのカード(ラジオ。何が変わるかの小さな例つき)、選んだパターンで**プログラムの先頭に入る文**(`problem-settings-modal-sentences`。何も入らないときは「いまの約束の文は消えます」)、「ほかのコメントはそのまま残ります。」、「ほかの約束を頼む」のリンク、「キャンセル」「決定」。 - はじめは、いまのパターンのカードが選ばれている。「そのほか」のときはどれも選ばれておらず、選ぶまで「決定」は押せない。 - 背の低い画面(授業の PC の 1300×600・スマホの横向き)では、ポップアップを画面の上に寄せ、中身をスクロールできるようにする(共有のモーダルの外側はスクロールしないので、そのままでは「決定」が画面の外に出る)。 @@ -427,6 +427,7 @@ DNCL モードは特定のブロックに紐づくものではなく、**Ruby | 添字が 1 から始まる問題 | 10 | 1 から | `#` | 書く(`and` / `or` / `not` の 3 文) | `problem-settings-modal-pattern-index-from-one` | 「決定」(`problem-settings-modal-ok`)で、冒頭の設定の文を消してパターンの文を先頭に書き(ほかのコメントは残す)、プログラムを Ruby にしてからその設定で日本語に戻す(`dnclWithSettingsPattern`)。意味は変わらないので、添字は書きかわる(0 からで `A[0]` のプログラムを 1 からにすると `A[1]`)。Ruby にできないプログラムは、冒頭の文だけを書きかえる。1 回の Undo で戻る。「キャンセル」(`problem-settings-modal-cancel`)では何も変えない。 + - 「ほかの約束を頼む」(`problem-settings-modal-request`): 約束は Smalruby がプログラムの読み方を変えるものなので、利用者が自由に足すことはできない。新しい例題でいまのパターンに無い約束が要るときに、開発者に頼むためのリンク。押すと確かめのダイアログ(「スモウルビーの開発者に、問題の約束を足してほしいと頼みます。フィードバックの画面を開きますか?」)を出し、「OK」でフィードバックの画面(「フィードバックを送信」と同じ Google フォーム)を新しいタブで開く。種類は「機能要望」、内容は「日本語モードの問題の約束を足してほしい。/足したい約束の文:」を入れておき、利用者は足したい約束の文だけを書けばよい(値を入れた URL は `src/lib/feedback-form.js` の `feedbackFormUrl`。フォームの質問の id を使う)。 - 自動置換(既定でオン)はコメントの中を変えないので、説明文の `,` は `,` のまま残る(`#` と、設定で `//` をコメントにしたときの `//` の後ろ。`「…」` の中の `#` はコメントにしない)。`,` で書いた文も同じ設定として読む。 - 作品を保存して開き直しても設定は残る: 冒頭の文は Ruby のコメントになり、最初のブロックのコメントとして作品に保存される(`test/unit/lib/dncl/dncl-settings-project.test.js` が、ブロックにして保存し、開き直して日本語に戻すと同じ文と設定になることを確かめる)。 - 添字が 1 から始まる設定のプログラムには、範囲外の添字の警告(`dncl-array-index-hint.js`)を出さない。 diff --git a/packages/scratch-gui/.prettierignore b/packages/scratch-gui/.prettierignore index df1e3e2a40..d754730107 100644 --- a/packages/scratch-gui/.prettierignore +++ b/packages/scratch-gui/.prettierignore @@ -288,6 +288,7 @@ src/lib/* !src/lib/libraries/ # Individual Smalruby files !src/lib/auto-correct.js +!src/lib/feedback-form.js !src/lib/backpack-mesh-v1-migration.js !src/lib/bug-report-api.js !src/lib/koshien-mock-config.js @@ -747,6 +748,7 @@ test/unit/lib/* !test/unit/lib/ruby-to-blocks-converter/** # Individual Smalruby files !test/unit/lib/analytics.test.js +!test/unit/lib/feedback-form.test.js !test/unit/lib/smalruby-console.test.js !test/unit/lib/image-viewer-math.test.js !test/unit/lib/auto-correct.test.js diff --git a/packages/scratch-gui/src/components/problem-settings-modal/problem-settings-modal.css b/packages/scratch-gui/src/components/problem-settings-modal/problem-settings-modal.css index 2cd82d09a9..7de66841d5 100644 --- a/packages/scratch-gui/src/components/problem-settings-modal/problem-settings-modal.css +++ b/packages/scratch-gui/src/components/problem-settings-modal/problem-settings-modal.css @@ -138,3 +138,11 @@ $frame-height: calc($library-header-height + 8px); opacity: 0.5; cursor: default; } + +/* 「ほかの約束を頼む」: a small link, so that it is not taken for one of the patterns. */ +.request-link { + align-self: flex-start; + font-size: 0.8rem; + color: hsla(163, 85%, 28%, 1); /* darker than $ui-green-2, to be read on white */ + text-decoration: underline; +} diff --git a/packages/scratch-gui/src/components/problem-settings-modal/problem-settings-modal.jsx b/packages/scratch-gui/src/components/problem-settings-modal/problem-settings-modal.jsx index a43131f9b6..2d52dcaa3e 100644 --- a/packages/scratch-gui/src/components/problem-settings-modal/problem-settings-modal.jsx +++ b/packages/scratch-gui/src/components/problem-settings-modal/problem-settings-modal.jsx @@ -4,6 +4,7 @@ import React, { useCallback, useState } from 'react'; import { defineMessages, FormattedMessage, injectIntl } from 'react-intl'; import Modal from '../../containers/modal.jsx'; import { dnclSettingsSentences } from '../../lib/dncl/dncl-settings'; +import { FEEDBACK_KIND_REQUEST, feedbackFormUrl } from '../../lib/feedback-form'; import intlShape from '../../lib/intlShape.js'; import Box from '../box/box.jsx'; import styles from './problem-settings-modal.css'; @@ -50,6 +51,23 @@ const messages = defineMessages({ description: 'Note that the other comments of the program are kept', id: 'gui.problemSettingsModal.othersKept', }, + request: { + defaultMessage: 'Ask for another rule', + description: 'Link to ask the developers of Smalruby to add a rule of the problem', + id: 'gui.problemSettingsModal.request', + }, + requestConfirm: { + defaultMessage: + 'This asks the developers of Smalruby to add a rule of the problem. Open the page to send feedback?', + description: 'Confirm dialog before the feedback form opens to ask for a rule of the problem', + id: 'gui.problemSettingsModal.requestConfirm', + }, + requestContent: { + defaultMessage: 'Please add a rule of the problem to the Japanese mode.\nThe sentence of the rule to add:\n', + description: + 'The text filled in the feedback form to ask for a rule of the problem; the user writes the sentence after it', + id: 'gui.problemSettingsModal.requestContent', + }, cancel: { defaultMessage: 'Cancel', description: 'Button to close the popup of the rules of the problem without changing them', @@ -77,6 +95,21 @@ const ProblemSettingsModal = ({ intl, currentPatternId, onDecide, onRequestClose if (choice) onDecide(choice); }, [choice, onDecide]); + // A rule changes how Smalruby reads the program, so the user cannot add one but can ask for one (#2635). + const handleRequest = useCallback( + (event) => { + event.preventDefault(); + // eslint-disable-next-line no-alert + if (!window.confirm(intl.formatMessage(messages.requestConfirm))) return; + const url = feedbackFormUrl({ + kind: FEEDBACK_KIND_REQUEST, + content: intl.formatMessage(messages.requestContent), + }); + window.open(url, '_blank', 'noopener,noreferrer'); + }, + [intl], + ); + const sentences = choice ? dnclSettingsSentences(choice) : []; return ( @@ -127,6 +160,14 @@ const ProblemSettingsModal = ({ intl, currentPatternId, onDecide, onRequestClose