Skip to content

Commit e0fce43

Browse files
chore: optimizations around browser dropdown code (#31256)
* chore: optimizations around browser dropdown code * Write test for overlayZIndex prop, ensuring it takes effect + update styles. * pass in numbers
1 parent c66b449 commit e0fce43

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

packages/app/src/runner/SpecRunnerDropdown.vue

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ import { Popover, PopoverButton, PopoverPanel } from '@headlessui/vue'
6464
const props = withDefaults(defineProps<{
6565
variant?: 'panel'
6666
align?: 'left' | 'right'
67+
// The minimal prop is used to style the dropdown as a minimal button with
68+
// no border, background, or chevron icon.
6769
minimal?: boolean
6870
// The disabled prop is used as the Popover key so that changes to the prop
6971
// cause the Popover component to mount again. This re-mounting ensures that

packages/app/src/runner/SpecRunnerHeaderOpenMode.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
v-if="studioStore.needsUrl && !urlDisabled"
6363
:aut-url-input-ref="autUrlInputRef"
6464
:url-in-progress="urlInProgress"
65+
:overlay-z-index="studioOverlayZIndex"
6566
@submit="visitUrl"
6667
@cancel="() => eventManager.emit('studio:cancel', undefined)"
6768
/>
@@ -182,10 +183,12 @@ watchEffect(() => {
182183
183184
const autIframe = props.getAutIframe()
184185
186+
const studioOverlayZIndex = 50
187+
185188
const inputZIndex = computed(() => {
186189
// input needs to be above the Studio prompt overlay
187190
// but other times it needs to be below other resizable panels
188-
return studioStore.needsUrl ? 51 : 5
191+
return studioStore.needsUrl ? studioOverlayZIndex + 1 : 5
189192
})
190193
191194
const displayScale = computed(() => {

packages/app/src/runner/studio/StudioUrlPrompt.cy.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import StudioUrlPrompt from './StudioUrlPrompt.vue'
22

33
describe('<StudioUrlPrompt />', () => {
44
it('renders', () => {
5-
cy.mount(<StudioUrlPrompt urlInProgress="" />)
5+
cy.mount(<StudioUrlPrompt urlInProgress="" overlayZIndex={50} />)
66
cy.percySnapshot()
77
})
88

9+
it('zindex of overlay matches passed in zindex', () => {
10+
cy.mount(<StudioUrlPrompt urlInProgress="" overlayZIndex={99} />)
11+
cy.get('[cy-data="studio-url-overlay"]').should('have.css', 'z-index', '99')
12+
})
13+
914
it('emits cancel when button is clicked', () => {
1015
const cancelStub = cy.stub()
1116

12-
cy.mount(<StudioUrlPrompt urlInProgress="" onCancel={cancelStub}/>)
17+
cy.mount(<StudioUrlPrompt urlInProgress="" overlayZIndex={50} onCancel={cancelStub}/>)
1318

1419
cy.findByText('Cancel').click().then(() => {
1520
expect(cancelStub).to.be.called
@@ -19,7 +24,7 @@ describe('<StudioUrlPrompt />', () => {
1924
it('disables submit button when url field is empty', () => {
2025
const continueStub = cy.stub()
2126

22-
cy.mount(<StudioUrlPrompt urlInProgress="" onSubmit={continueStub}/>)
27+
cy.mount(<StudioUrlPrompt urlInProgress="" overlayZIndex={50} onSubmit={continueStub}/>)
2328

2429
cy.findByText('Continue ➜').should('be.disabled')
2530
})
@@ -29,7 +34,7 @@ describe('<StudioUrlPrompt />', () => {
2934

3035
const url = 'http://localhost:8080'
3136

32-
cy.mount(<StudioUrlPrompt urlInProgress={url} onSubmit={continueStub}/>)
37+
cy.mount(<StudioUrlPrompt urlInProgress={url} overlayZIndex={50} onSubmit={continueStub}/>)
3338

3439
cy.findByText('Continue ➜').click().then(() => {
3540
expect(continueStub).to.be.called

packages/app/src/runner/studio/StudioUrlPrompt.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
</div>
2929
<div
3030
cy-data="studio-url-overlay"
31-
class="bg-black h-full w-full opacity-[.35] top-0 right-0 bottom-0 left-0 z-50 fixed"
31+
class="bg-black h-full w-full opacity-[.35] top-0 right-0 bottom-0 left-0 fixed"
32+
:style="{ zIndex: props.overlayZIndex }"
3233
/>
3334
</template>
3435

@@ -41,6 +42,7 @@ const { t } = useI18n()
4142
const props = defineProps<{
4243
autUrlInputRef?: HTMLInputElement
4344
urlInProgress: string
45+
overlayZIndex: number
4446
}>()
4547
4648
const emit = defineEmits<{

packages/frontend-shared/src/gql-components/topnav/VerticalBrowserListItems.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import { computed } from 'vue'
8080
import { gql, useMutation } from '@urql/vue'
8181
import { allBrowsersIcons } from '@packages/frontend-shared/src/assets/browserLogos'
8282
import Tooltip from '../../components/Tooltip.vue'
83+
import _ from 'lodash'
8384
8485
const { t } = useI18n()
8586
@@ -121,10 +122,12 @@ const props = withDefaults(defineProps <{
121122
})
122123
123124
const browsers = computed(() => {
124-
const alphaSortedBrowser = (props.gql.browsers ?? []).slice().sort((a, b) => a.displayName > b.displayName ? 1 : -1)
125+
const alphaSortedBrowser = _.sortBy(props.gql.browsers ?? [], 'displayName')
126+
127+
const [selectedBrowser] = _.remove(alphaSortedBrowser, (browser) => browser.isSelected)
125128
126129
// move the selected browser to the top to easily see selected browser version at the top when opening the dropdown
127-
alphaSortedBrowser.some((browser, i) => browser.isSelected && alphaSortedBrowser.unshift(alphaSortedBrowser.splice(i, 1)[0]))
130+
alphaSortedBrowser.unshift(selectedBrowser)
128131
129132
return alphaSortedBrowser
130133
})

0 commit comments

Comments
 (0)