diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-09-14 03:05:28 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-09-14 03:43:26 +0200 |
commit | 13b464db253566290be6a1063ad8e296288d3339 (patch) | |
tree | 29e0a9a346f66974d6c0be0482f511e9becab51c /subprojects/frontend/src | |
parent | fix(frontend): keep live while model generation (diff) | |
download | refinery-13b464db253566290be6a1063ad8e296288d3339.tar.gz refinery-13b464db253566290be6a1063ad8e296288d3339.tar.zst refinery-13b464db253566290be6a1063ad8e296288d3339.zip |
feat: specify random seed for generation
Diffstat (limited to 'subprojects/frontend/src')
8 files changed, 45 insertions, 17 deletions
diff --git a/subprojects/frontend/src/editor/AnimatedButton.tsx b/subprojects/frontend/src/editor/AnimatedButton.tsx index 24ec69be..606aabea 100644 --- a/subprojects/frontend/src/editor/AnimatedButton.tsx +++ b/subprojects/frontend/src/editor/AnimatedButton.tsx | |||
@@ -45,7 +45,7 @@ export default function AnimatedButton({ | |||
45 | children, | 45 | children, |
46 | }: { | 46 | }: { |
47 | 'aria-label'?: string; | 47 | 'aria-label'?: string; |
48 | onClick?: () => void; | 48 | onClick?: React.MouseEventHandler<HTMLElement>; |
49 | color: 'error' | 'warning' | 'primary' | 'inherit'; | 49 | color: 'error' | 'warning' | 'primary' | 'inherit'; |
50 | disabled?: boolean; | 50 | disabled?: boolean; |
51 | startIcon?: JSX.Element; | 51 | startIcon?: JSX.Element; |
diff --git a/subprojects/frontend/src/editor/EditorStore.ts b/subprojects/frontend/src/editor/EditorStore.ts index f9a9a7da..9508858d 100644 --- a/subprojects/frontend/src/editor/EditorStore.ts +++ b/subprojects/frontend/src/editor/EditorStore.ts | |||
@@ -313,14 +313,14 @@ export default class EditorStore { | |||
313 | this.disposed = true; | 313 | this.disposed = true; |
314 | } | 314 | } |
315 | 315 | ||
316 | startModelGeneration(): void { | 316 | startModelGeneration(randomSeed?: number): void { |
317 | this.client | 317 | this.client |
318 | ?.startModelGeneration() | 318 | ?.startModelGeneration(randomSeed) |
319 | ?.catch((error) => log.error('Could not start model generation', error)); | 319 | ?.catch((error) => log.error('Could not start model generation', error)); |
320 | } | 320 | } |
321 | 321 | ||
322 | addGeneratedModel(uuid: string): void { | 322 | addGeneratedModel(uuid: string, randomSeed: number): void { |
323 | this.generatedModels.set(uuid, new GeneratedModelStore()); | 323 | this.generatedModels.set(uuid, new GeneratedModelStore(randomSeed)); |
324 | this.selectGeneratedModel(uuid); | 324 | this.selectGeneratedModel(uuid); |
325 | } | 325 | } |
326 | 326 | ||
diff --git a/subprojects/frontend/src/editor/GenerateButton.tsx b/subprojects/frontend/src/editor/GenerateButton.tsx index b8dcd531..b6b1655a 100644 --- a/subprojects/frontend/src/editor/GenerateButton.tsx +++ b/subprojects/frontend/src/editor/GenerateButton.tsx | |||
@@ -98,7 +98,13 @@ const GenerateButton = observer(function GenerateButton({ | |||
98 | disabled={!editorStore.opened} | 98 | disabled={!editorStore.opened} |
99 | color={warningCount > 0 ? 'warning' : 'primary'} | 99 | color={warningCount > 0 ? 'warning' : 'primary'} |
100 | startIcon={<PlayArrowIcon />} | 100 | startIcon={<PlayArrowIcon />} |
101 | onClick={() => editorStore.startModelGeneration()} | 101 | onClick={(event) => { |
102 | if (event.shiftKey) { | ||
103 | editorStore.startModelGeneration(1); | ||
104 | } else { | ||
105 | editorStore.startModelGeneration(); | ||
106 | } | ||
107 | }} | ||
102 | > | 108 | > |
103 | {summary === '' ? GENERATE_LABEL : `${GENERATE_LABEL} (${summary})`} | 109 | {summary === '' ? GENERATE_LABEL : `${GENERATE_LABEL} (${summary})`} |
104 | </AnimatedButton> | 110 | </AnimatedButton> |
diff --git a/subprojects/frontend/src/editor/GeneratedModelStore.ts b/subprojects/frontend/src/editor/GeneratedModelStore.ts index d0181eed..5088d603 100644 --- a/subprojects/frontend/src/editor/GeneratedModelStore.ts +++ b/subprojects/frontend/src/editor/GeneratedModelStore.ts | |||
@@ -18,9 +18,9 @@ export default class GeneratedModelStore { | |||
18 | 18 | ||
19 | graph: GraphStore | undefined; | 19 | graph: GraphStore | undefined; |
20 | 20 | ||
21 | constructor() { | 21 | constructor(randomSeed: number) { |
22 | const time = new Date().toLocaleTimeString(undefined, { hour12: false }); | 22 | const time = new Date().toLocaleTimeString(undefined, { hour12: false }); |
23 | this.title = `Generated at ${time}`; | 23 | this.title = `Generated at ${time} (${randomSeed})`; |
24 | makeAutoObservable(this); | 24 | makeAutoObservable(this); |
25 | } | 25 | } |
26 | 26 | ||
diff --git a/subprojects/frontend/src/xtext/ModelGenerationService.ts b/subprojects/frontend/src/xtext/ModelGenerationService.ts index 1e9f837a..29a70623 100644 --- a/subprojects/frontend/src/xtext/ModelGenerationService.ts +++ b/subprojects/frontend/src/xtext/ModelGenerationService.ts | |||
@@ -4,12 +4,18 @@ | |||
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | 6 | ||
7 | import type { Transaction } from '@codemirror/state'; | ||
8 | |||
7 | import type EditorStore from '../editor/EditorStore'; | 9 | import type EditorStore from '../editor/EditorStore'; |
8 | 10 | ||
9 | import type UpdateService from './UpdateService'; | 11 | import type UpdateService from './UpdateService'; |
10 | import { ModelGenerationResult } from './xtextServiceResults'; | 12 | import { ModelGenerationResult } from './xtextServiceResults'; |
11 | 13 | ||
14 | const INITIAL_RANDOM_SEED = 1; | ||
15 | |||
12 | export default class ModelGenerationService { | 16 | export default class ModelGenerationService { |
17 | private nextRandomSeed = INITIAL_RANDOM_SEED; | ||
18 | |||
13 | constructor( | 19 | constructor( |
14 | private readonly store: EditorStore, | 20 | private readonly store: EditorStore, |
15 | private readonly updateService: UpdateService, | 21 | private readonly updateService: UpdateService, |
@@ -26,14 +32,24 @@ export default class ModelGenerationService { | |||
26 | } | 32 | } |
27 | } | 33 | } |
28 | 34 | ||
35 | onTransaction(transaction: Transaction): void { | ||
36 | if (transaction.docChanged) { | ||
37 | this.resetRandomSeed(); | ||
38 | } | ||
39 | } | ||
40 | |||
29 | onDisconnect(): void { | 41 | onDisconnect(): void { |
30 | this.store.modelGenerationCancelled(); | 42 | this.store.modelGenerationCancelled(); |
43 | this.resetRandomSeed(); | ||
31 | } | 44 | } |
32 | 45 | ||
33 | async start(): Promise<void> { | 46 | async start(randomSeed?: number): Promise<void> { |
34 | const result = await this.updateService.startModelGeneration(); | 47 | const randomSeedOrNext = randomSeed ?? this.nextRandomSeed; |
48 | this.nextRandomSeed = randomSeedOrNext + 1; | ||
49 | const result = | ||
50 | await this.updateService.startModelGeneration(randomSeedOrNext); | ||
35 | if (!result.cancelled) { | 51 | if (!result.cancelled) { |
36 | this.store.addGeneratedModel(result.data.uuid); | 52 | this.store.addGeneratedModel(result.data.uuid, randomSeedOrNext); |
37 | } | 53 | } |
38 | } | 54 | } |
39 | 55 | ||
@@ -43,4 +59,8 @@ export default class ModelGenerationService { | |||
43 | this.store.modelGenerationCancelled(); | 59 | this.store.modelGenerationCancelled(); |
44 | } | 60 | } |
45 | } | 61 | } |
62 | |||
63 | private resetRandomSeed() { | ||
64 | this.nextRandomSeed = INITIAL_RANDOM_SEED; | ||
65 | } | ||
46 | } | 66 | } |
diff --git a/subprojects/frontend/src/xtext/UpdateService.ts b/subprojects/frontend/src/xtext/UpdateService.ts index d1246d5e..70e79764 100644 --- a/subprojects/frontend/src/xtext/UpdateService.ts +++ b/subprojects/frontend/src/xtext/UpdateService.ts | |||
@@ -343,9 +343,9 @@ export default class UpdateService { | |||
343 | return { cancelled: false, data: parsedOccurrencesResult }; | 343 | return { cancelled: false, data: parsedOccurrencesResult }; |
344 | } | 344 | } |
345 | 345 | ||
346 | async startModelGeneration(): Promise< | 346 | async startModelGeneration( |
347 | CancellableResult<ModelGenerationStartedResult> | 347 | randomSeed: number, |
348 | > { | 348 | ): Promise<CancellableResult<ModelGenerationStartedResult>> { |
349 | try { | 349 | try { |
350 | await this.updateOrThrow(); | 350 | await this.updateOrThrow(); |
351 | } catch (error) { | 351 | } catch (error) { |
@@ -360,6 +360,7 @@ export default class UpdateService { | |||
360 | serviceType: 'modelGeneration', | 360 | serviceType: 'modelGeneration', |
361 | requiredStateId: this.xtextStateId, | 361 | requiredStateId: this.xtextStateId, |
362 | start: true, | 362 | start: true, |
363 | randomSeed, | ||
363 | }); | 364 | }); |
364 | if (isConflictResult(data)) { | 365 | if (isConflictResult(data)) { |
365 | return { cancelled: true }; | 366 | return { cancelled: true }; |
diff --git a/subprojects/frontend/src/xtext/XtextClient.ts b/subprojects/frontend/src/xtext/XtextClient.ts index 4df4f57a..7486d737 100644 --- a/subprojects/frontend/src/xtext/XtextClient.ts +++ b/subprojects/frontend/src/xtext/XtextClient.ts | |||
@@ -99,6 +99,7 @@ export default class XtextClient { | |||
99 | this.contentAssistService.onTransaction(transaction); | 99 | this.contentAssistService.onTransaction(transaction); |
100 | this.updateService.onTransaction(transaction); | 100 | this.updateService.onTransaction(transaction); |
101 | this.occurrencesService.onTransaction(transaction); | 101 | this.occurrencesService.onTransaction(transaction); |
102 | this.modelGenerationService.onTransaction(transaction); | ||
102 | } | 103 | } |
103 | 104 | ||
104 | private onPush( | 105 | private onPush( |
@@ -150,8 +151,8 @@ export default class XtextClient { | |||
150 | return this.contentAssistService.contentAssist(context); | 151 | return this.contentAssistService.contentAssist(context); |
151 | } | 152 | } |
152 | 153 | ||
153 | startModelGeneration(): Promise<void> { | 154 | startModelGeneration(randomSeed?: number): Promise<void> { |
154 | return this.modelGenerationService.start(); | 155 | return this.modelGenerationService.start(randomSeed); |
155 | } | 156 | } |
156 | 157 | ||
157 | cancelModelGeneration(): Promise<void> { | 158 | cancelModelGeneration(): Promise<void> { |
diff --git a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts index bb84223c..280ac875 100644 --- a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts +++ b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts | |||
@@ -204,7 +204,7 @@ export default class XtextWebSocketClient { | |||
204 | 204 | ||
205 | get state() { | 205 | get state() { |
206 | this.stateAtom.reportObserved(); | 206 | this.stateAtom.reportObserved(); |
207 | return this.interpreter.state; | 207 | return this.interpreter.getSnapshot(); |
208 | } | 208 | } |
209 | 209 | ||
210 | get opening(): boolean { | 210 | get opening(): boolean { |