Skip to content

Commit fe9d904

Browse files
authored
fix: re-enable the flipping of sync styling on and off, as the composition synced is toggled on and off (#6420)
1 parent 475da92 commit fe9d904

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

cypress/e2e/shared/fluxQueryBuilder.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,30 @@ describe('Script Builder', () => {
638638
cy.log('starts as synced')
639639
cy.getByTestID('flux-sync--toggle').should('have.class', 'active')
640640

641-
cy.log('sync toggles on and off')
641+
cy.log('empty editor text')
642+
cy.getByTestID('flux-editor').monacoType('{selectAll}{del}')
643+
644+
cy.log('Ensure LSP is online') // deflake
645+
cy.wait(DELAY_FOR_LSP_SERVER_BOOTUP)
646+
647+
cy.log('make a composition')
648+
selectSchema()
649+
confirmSchemaComposition()
650+
651+
cy.log('sync toggles on and off, with matching styles')
652+
cy.get('.composition-sync--on').should('have.length', 3)
653+
cy.get('.composition-sync--off').should('have.length', 0)
642654
cy.getByTestID('flux-sync--toggle')
643655
.should('have.class', 'active')
644656
.click()
645657
.should('not.have.class', 'active')
658+
cy.get('.composition-sync--on').should('have.length', 0)
659+
cy.get('.composition-sync--off').should('have.length', 3)
660+
cy.getByTestID('flux-sync--toggle')
646661
.click()
647662
.should('have.class', 'active')
663+
cy.get('.composition-sync--on').should('have.length', 3)
664+
cy.get('.composition-sync--off').should('have.length', 0)
648665

649666
cy.log('turn off flux sync')
650667
cy.getByTestID('flux-sync--toggle')

src/languageSupport/languages/flux/lsp/connection.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class ConnectionManager {
5959
) => void = () => null
6060
private _dispatcher = _ => {}
6161
private _first_load = true
62+
private _compositionRange: LspRange
6263

6364
constructor(worker: Worker) {
6465
this._worker = worker
@@ -147,8 +148,10 @@ export class ConnectionManager {
147148
})
148149
}
149150

150-
_compositionSyncStyle(startLine: number, endLine: number) {
151-
const classNamePrefix = 'composition-sync--on'
151+
_compositionSyncStyle(startLine: number, endLine: number, synced: boolean) {
152+
const classNamePrefix = synced
153+
? 'composition-sync--on'
154+
: 'composition-sync--off'
152155

153156
// Customize the full width of Monaco editor margin using API `marginClassName`
154157
// https://github.com/microsoft/monaco-editor/blob/35eb0ef/website/typedoc/monaco.d.ts#L1533
@@ -173,14 +176,15 @@ export class ConnectionManager {
173176
return [startLineStyle, middleLinesStyle, endLineStyle]
174177
}
175178

176-
_setEditorBlockStyle(range: LspRange | null) {
179+
_setEditorBlockStyle(range: LspRange | null, synced: boolean = false) {
180+
this._compositionRange = range
177181
const shouldRemoveAllStyles = range == null
178182

179183
this._compositionStyle = this._editor.deltaDecorations(
180184
this._compositionStyle,
181185
shouldRemoveAllStyles
182186
? []
183-
: this._compositionSyncStyle(range.start.line, range.end.line)
187+
: this._compositionSyncStyle(range.start.line, range.end.line, synced)
184188
)
185189
}
186190

@@ -348,9 +352,17 @@ export class ConnectionManager {
348352
}
349353

350354
if (!schema.composition.synced) {
355+
this._session.composition.synced = false
356+
this._setEditorBlockStyle(this._compositionRange)
351357
return
352358
}
359+
const syncTurnedBackOn =
360+
schema.composition.synced && !previousState.composition.synced
361+
if (syncTurnedBackOn) {
362+
this._setEditorBlockStyle(this._compositionRange, true)
363+
}
353364

365+
// don't update the `this._session` until here. Since used to diffChange.
354366
this._session = {...schema, composition: {...schema.composition}}
355367
const {toAdd, toRemove, shouldRemoveDefaultMsg} = this._diffSchemaChange(
356368
schema,
@@ -414,7 +426,7 @@ export class ConnectionManager {
414426
actions.forEach((action: ActionItem) => {
415427
switch (action.title) {
416428
case ActionItemCommand.CompositionRange:
417-
this._setEditorBlockStyle(action.range)
429+
this._setEditorBlockStyle(action.range, true)
418430
break
419431
case ActionItemCommand.CompositionState:
420432
if (action.state) {

src/shared/components/MonacoEditor.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,24 @@
8080
.composition-sync--on--last {
8181
border-bottom: 1px solid $c-pool;
8282
}
83+
84+
.composition-sync--off {
85+
opacity: 50%;
86+
background-color: $cf-grey-35;
87+
}
88+
89+
.composition-sync--off--first {
90+
opacity: 50%;
91+
border-top: 1px solid $cf-white;
92+
// composition sync icon
93+
background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M4.82511 4.0427L7.10622 1.6971L5.67243 0.302734L0.0902793 6.0427H16V4.0427H4.82511ZM11.1749 11.9571H0V9.95714H15.9097L10.3275 15.6971L8.89376 14.3027L11.1749 11.9571Z' fill='white'/%3E%3C/svg%3E%0A");
94+
background-repeat: no-repeat;
95+
background-size: 11px 11px;
96+
background-position: $cf-space-3xs $cf-space-3xs;
97+
}
98+
99+
.composition-sync--off--last {
100+
opacity: 50%;
101+
border-bottom: 1px solid $cf-white;
102+
}
83103
}

0 commit comments

Comments
 (0)