Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .claude/rules/scratch-gui/e2e-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

Expand Down
3 changes: 2 additions & 1 deletion docs/dncl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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・スマホの横向き)では、ポップアップを画面の上に寄せ、中身をスクロールできるようにする(共有のモーダルの外側はスクロールしないので、そのままでは「決定」が画面の外に出る)。

Expand All @@ -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`)を出さない。
Expand Down
2 changes: 2 additions & 0 deletions packages/scratch-gui/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -127,6 +160,14 @@ const ProblemSettingsModal = ({ intl, currentPatternId, onDecide, onRequestClose
<div className={styles.note}>{intl.formatMessage(messages.othersKept)}</div>
</>
)}
<a
className={styles.requestLink}
data-testid="problem-settings-modal-request"
href="#"
onClick={handleRequest}
>
{intl.formatMessage(messages.request)}
</a>
<div className={styles.buttonRow}>
<button
className={styles.cancelButton}
Expand Down
30 changes: 30 additions & 0 deletions packages/scratch-gui/src/lib/feedback-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// === Smalruby: This file is Smalruby-specific (the URL of the feedback form with values filled in) ===

/** The Google Form of 「フィードバックを送信」 (the link at the bottom right of the editor). */
const FEEDBACK_FORM_URL =
'https://docs.google.com/forms/d/e/1FAIpQLSemSOgv8TlJXF6vmFzVm5yUdcNZVMEKBcBcsKHnbW0RFmU3sg/viewform';

// The ids of the questions of the form: 「お問い合わせの種類」 and 「お問い合わせの内容」.
const ENTRY_KIND = 'entry.366340186';
const ENTRY_CONTENT = 'entry.419674590';

/** The choice 「機能要望」 of 「お問い合わせの種類」. It must be the same as the choice of the form. */
const FEEDBACK_KIND_REQUEST = '機能要望';

/**
* The URL of the feedback form with the kind and the content filled in,
* so that the user only writes what is left (#2635).
* @param {object} [values] - The values to fill in.
* @param {string} [values.kind] - The choice of 「お問い合わせの種類」.
* @param {string} [values.content] - The text of 「お問い合わせの内容」.
* @returns {string} The URL of the form.
*/
const feedbackFormUrl = ({ kind, content } = {}) => {
const params = new URLSearchParams();
if (kind) params.set(ENTRY_KIND, kind);
if (content) params.set(ENTRY_CONTENT, content);
if ([...params.keys()].length === 0) return FEEDBACK_FORM_URL;
return `${FEEDBACK_FORM_URL}?usp=pp_url&${params.toString()}`;
};

export { FEEDBACK_FORM_URL, FEEDBACK_KIND_REQUEST, feedbackFormUrl };
5 changes: 5 additions & 0 deletions packages/scratch-gui/src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,11 @@ export default {
'gui.problemSettingsModal.sentencesLabel': 'The sentences written at the top of the program:',
'gui.problemSettingsModal.noSentences': '(Nothing is written. The sentences of the rules now are removed.)',
'gui.problemSettingsModal.othersKept': 'The other comments stay as they are.',
'gui.problemSettingsModal.request': 'Ask for another rule',
'gui.problemSettingsModal.requestConfirm':
'This asks the developers of Smalruby to add a rule of the problem. Open the page to send feedback?',
'gui.problemSettingsModal.requestContent':
'Please add a rule of the problem to the Japanese mode.\nThe sentence of the rule to add:\n',
'gui.problemSettingsModal.cancel': 'Cancel',
'gui.problemSettingsModal.ok': 'OK',
'gui.problemSettingsBand.label': 'Rules of the problem: {rules}',
Expand Down
5 changes: 5 additions & 0 deletions packages/scratch-gui/src/locales/ja-Hira.js
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,11 @@ export default {
'gui.problemSettingsModal.sentencesLabel': 'プログラムのせんとうにはいるぶん:',
'gui.problemSettingsModal.noSentences': '(なにもはいりません。いまのやくそくのぶんはきえます)',
'gui.problemSettingsModal.othersKept': 'ほかのコメントはそのままのこります。',
'gui.problemSettingsModal.request': 'ほかのやくそくをたのむ',
'gui.problemSettingsModal.requestConfirm':
'スモウルビーのかいはつしゃに、もんだいのやくそくをたしてほしいとたのみます。フィードバックのがめんをひらきますか?',
'gui.problemSettingsModal.requestContent':
'にほんごモードのもんだいのやくそくをたしてほしい。\nたしたいやくそくのぶん:\n',
'gui.problemSettingsModal.cancel': 'キャンセル',
'gui.problemSettingsModal.ok': 'けってい',
'gui.problemSettingsBand.label': 'もんだいのやくそく: {rules}',
Expand Down
4 changes: 4 additions & 0 deletions packages/scratch-gui/src/locales/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,10 @@ export default {
'gui.problemSettingsModal.sentencesLabel': 'プログラムの先頭に入る文:',
'gui.problemSettingsModal.noSentences': '(何も入りません。いまの約束の文は消えます)',
'gui.problemSettingsModal.othersKept': 'ほかのコメントはそのまま残ります。',
'gui.problemSettingsModal.request': 'ほかの約束を頼む',
'gui.problemSettingsModal.requestConfirm':
'スモウルビーの開発者に、問題の約束を足してほしいと頼みます。フィードバックの画面を開きますか?',
'gui.problemSettingsModal.requestContent': '日本語モードの問題の約束を足してほしい。\n足したい約束の文:\n',
'gui.problemSettingsModal.cancel': 'キャンセル',
'gui.problemSettingsModal.ok': '決定',
'gui.problemSettingsBand.label': '問題の約束: {rules}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,36 @@ describe('ProblemSettingsBandItem', () => {
expect(props.onChange).toHaveBeenCalledTimes(1);
});
});

describe('ProblemSettingsModal: asking for another rule', () => {
let confirmSpy;
let openSpy;
beforeEach(() => {
confirmSpy = jest.spyOn(window, 'confirm');
openSpy = jest.spyOn(window, 'open').mockImplementation(() => null);
});
afterEach(() => {
confirmSpy.mockRestore();
openSpy.mockRestore();
});

test('confirms, then opens the feedback form with the request filled in', () => {
confirmSpy.mockReturnValue(true);
const { container } = renderModal();
const link = byTestId(container, 'problem-settings-modal-request');
expect(link).toHaveTextContent('ほかの約束を頼む');
fireEvent.click(link);
expect(confirmSpy.mock.calls[0][0]).toContain('問題の約束を足してほしいと頼みます');
expect(openSpy).toHaveBeenCalledTimes(1);
const url = new URL(openSpy.mock.calls[0][0]);
expect(url.searchParams.get('entry.366340186')).toBe('機能要望');
expect(url.searchParams.get('entry.419674590')).toContain('日本語モードの問題の約束を足してほしい');
});

test('says no, and nothing opens', () => {
confirmSpy.mockReturnValue(false);
const { container } = renderModal();
fireEvent.click(byTestId(container, 'problem-settings-modal-request'));
expect(openSpy).not.toHaveBeenCalled();
});
});
17 changes: 17 additions & 0 deletions packages/scratch-gui/test/unit/lib/feedback-form.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-env jest */
// The URL of the feedback form with the kind and the content filled in (#2635)
import { FEEDBACK_FORM_URL, FEEDBACK_KIND_REQUEST, feedbackFormUrl } from '../../../src/lib/feedback-form';

describe('feedbackFormUrl', () => {
test('without values is the plain form', () => {
expect(feedbackFormUrl()).toBe(FEEDBACK_FORM_URL);
});

test('fills in the kind and the content', () => {
const url = new URL(feedbackFormUrl({ kind: FEEDBACK_KIND_REQUEST, content: '約束を足して\n文: ' }));
expect(url.origin + url.pathname).toBe(FEEDBACK_FORM_URL);
expect(url.searchParams.get('usp')).toBe('pp_url');
expect(url.searchParams.get('entry.366340186')).toBe('機能要望');
expect(url.searchParams.get('entry.419674590')).toBe('約束を足して\n文: ');
});
});
Loading