Skip to content

Commit

Permalink
fix(frontend): improve default id of the components of the topbar (#4222
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fatonramadani authored Aug 9, 2024
1 parent c0853ea commit 7115a35
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
17 changes: 10 additions & 7 deletions frontend/src/lib/components/apps/editor/appUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,11 @@ export function createNewGridItem(
data: AppComponent,
columns?: Record<number, any>,
initialPosition: { x: number; y: number } = { x: 0, y: 0 },
recOverride?: Record<number, Size>
recOverride?: Record<number, Size>,
fixed?: boolean
): GridItem {
const newComponent = {
fixed: false,
fixed: fixed ?? false,
x: initialPosition.x,
y: initialPosition.y,
fullHeight: false
Expand Down Expand Up @@ -389,7 +390,9 @@ export function insertNewGridItem(
columns?: Record<string, any>,
keepId?: string,
initialPosition: { x: number; y: number } = { x: 0, y: 0 },
recOverride?: Record<number, Size>
recOverride?: Record<number, Size>,
keepSubgrids?: boolean,
fixed?: boolean
): string {
const id = keepId ?? getNextGridItemId(app)

Expand All @@ -404,7 +407,7 @@ export function insertNewGridItem(
}

// We only want to set subgrids when we are not moving
if (!keepId) {
if (!keepId || keepSubgrids) {
for (let i = 0; i < (data.numberOfSubgrids ?? 0); i++) {
app.subgrids[`${id}-${i}`] = []
}
Expand Down Expand Up @@ -436,7 +439,7 @@ export function insertNewGridItem(

let grid = focusedGrid ? app.subgrids[key!] : app.grid

const newItem = createNewGridItem(grid, id, data, columns, initialPosition, recOverride)
const newItem = createNewGridItem(grid, id, data, columns, initialPosition, recOverride, fixed)
grid.push(newItem)
return id
}
Expand Down Expand Up @@ -1094,7 +1097,7 @@ export function setUpTopBarComponentContent(id: string, app: App) {
subGridIndex: 0
},
undefined,
undefined,
'title',
undefined,
{
3: {
Expand All @@ -1118,7 +1121,7 @@ export function setUpTopBarComponentContent(id: string, app: App) {
subGridIndex: 0
},
undefined,
undefined,
'recomputeall',
undefined,
{
3: {
Expand Down
32 changes: 16 additions & 16 deletions frontend/src/lib/components/details/createAppFromScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export function createAppFromScript(path: string, schema: Record<string, any> |
},
actions: [],
numberOfSubgrids: 1,
id: 'g'
id: 'topbar'
},
id: 'g'
id: 'topbar'
}
],
fullscreen: false,
Expand Down Expand Up @@ -410,7 +410,7 @@ export function createAppFromScript(path: string, schema: Record<string, any> |
id: 'f'
}
],
'g-0': [
'topbar-0': [
{
'3': {
fixed: false,
Expand Down Expand Up @@ -481,9 +481,9 @@ export function createAppFromScript(path: string, schema: Record<string, any> |
actions: [],
horizontalAlignment: 'left',
verticalAlignment: 'center',
id: 'h'
id: 'title'
},
id: 'h'
id: 'title'
},
{
'3': {
Expand Down Expand Up @@ -515,9 +515,9 @@ export function createAppFromScript(path: string, schema: Record<string, any> |
menuItems: [],
horizontalAlignment: 'right',
verticalAlignment: 'center',
id: 'i'
id: 'recomputeall'
},
id: 'i'
id: 'recomputeall'
}
]
}
Expand Down Expand Up @@ -592,15 +592,15 @@ export function createAppFromFlow(path: string, schema: Record<string, any> | un
},
{
'3': {
fixed: false,
fixed: true,
x: 0,
y: 8,
fullHeight: false,
w: 6,
h: 2
},
'12': {
fixed: false,
fixed: true,
x: 0,
y: 0,
fullHeight: false,
Expand All @@ -618,9 +618,9 @@ export function createAppFromFlow(path: string, schema: Record<string, any> | un
},
actions: [],
numberOfSubgrids: 1,
id: 'g'
id: 'topbar'
},
id: 'g'
id: 'topbar'
}
],
fullscreen: false,
Expand Down Expand Up @@ -973,7 +973,7 @@ export function createAppFromFlow(path: string, schema: Record<string, any> | un
id: 'f'
}
],
'g-0': [
'topbar-0': [
{
'3': {
fixed: false,
Expand Down Expand Up @@ -1044,9 +1044,9 @@ export function createAppFromFlow(path: string, schema: Record<string, any> | un
actions: [],
horizontalAlignment: 'left',
verticalAlignment: 'center',
id: 'h'
id: 'title'
},
id: 'h'
id: 'title'
},
{
'3': {
Expand Down Expand Up @@ -1078,9 +1078,9 @@ export function createAppFromFlow(path: string, schema: Record<string, any> | un
menuItems: [],
horizontalAlignment: 'right',
verticalAlignment: 'center',
id: 'i'
id: 'recomputeall'
},
id: 'i'
id: 'recomputeall'
}
]
}
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/routes/(root)/(logged)/apps/add/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@
}) as (id: string) => AppComponent,
undefined,
undefined,
undefined,
'topbar',
{ x: 0, y: 0 },
{
3: processDimension(preset.dims, 3),
12: processDimension(preset.dims, 12)
}
},
true,
true
)
setUpTopBarComponentContent(id, value)
Expand Down

0 comments on commit 7115a35

Please sign in to comment.