-
Notifications
You must be signed in to change notification settings - Fork 113
feat(laboratory): scope environment variables to target #6500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jasonkuhrt
wants to merge
13
commits into
main
Choose a base branch
from
console-994
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dcdb72e
feat(laboratory): scope environment variables to target
jasonkuhrt 47ee32f
unit tests
jasonkuhrt ce95ba6
changeset
jasonkuhrt 2ef5394
Merge branch 'main' into console-994
jasonkuhrt c166d97
ignore
jasonkuhrt c7b974c
fix useState
jasonkuhrt f4bdfe6
e2e tests that work
jasonkuhrt b7729cc
factor out
jasonkuhrt a83b7a3
Merge branch 'main' into console-994
jasonkuhrt b92f941
type import
jasonkuhrt 84b7d52
last e2e test
jasonkuhrt 895d220
optimize
jasonkuhrt 8a1c77f
thing
jasonkuhrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
'hive': minor | ||
--- | ||
|
||
Laboratory Environment Variables are now scoped to Target. | ||
|
||
Previously, we stored environment variables as a static key in your browser's local storage. This meant that any changes to the environment variables would affect all targets' Laboratory. | ||
|
||
Now when you use Laboratory, any changes to the environment variables will not affect the environment variables of other targets' Laboratory. | ||
|
||
## Migration Details (TL;DR: You Won't Notice Anything!) | ||
|
||
For an indefinite period of time we will support the following migration when you load Laboratory on any target. If this holds true: | ||
|
||
1. Your browser's localStorage has a key for the global environment variables; | ||
2. Your browser's localStorage does NOT have a key for scoped environment variables for the Target Laboratory being loaded; | ||
|
||
Then we will initialize the scoped environment variables for the Target Laboratory being loaded with the global ones. | ||
|
||
Laboratory will _never_ write to the global environment variables again, so this should give you a seamless migration to scoped environment variables for all your targets. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { | ||
environmentVariablesStorageKey, | ||
persistAuthenticationCookies, | ||
selectors, | ||
type Target, | ||
} from '../support/testkit'; | ||
|
||
const data = { | ||
globalEnvars: { foo: '123' }, | ||
globalEnvarsJson: '{"foo":"123"}', | ||
scopedEnvars: { bar: '456' }, | ||
targetEnvarsJson: '{"bar":"456"}', | ||
}; | ||
|
||
interface Ctx { | ||
targetDevelopment: Target; | ||
targetProduction: Target; | ||
cookies: Cypress.Cookie[]; | ||
} | ||
const ctx = { | ||
cookies: [], | ||
} as Ctx; | ||
|
||
before(() => { | ||
cy.task('seedTarget').then(({ refreshToken, targets }: any) => { | ||
cy.setCookie('sRefreshToken', refreshToken); | ||
ctx.targetDevelopment = targets.development; | ||
ctx.targetProduction = targets.production; | ||
}); | ||
}); | ||
|
||
persistAuthenticationCookies(); | ||
|
||
const openPreflightTab = () => cy.get(selectors.buttonGraphiQLPreflight).click(); | ||
const openPreflightModal = () => cy.dataCy(selectors.buttonModalCy).click(); | ||
|
||
const storageGlobalGet = () => cy.getLocalStorage(environmentVariablesStorageKey.global); | ||
const storageGlobalSet = (value: string) => cy.setLocalStorage(environmentVariablesStorageKey.global, value); // prettier-ignore | ||
const storageGlobalRemove = () => cy.removeLocalStorage(environmentVariablesStorageKey.global); | ||
|
||
const visitTargetDevelopment = () => cy.visit(`${ctx.targetDevelopment.path}/laboratory`); | ||
const storageTargetDevelopmentGet = () => cy.getLocalStorage(environmentVariablesStorageKey.scoped(ctx.targetDevelopment.id)); // prettier-ignore | ||
const storageTargetDevelopmentSet = (value: string) => cy.setLocalStorage(environmentVariablesStorageKey.scoped(ctx.targetDevelopment.id), value); // prettier-ignore | ||
const storageTargetDevelopmentRemove = () => cy.removeLocalStorage(environmentVariablesStorageKey.scoped(ctx.targetDevelopment.id)); // prettier-ignore | ||
|
||
const visitTargetProduction = () => cy.visit(`${ctx.targetProduction.path}/laboratory`); | ||
// const storageTargetProductionGet = () => cy.getLocalStorage(environmentVariablesStorageKey.scoped(ctx.targetProduction.id)); // prettier-ignore | ||
// const storageTargetProductionSet = (value: string) => cy.setLocalStorage(environmentVariablesStorageKey.scoped(ctx.targetProduction.id), value); // prettier-ignore | ||
const storageTargetProductionRemove = () => cy.removeLocalStorage(environmentVariablesStorageKey.scoped(ctx.targetProduction.id)); // prettier-ignore | ||
|
||
beforeEach(() => { | ||
storageGlobalRemove(); | ||
storageTargetDevelopmentRemove(); | ||
storageTargetProductionRemove(); | ||
}); | ||
|
||
describe('tab editor', () => { | ||
it('if state empty, is null', () => { | ||
visitTargetDevelopment(); | ||
openPreflightTab(); | ||
storageTargetDevelopmentGet().should('equal', null); | ||
storageGlobalGet().should('equal', null); | ||
}); | ||
|
||
it('if storage just has target-scope value, value used', () => { | ||
storageTargetDevelopmentSet(data.targetEnvarsJson); | ||
visitTargetDevelopment(); | ||
openPreflightTab(); | ||
cy.contains(data.targetEnvarsJson); | ||
}); | ||
|
||
it('if storage just has global-scope value, copied to new target-scope value, used', () => { | ||
storageGlobalSet(data.globalEnvarsJson); | ||
visitTargetDevelopment(); | ||
openPreflightTab(); | ||
cy.contains(data.globalEnvarsJson); | ||
storageTargetDevelopmentGet().should('equal', data.globalEnvarsJson); | ||
}); | ||
|
||
it('if storage has global-scope AND target-scope values, target-scope value used', () => { | ||
storageTargetDevelopmentSet(data.targetEnvarsJson); | ||
storageGlobalSet(data.globalEnvarsJson); | ||
visitTargetDevelopment(); | ||
openPreflightTab(); | ||
cy.contains(data.targetEnvarsJson); | ||
}); | ||
}); | ||
|
||
describe('modal', () => { | ||
it('changing environment variables persists to target-scope', () => { | ||
storageGlobalSet(data.globalEnvarsJson); | ||
visitTargetDevelopment(); | ||
openPreflightTab(); | ||
openPreflightModal(); | ||
cy.contains(data.globalEnvarsJson); | ||
setMonacoEditorContents('env-editor', data.targetEnvarsJson); | ||
storageTargetDevelopmentGet().should('equal', data.targetEnvarsJson); | ||
cy.contains(data.targetEnvarsJson); | ||
visitTargetProduction(); | ||
openPreflightTab(); | ||
cy.contains(data.globalEnvarsJson); | ||
}); | ||
}); | ||
|
||
// todo: in another PR this utility is factored out into a shared file | ||
/** Helper function for setting the text within a monaco editor as typing manually results in flaky tests */ | ||
export function setMonacoEditorContents(editorCyName: string, text: string) { | ||
// wait for textarea appearing which indicates monaco is loaded | ||
cy.dataCy(editorCyName).find('textarea'); | ||
cy.window().then(win => { | ||
// First, check if monaco is available on the main window | ||
const editor = (win as any).monaco.editor | ||
.getEditors() | ||
.find(e => e.getContainerDomNode().parentElement.getAttribute('data-cy') === editorCyName); | ||
|
||
// If Monaco instance is found | ||
if (editor) { | ||
editor.setValue(text); | ||
} else { | ||
throw new Error('Monaco editor not found on the window or frames[0]'); | ||
} | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.