Skip to content

Commit

Permalink
add ability to highlight multiple settings
Browse files Browse the repository at this point in the history
  • Loading branch information
PClmnt committed Jan 15, 2025
1 parent 5c54c43 commit 8763f52
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@
let highlightType
$: highlightedProp = $builderStore.highlightedSetting
$: highlightedSettings = $builderStore.highlightedSettings
$: allBindings = getAllBindings(bindings, componentBindings, nested)
$: safeValue = getSafeValue(value, defaultValue, allBindings)
$: replaceBindings = val => readableToRuntimeBinding(allBindings, val)
$: if (!Array.isArray(value)) {
highlightType =
highlightedProp?.key === key ? `highlighted-${highlightedProp?.type}` : ""
const highlightedSetting = highlightedSettings?.find(
setting => setting.key === key
)
highlightType = highlightedSetting
? `highlighted-${highlightedSetting.type}`
: ""
}
const getAllBindings = (bindings, componentBindings, nested) => {
Expand Down Expand Up @@ -77,7 +81,7 @@
}
onDestroy(() => {
if (highlightedProp) {
if (highlightedSettings) {
builderStore.highlightSetting(null)
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { onDestroy } from "svelte"
import { ActionButton, Modal, ModalContent, Combobox } from "@budibase/bbui"
import { getAllStateVariables } from "@/dataBinding"
import {
Expand All @@ -13,7 +14,7 @@
} from "@budibase/string-templates"
let modal: Modal
let selectedKey = ""
let selectedKey: string | null = null
let componentsUsingState: Array<{
id: string
name: string
Expand Down Expand Up @@ -75,7 +76,9 @@
function handleKeySelect(event: CustomEvent) {
selectedKey = event.detail
if (!selectedKey) {
throw new Error("No state key selected")
}
if ($selectedScreen?.props) {
componentsUsingState = findComponentsUsingState(
$selectedScreen.props,
Expand All @@ -90,20 +93,29 @@
settings: string[]
}) {
componentStore.select(component.id)
// Delay highlighting until after component selection and re-render
// Delay highlighting until after component selection and re-render (i know this is disgusting)
setTimeout(() => {
component.settings.forEach(setting => {
builderStore.highlightSetting(setting)
})
}, 100)
}
onDestroy(() => {
builderStore.highlightSetting(undefined)
})
</script>

<ActionButton on:click={modal.show}>State</ActionButton>

<Modal bind:this={modal}>
<ModalContent title="State" showConfirmButton={false} cancelText="Close">
<Combobox options={keyOptions} on:change={handleKeySelect} />
<Combobox
value={selectedKey}
options={keyOptions}
on:change={handleKeySelect}
/>
{#if componentsUsingState.length > 0}
<div class="components-list">
<h4>Components using this state:</h4>
Expand Down
33 changes: 26 additions & 7 deletions packages/builder/src/stores/builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { App } from "@budibase/types"

interface BuilderState {
previousTopNavPath: Record<string, string>
highlightedSetting: {
highlightedSettings: Array<{
key: string
type: "info" | string
} | null
}> | null
propertyFocus: string | null
builderSidePanel: boolean
onboarding: boolean
Expand All @@ -24,7 +24,7 @@ interface BuilderState {

export const INITIAL_BUILDER_STATE: BuilderState = {
previousTopNavPath: {},
highlightedSetting: null,
highlightedSettings: null,
propertyFocus: null,
builderSidePanel: false,
onboarding: false,
Expand Down Expand Up @@ -76,10 +76,29 @@ export class BuilderStore extends BudiStore<BuilderState> {
}

highlightSetting(key?: string, type?: string) {
this.update(state => ({
...state,
highlightedSetting: key ? { key, type: type || "info" } : null,
}))
this.update(state => {
if (!key) {
return {
...state,
highlightedSettings: null,
}
}

const currentSettings = state.highlightedSettings || []

const settingExists = currentSettings.some(setting => setting.key === key)
if (!settingExists) {
return {
...state,
highlightedSettings: [
...currentSettings,
{ key, type: type || "info" },
],
}
}

return state
})
}

propertyFocus(key: string | null) {
Expand Down

0 comments on commit 8763f52

Please sign in to comment.