Skip to content
Merged
133 changes: 133 additions & 0 deletions apps/web/eslint-rules/form-label-scale.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* Every field label in the dashboard is on one scale: the lib's `large` (`text-h4`), as the script forms are.
*
* The lib's default field label is `text-h6`, kept small on purpose for the other Flamingo apps, and each control
* opts into the large scale per call site (`labelVariant="large"`, `<Label variant="large">`). Without a check every new
* form starts on the small default, which is how the policy and ticket forms ended up a size below the script forms
* next to them. The fix is mechanical, so the rule fixes it.
*
* - A lib field control with a `label` (`ScriptArguments`: `titleLabel`; `ImageUploader` / `FileUpload`:
* `fieldLabel`) needs `labelVariant="large"`.
* - A lib `<Label>` needs `variant="large"` unless it is a click surface (`variant="surface"`) or its `className`
* already states `text-h4`. A `className` stating another `text-h*` would win over the variant, so it is reported
* and left for a person.
*/

const LIB_SOURCE = /^@flamingo-stack\/openframe-frontend-core(\/|$)/;

/** The lib controls that draw their label through `FieldWrapper`, by the prop that carries the label text. */
const LIB_FIELD_CONTROLS = new Map([
['Autocomplete', 'label'],
['FieldWrapper', 'label'],
['FileUpload', 'fieldLabel'],
['ImageUploader', 'fieldLabel'],
['Input', 'label'],
['ScriptArguments', 'titleLabel'],
['SearchableSelect', 'label'],
['SelectTrigger', 'label'],
['Textarea', 'label'],
]);

const LARGE = 'large';
const OTHER_TEXT_SCALE = /(^|\s)text-h(?!4\b)\d\b/;

function attribute(node, name) {
return node.attributes.find(a => a.type === 'JSXAttribute' && a.name.name === name);
}

/** A string literal attribute's value (`a="x"` or `a={'x'}`), or `undefined` for anything computed. */
function literal(attr) {
if (!attr || !attr.value) return undefined;
if (attr.value.type === 'Literal') return attr.value.value;
const expression = attr.value.type === 'JSXExpressionContainer' ? attr.value.expression : null;
if (expression?.type === 'Literal') return expression.value;
if (expression?.type === 'TemplateLiteral' && expression.expressions.length === 0)
return expression.quasis[0].value.cooked;
return undefined;
}

/** @type {import('eslint').Rule.RuleModule} */
export const formLabelScale = {
meta: {
type: 'suggestion',
docs: { description: 'put every dashboard field label on the large (text-h4) scale' },
fixable: 'code',
schema: [],
messages: {
controlNeedsLarge:
'`{{name}}` draws its label on the lib default (text-h6); the dashboard labels fields on the large scale. Add labelVariant="large".',
labelNeedsLarge:
'This `Label` is on the lib default (text-h6); the dashboard labels fields on the large scale. Use variant="large".',
classNameOverridesScale:
"This `className` sets a text scale other than text-h4, which wins over the label's variant. Drop it so the label stays on the large scale.",
},
},

create(context) {
/** Local binding → the prop that carries its label text. */
const fieldControls = new Map();
/** Local bindings of the lib's `Label`. */
const labels = new Set();

return {
ImportDeclaration(node) {
const source = node.source.value;
for (const specifier of node.specifiers) {
if (specifier.type !== 'ImportSpecifier') continue;
const imported = specifier.imported.name;
if (!LIB_SOURCE.test(source)) continue;
if (imported === 'Label') labels.add(specifier.local.name);
const prop = LIB_FIELD_CONTROLS.get(imported);
if (prop) fieldControls.set(specifier.local.name, prop);
}
},

JSXOpeningElement(node) {
if (node.name.type !== 'JSXIdentifier') return;
const name = node.name.name;

const labelProp = fieldControls.get(name);
if (labelProp) {
const labelAttr = attribute(node, labelProp);
if (!labelAttr) return;
const variant = attribute(node, 'labelVariant');
if (variant) {
if (literal(variant) !== LARGE)
context.report({ node: variant, messageId: 'controlNeedsLarge', data: { name } });
return;
}
context.report({
node: labelAttr,
messageId: 'controlNeedsLarge',
data: { name },
fix: fixer => fixer.insertTextAfter(labelAttr, ` labelVariant="${LARGE}"`),
});
return;
}

if (!labels.has(name)) return;
const variant = attribute(node, 'variant');
const variantValue = literal(variant);
if (variantValue === 'surface') return;

const className = literal(attribute(node, 'className'));
if (typeof className === 'string' && OTHER_TEXT_SCALE.test(className)) {
context.report({ node: attribute(node, 'className'), messageId: 'classNameOverridesScale' });
return;
}
if (variantValue === LARGE) return;
if (typeof className === 'string' && /(^|\s)text-h4\b/.test(className)) return;

context.report({
node,
messageId: 'labelNeedsLarge',
fix: variant
? variant.value && variantValue !== undefined
? fixer => fixer.replaceText(variant.value, `"${LARGE}"`)
: null
: fixer => fixer.insertTextAfter(node.name, ` variant="${LARGE}"`),
});
},
};
},
};
12 changes: 12 additions & 0 deletions apps/web/eslint-rules/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { formLabelScale } from './form-label-scale.mjs';
import { reactHookFormNeedsNoMemo } from './react-hook-form-needs-no-memo.mjs';

/** The plugin object `eslint.config.mjs` registers under the `openframe/` prefix. */
const openframePlugin = {
rules: {
'form-label-scale': formLabelScale,
'react-hook-form-needs-no-memo': reactHookFormNeedsNoMemo,
},
};

export default openframePlugin;
5 changes: 0 additions & 5 deletions apps/web/eslint-rules/react-hook-form-needs-no-memo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,3 @@ export const reactHookFormNeedsNoMemo = {
};
},
};

/** The plugin object `eslint.config.mjs` registers under the `openframe/` prefix. */
const openframePlugin = { rules: { 'react-hook-form-needs-no-memo': reactHookFormNeedsNoMemo } };

export default openframePlugin;
14 changes: 13 additions & 1 deletion apps/web/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import relay from '@flamingo-stack/openframe-frontend-core/eslint-config/relay';
import tests from '@flamingo-stack/openframe-frontend-core/eslint-config/tests';
import { defineConfig } from 'eslint/config';

import openframeRules from './eslint-rules/react-hook-form-needs-no-memo.mjs';
import openframeRules from './eslint-rules/index.mjs';

/*
* The fast pass — no type-aware rules. This is what the editor loads (see
Expand Down Expand Up @@ -356,6 +356,18 @@ export default defineConfig([
rules: { 'openframe/react-hook-form-needs-no-memo': 'error' },
},

{
// One field-label scale across the dashboard: the lib's `large` (text-h4), as the script forms have it. The lib
// keeps text-h6 as its default for the other Flamingo apps, so every call site here opts in, and this rule (which
// fixes it) keeps a new form from starting on the small default. The auth pages are their own layout and keep the
// lib default.
name: 'openframe-frontend/form-label-scale',
files: ['src/**/*.tsx'],
ignores: ['src/app/(auth)/**'],
plugins: { openframe: openframeRules },
rules: { 'openframe/form-label-scale': 'error' },
},

{
// The two extra lint configs are `eslint.*.mjs`, not `*.config.*`, so they
// fall outside the shared devDependencies allowlist and every import they
Expand Down
8 changes: 4 additions & 4 deletions apps/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@codemirror/search": "6.7.1",
"@codemirror/state": "6.7.1",
"@codemirror/view": "6.43.9",
"@flamingo-stack/openframe-frontend-core": "0.0.815",
"@flamingo-stack/openframe-frontend-core": "https://pkg.pr.new/flamingo-stack/openframe-oss-lib/@flamingo-stack/openframe-frontend-core@6200129",
"@hookform/resolvers": "5.2.2",
"@lezer/highlight": "1.2.3",
"@tanstack/react-query": "5.90.21",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export const CustomerAiConfiguration = forwardRef<CustomerAiConfigurationHandle,
name="assistantName"
control={form.control}
render={({ field, fieldState }) => (
<Input {...field} label="Assistant Name" error={fieldState.error?.message} />
<Input {...field} label="Assistant Name" labelVariant="large" error={fieldState.error?.message} />
)}
/>

Expand All @@ -309,6 +309,7 @@ export const CustomerAiConfiguration = forwardRef<CustomerAiConfigurationHandle,
<div className="w-full shrink-0 content-md:w-[274px]">
<ImageUploader
fieldLabel="Assistant Avatar"
labelVariant="large"
value={avatarUrl}
onChange={handleAvatarChange}
onRemove={handleAvatarRemove}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function ContactInput({ control, index, field, disabled, showErrors }: ContactIn
<Input
type={FIELD_TYPES[field]}
label={CONTACT_FIELD_LABELS[field]}
labelVariant="large"
placeholder={PLACEHOLDERS[field]}
value={input.value}
onChange={input.onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const CustomerDeviceGuardrailsSettings = forwardRef<
value={selectedMode}
onValueChange={value => setChoice({ useDefault: false, mode: value as RemoteAccessMode })}
>
<SelectTrigger label="Default Remote Access Permission">
<SelectTrigger label="Default Remote Access Permission" labelVariant="large">
{/* Children override Radix's item mirror, so the closed trigger
reads the label straight from the mode, not from a mounted item. */}
<SelectValue>{REMOTE_ACCESS_MODE_META[selectedMode].label}</SelectValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function CustomerFormFields({ form, disabled, showErrors, logoSlot }: Cus
render={({ field, fieldState: { error } }) => (
<Input
label="Customer Name"
labelVariant="large"
placeholder="Customer Name"
value={field.value}
onChange={field.onChange}
Expand All @@ -63,6 +64,7 @@ export function CustomerFormFields({ form, disabled, showErrors, logoSlot }: Cus
render={({ field, fieldState: { error } }) => (
<Input
label="Website URL"
labelVariant="large"
placeholder="https://www.website.com"
value={field.value}
onChange={field.onChange}
Expand All @@ -84,6 +86,7 @@ export function CustomerFormFields({ form, disabled, showErrors, logoSlot }: Cus
render={({ field }) => (
<Textarea
label="Notes"
labelVariant="large"
rows={4}
placeholder="Your notes here..."
value={field.value}
Expand All @@ -105,6 +108,7 @@ export function CustomerFormFields({ form, disabled, showErrors, logoSlot }: Cus
render={({ field }) => (
<Input
label="Physical Address"
labelVariant="large"
placeholder={ADDRESS_PLACEHOLDER}
value={field.value}
onChange={event => {
Expand Down Expand Up @@ -147,6 +151,7 @@ export function CustomerFormFields({ form, disabled, showErrors, logoSlot }: Cus
render={({ field }) => (
<Input
label="Mailing Address"
labelVariant="large"
placeholder={ADDRESS_PLACEHOLDER}
value={field.value}
onChange={field.onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ export function RemoteSettingsModal({
<div className="grid grid-cols-2 gap-4">
{/* Quality Selector */}
<div className="space-y-2">
<Label htmlFor="quality">Quality</Label>
<Label variant="large" htmlFor="quality">
Quality
</Label>
<Select
value={String(settings.quality)}
onValueChange={value => setSettings({ ...settings, quality: Number(value) })}
Expand All @@ -156,7 +158,9 @@ export function RemoteSettingsModal({

{/* Scaling Selector */}
<div className="space-y-2">
<Label htmlFor="scaling">Scaling</Label>
<Label variant="large" htmlFor="scaling">
Scaling
</Label>
<Select
value={String(settings.scaling)}
onValueChange={value => setSettings({ ...settings, scaling: Number(value) })}
Expand All @@ -179,7 +183,9 @@ export function RemoteSettingsModal({

{/* Frame Rate */}
<div className="space-y-2">
<Label htmlFor="framerate">Frame Rate</Label>
<Label variant="large" htmlFor="framerate">
Frame Rate
</Label>
<Select
value={settings.frameRate}
onValueChange={value => setSettings({ ...settings, frameRate: value as RemoteSettingsConfig['frameRate'] })}
Expand All @@ -205,7 +211,7 @@ export function RemoteSettingsModal({
onCheckedChange={checked => setSettings({ ...settings, invertScrollDirection: !!checked })}
/>
<div className="flex-1">
<Label htmlFor="invert-scroll" className="cursor-pointer">
<Label variant="large" htmlFor="invert-scroll" className="cursor-pointer">
Invert Scroll Direction
</Label>
<p className="text-ods-text-secondary text-h6">Reverse mouse wheel scroll direction</p>
Expand All @@ -220,7 +226,7 @@ export function RemoteSettingsModal({
onCheckedChange={checked => setSettings({ ...settings, swapMouseButtons: !!checked })}
/>
<div className="flex-1">
<Label htmlFor="swap-mouse" className="cursor-pointer">
<Label variant="large" htmlFor="swap-mouse" className="cursor-pointer">
Swap Mouse Buttons
</Label>
<p className="text-ods-text-secondary text-h6">Reverse left and right mouse button functions</p>
Expand All @@ -234,7 +240,7 @@ export function RemoteSettingsModal({
onCheckedChange={checked => setSettings({ ...settings, useRemoteKeyboardMap: !!checked })}
/>
<div className="flex-1">
<Label htmlFor="keyboard-map" className="cursor-pointer">
<Label variant="large" htmlFor="keyboard-map" className="cursor-pointer">
Use Remote Keyboard Map
</Label>
<p className="text-ods-text-secondary text-h6">Use the remote device's keyboard layout</p>
Expand All @@ -248,7 +254,7 @@ export function RemoteSettingsModal({
onCheckedChange={checked => onAutoHideToolbarChange(!!checked)}
/>
<div className="flex-1">
<Label htmlFor="auto-hide-toolbar" className="cursor-pointer">
<Label variant="large" htmlFor="auto-hide-toolbar" className="cursor-pointer">
Auto-hide Toolbar
</Label>
<p className="text-ods-text-secondary text-h6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ export function ShortcutsSettingsModal({ open, onOpenChange, shortcuts, onSave }
</div>
<div className="flex items-end gap-[var(--spacing-system-xs)]">
<div className="flex min-w-0 flex-1 flex-col gap-[var(--spacing-system-xxs)]">
<Label htmlFor="shortcut-key">Key</Label>
<Label variant="large" htmlFor="shortcut-key">
Key
</Label>
<Input
id="shortcut-key"
value={keyInput}
Expand Down
Loading
Loading