Compare commits

...

2 Commits

Author SHA1 Message Date
Marcus Andersson
8e0bd2527c wip 2025-12-19 16:21:17 +01:00
Marcus Andersson
5e3baf593d fixed switch variable form when in new dashboard inline layout. 2025-12-19 16:05:39 +01:00
3 changed files with 29 additions and 14 deletions

View File

@@ -17,22 +17,29 @@ export function DashboardLinksControls({ links, dashboard }: Props) {
sceneGraph.getTimeRange(dashboard).useState(); sceneGraph.getTimeRange(dashboard).useState();
const uid = dashboard.state.uid; const uid = dashboard.state.uid;
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
const linksToDisplay = excludeControlMenuLinks(links);
if (!links || !uid || links.length === 0) { if (!uid || linksToDisplay.length === 0) {
return null; return null;
} }
return ( return (
<div className={styles.linksContainer}> <div className={styles.linksContainer}>
{links {linksToDisplay.map((link: DashboardLink, index: number) => (
.filter((link) => link.placement === undefined) <DashboardLinkRenderer link={link} dashboardUID={uid} key={`${link.title}-$${index}`} />
.map((link: DashboardLink, index: number) => ( ))}
<DashboardLinkRenderer link={link} dashboardUID={uid} key={`${link.title}-$${index}`} />
))}
</div> </div>
); );
} }
function excludeControlMenuLinks(links: DashboardLink[]): DashboardLink[] {
if (!links || links.length === 0) {
return [];
}
return links.filter((link) => link.placement === undefined);
}
function getStyles(theme: GrafanaTheme2) { function getStyles(theme: GrafanaTheme2) {
return { return {
linksContainer: css({ linksContainer: css({

View File

@@ -11,6 +11,7 @@ interface SwitchVariableFormProps {
disabledValue: string; disabledValue: string;
onEnabledValueChange: (value: string) => void; onEnabledValueChange: (value: string) => void;
onDisabledValueChange: (value: string) => void; onDisabledValueChange: (value: string) => void;
inline?: boolean;
} }
const VALUE_PAIR_OPTIONS: Array<ComboboxOption<string>> = [ const VALUE_PAIR_OPTIONS: Array<ComboboxOption<string>> = [
@@ -25,6 +26,7 @@ export function SwitchVariableForm({
disabledValue, disabledValue,
onEnabledValueChange, onEnabledValueChange,
onDisabledValueChange, onDisabledValueChange,
inline,
}: SwitchVariableFormProps) { }: SwitchVariableFormProps) {
const currentValuePairType = getCurrentValuePairType(enabledValue, disabledValue); const currentValuePairType = getCurrentValuePairType(enabledValue, disabledValue);
const [isCustomValuePairType, setIsCustomValuePairType] = useState(currentValuePairType === 'custom'); const [isCustomValuePairType, setIsCustomValuePairType] = useState(currentValuePairType === 'custom');
@@ -87,11 +89,15 @@ export function SwitchVariableForm({
} }
}; };
const fieldWidth = inline ? undefined : 30;
return ( return (
<> <>
<VariableLegend> {!inline && (
<Trans i18nKey="dashboard-scene.switch-variable-form.switch-options">Switch options</Trans> <VariableLegend>
</VariableLegend> <Trans i18nKey="dashboard-scene.switch-variable-form.switch-options">Switch options</Trans>
</VariableLegend>
)}
<Stack gap={2} direction="column"> <Stack gap={2} direction="column">
<Field <Field
@@ -103,7 +109,7 @@ export function SwitchVariableForm({
)} )}
> >
<Combobox <Combobox
width={40} width={fieldWidth}
value={isCustomValuePairType ? 'custom' : currentValuePairType} value={isCustomValuePairType ? 'custom' : currentValuePairType}
options={VALUE_PAIR_OPTIONS} options={VALUE_PAIR_OPTIONS}
onChange={onValuePairTypeChange} onChange={onValuePairTypeChange}
@@ -125,7 +131,7 @@ export function SwitchVariableForm({
invalid={enabledValueInvalid} invalid={enabledValueInvalid}
> >
<Input <Input
width={40} width={fieldWidth}
defaultValue={enabledValue} defaultValue={enabledValue}
onChange={(event) => { onChange={(event) => {
handleEnabledValueChange(event.currentTarget.value); handleEnabledValueChange(event.currentTarget.value);
@@ -149,7 +155,7 @@ export function SwitchVariableForm({
invalid={disabledValueInvalid} invalid={disabledValueInvalid}
> >
<Input <Input
width={40} width={fieldWidth}
defaultValue={disabledValue} defaultValue={disabledValue}
onChange={(event) => handleDisabledValueChange(event.currentTarget.value)} onChange={(event) => handleDisabledValueChange(event.currentTarget.value)}
placeholder={t( placeholder={t(

View File

@@ -5,9 +5,10 @@ import { SwitchVariableForm } from '../components/SwitchVariableForm';
interface SwitchVariableEditorProps { interface SwitchVariableEditorProps {
variable: SwitchVariable; variable: SwitchVariable;
inline?: boolean;
} }
export function SwitchVariableEditor({ variable }: SwitchVariableEditorProps) { export function SwitchVariableEditor({ variable, inline = false }: SwitchVariableEditorProps) {
const { value, enabledValue, disabledValue } = variable.useState(); const { value, enabledValue, disabledValue } = variable.useState();
const onEnabledValueChange = (newEnabledValue: string) => { const onEnabledValueChange = (newEnabledValue: string) => {
@@ -36,6 +37,7 @@ export function SwitchVariableEditor({ variable }: SwitchVariableEditorProps) {
disabledValue={disabledValue} disabledValue={disabledValue}
onEnabledValueChange={onEnabledValueChange} onEnabledValueChange={onEnabledValueChange}
onDisabledValueChange={onDisabledValueChange} onDisabledValueChange={onDisabledValueChange}
inline={inline}
/> />
); );
} }
@@ -49,7 +51,7 @@ export function getSwitchVariableOptions(variable: SceneVariable): OptionsPaneIt
return [ return [
new OptionsPaneItemDescriptor({ new OptionsPaneItemDescriptor({
id: `variable-${variable.state.name}-value`, id: `variable-${variable.state.name}-value`,
render: () => <SwitchVariableEditor variable={variable} />, render: () => <SwitchVariableEditor variable={variable} inline={true} />,
}), }),
]; ];
} }