Skip to content
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

feat: generate mobile replays for local dev #19228

Closed
wants to merge 7 commits into from
Closed
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
21 changes: 18 additions & 3 deletions ee/frontend/mobile-replay/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,13 @@ exports[`replay/transform transform can process unknown types without error 1`]
"childNodes": [
{
"attributes": {
"display": "block",
"fill": "grey",
"height": 30,
"style": "width: 100px;height: 30px;position: fixed;left: 25px;top: 42px;",
"style": "background-color: grey;width: 100px;height: 30px;position: fixed;left: 25px;top: 42px;",
"width": 100,
"x": 0,
"y": 0,
},
"childNodes": [],
"id": 101,
Expand All @@ -363,9 +366,11 @@ exports[`replay/transform transform can process unknown types without error 1`]
},
{
"attributes": {
"display": "block",
"dominant-baseline": "middle",
"fill": "white",
"font-size": "30",
"style": "background-color: grey;width: 100px;height: 30px;position: fixed;left: 25px;top: 42px;",
"text-anchor": "middle",
"x": "50%",
"y": "50%",
Expand Down Expand Up @@ -2628,10 +2633,13 @@ exports[`replay/transform transform inputs placeholder - $inputType - $value 1`]
"childNodes": [
{
"attributes": {
"display": "block",
"fill": "grey",
"height": 30,
"style": "width: 100px;height: 30px;position: fixed;left: 0px;top: 0px;",
"style": "background-color: grey;width: 100px;height: 30px;position: fixed;left: 0px;top: 0px;",
"width": 100,
"x": 0,
"y": 0,
},
"childNodes": [],
"id": 170,
Expand All @@ -2640,9 +2648,11 @@ exports[`replay/transform transform inputs placeholder - $inputType - $value 1`]
},
{
"attributes": {
"display": "block",
"dominant-baseline": "middle",
"fill": "white",
"font-size": "30",
"style": "background-color: grey;width: 100px;height: 30px;position: fixed;left: 0px;top: 0px;",
"text-anchor": "middle",
"x": "50%",
"y": "50%",
Expand Down Expand Up @@ -3080,10 +3090,13 @@ exports[`replay/transform transform omitting x and y is equivalent to setting th
"childNodes": [
{
"attributes": {
"display": "block",
"fill": "grey",
"height": 30,
"style": "width: 100px;height: 30px;position: fixed;left: 0px;top: 0px;",
"style": "background-color: grey;width: 100px;height: 30px;position: fixed;left: 0px;top: 0px;",
"width": 100,
"x": 0,
"y": 0,
},
"childNodes": [],
"id": 115,
Expand All @@ -3092,9 +3105,11 @@ exports[`replay/transform transform omitting x and y is equivalent to setting th
},
{
"attributes": {
"display": "block",
"dominant-baseline": "middle",
"fill": "white",
"font-size": "30",
"style": "background-color: grey;width: 100px;height: 30px;position: fixed;left: 0px;top: 0px;",
"text-anchor": "middle",
"x": "50%",
"y": "50%",
Expand Down
9 changes: 8 additions & 1 deletion ee/frontend/mobile-replay/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ function makePlaceholderElement(wireframe: wireframe, children: serializedNodeWi
type: NodeType.Element,
tagName: 'rect',
attributes: {
x: 0,
y: 0,
width: wireframe.width,
height: wireframe.height,
style: makeStylesString(wireframe),
fill: wireframe.style?.backgroundColor || 'grey',
...makeSvgBorder(wireframe.style),
style: makeStylesString(wireframe, { backgroundColor: 'grey' }),
display: 'block', // otherwise defaults to inline
},
id: idSequence.next().value,
childNodes: [],
Expand All @@ -164,6 +168,9 @@ function makePlaceholderElement(wireframe: wireframe, children: serializedNodeWi
y: '50%',
'dominant-baseline': 'middle',
'text-anchor': 'middle',
...makeSvgBorder(wireframe.style),
style: makeStylesString(wireframe, { backgroundColor: 'grey' }),
display: 'block', // otherwise defaults to inline
},
id: idSequence.next().value,
childNodes: [
Expand Down
80 changes: 51 additions & 29 deletions ee/frontend/mobile-replay/wireframeStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ function ensureUnit(value: string | number): string {
return isNumber(value) ? `${value}px` : value.replace(/px$/g, '') + 'px'
}

function makeBorderStyles(wireframe: wireframe): string {
function makeBorderStyles(wireframe: wireframe, styleOverride?: MobileStyles): string {
let styles = ''

if (!wireframe.style) {
const combinedStyles = {
...wireframe.style,
...styleOverride,
}

if (!combinedStyles) {
return styles
}

if (isUnitLike(wireframe.style.borderWidth)) {
const borderWidth = ensureUnit(wireframe.style.borderWidth)
if (isUnitLike(combinedStyles.borderWidth)) {
const borderWidth = ensureUnit(combinedStyles.borderWidth)
styles += `border-width: ${borderWidth};`
}
if (isUnitLike(wireframe.style.borderRadius)) {
const borderRadius = ensureUnit(wireframe.style.borderRadius)
if (isUnitLike(combinedStyles.borderRadius)) {
const borderRadius = ensureUnit(combinedStyles.borderRadius)
styles += `border-radius: ${borderRadius};`
}
if (wireframe.style?.borderColor) {
styles += `border-color: ${wireframe.style.borderColor};`
if (combinedStyles?.borderColor) {
styles += `border-color: ${combinedStyles.borderColor};`
}

if (styles.length > 0) {
Expand Down Expand Up @@ -85,16 +90,22 @@ export function makePositionStyles(wireframe: wireframe): string {
return styles
}

function makeLayoutStyles(wireframe: wireframe): string {
function makeLayoutStyles(wireframe: wireframe, styleOverride?: MobileStyles): string {
let styles = ''
if (wireframe.style?.verticalAlign) {

const combinedStyles = {
...wireframe.style,
...styleOverride,
}

if (combinedStyles.verticalAlign) {
styles += `align-items: ${
{ top: 'flex-start', center: 'center', bottom: 'flex-end' }[wireframe.style.verticalAlign]
{ top: 'flex-start', center: 'center', bottom: 'flex-end' }[combinedStyles.verticalAlign]
};`
}
if (wireframe.style?.horizontalAlign) {
if (combinedStyles.horizontalAlign) {
styles += `justify-content: ${
{ left: 'flex-start', center: 'center', right: 'flex-end' }[wireframe.style.horizontalAlign]
{ left: 'flex-start', center: 'center', right: 'flex-end' }[combinedStyles.horizontalAlign]
};`
}
if (styles.length) {
Expand All @@ -103,18 +114,23 @@ function makeLayoutStyles(wireframe: wireframe): string {
return styles
}

function makeFontStyles(wireframe: wireframe): string {
function makeFontStyles(wireframe: wireframe, styleOverride?: MobileStyles): string {
let styles = ''

if (!wireframe.style) {
const combinedStyles = {
...wireframe.style,
...styleOverride,
}

if (!combinedStyles) {
return styles
}

if (isUnitLike(wireframe.style.fontSize)) {
styles += `font-size: ${ensureUnit(wireframe.style?.fontSize)};`
if (isUnitLike(combinedStyles.fontSize)) {
styles += `font-size: ${ensureUnit(combinedStyles?.fontSize)};`
}
if (wireframe.style.fontFamily) {
styles += `font-family: ${wireframe.style.fontFamily};`
if (combinedStyles.fontFamily) {
styles += `font-family: ${combinedStyles.fontFamily};`
}
return styles
}
Expand Down Expand Up @@ -151,27 +167,33 @@ export function makeDeterminateProgressStyles(wireframe: wireframeProgress): str
/**
* normally use makeStylesString instead, but sometimes you need styles without any colors applied
* */
export function makeMinimalStyles(wireframe: wireframe): string {
export function makeMinimalStyles(wireframe: wireframe, styleOverride?: MobileStyles): string {
let styles = ''

styles += makePositionStyles(wireframe)
styles += makeLayoutStyles(wireframe)
styles += makeFontStyles(wireframe)
styles += makeLayoutStyles(wireframe, styleOverride)
styles += makeFontStyles(wireframe, styleOverride)

return styles
}

export function makeStylesString(wireframe: wireframe): string {
export function makeStylesString(wireframe: wireframe, styleOverride?: MobileStyles): string {
let styles = ''

if (wireframe.style?.color) {
styles += `color: ${wireframe.style.color};`
const combinedStyles = {
...wireframe.style,
...styleOverride,
}
if (wireframe.style?.backgroundColor) {
styles += `background-color: ${wireframe.style.backgroundColor};`

if (combinedStyles.color) {
styles += `color: ${combinedStyles.color};`
}
if (combinedStyles.backgroundColor) {
styles += `background-color: ${combinedStyles.backgroundColor};`
}
styles += makeBorderStyles(wireframe)
styles += makeMinimalStyles(wireframe)

styles += makeBorderStyles(wireframe, styleOverride)
styles += makeMinimalStyles(wireframe, styleOverride)

return styles
}
Expand Down
Loading
Loading