Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

feat: Commands panel enhancements (#5493)

Oleg Isonen564cc4538e77
diff --git a/apps/builder/app/builder/features/command-panel/groups/css-variables-group.tsx b/apps/builder/app/builder/features/command-panel/groups/css-variables-group.tsx
index 9bf6f3a2d2..4cc7d782b5 100644
--- a/apps/builder/app/builder/features/command-panel/groups/css-variables-group.tsx
+++ b/apps/builder/app/builder/features/command-panel/groups/css-variables-group.tsx
@@ -27,6 +27,7 @@ import {
focusCommandPanel,
} from "../command-state";
import type { BaseOption } from "../shared/types";
+import { formatUsageCount, getUsageSearchTerms } from "../shared/usage-utils";
import { getInstanceLabel } from "~/builder/shared/instance-label";
import { $instances } from "~/shared/nano-states";
import { $registeredComponentMetas } from "~/shared/nano-states";
@@ -58,17 +59,19 @@ export const $cssVariableOptions = computed(
const meta = metas.get(instance.component);
const instanceLabel = getInstanceLabel(instance, meta);
+ const usages = usedVariablesInInstances.get(property) ?? 0;
cssVariableOptions.push({
terms: [
"css variables",
property,
property.slice(2), // Include name without --
instanceLabel,
+ ...getUsageSearchTerms(usages),
],
type: "cssVariable",
property,
instanceId,
- usages: usedVariablesInInstances.get(property) ?? 0,
+ usages,
});
}
}
@@ -146,9 +149,7 @@ export const CssVariablesGroup = ({
<Text>
{property}{" "}
<Text as="span" color="moreSubtle">
- {usages === 0
- ? "unused"
- : `${usages} ${usages === 1 ? "usage" : "usages"}`}
+ {formatUsageCount(usages)}
</Text>
</Text>
<Text as="span" color="moreSubtle">
diff --git a/apps/builder/app/builder/features/command-panel/groups/data-variables-group.tsx b/apps/builder/app/builder/features/command-panel/groups/data-variables-group.tsx
index 5125c1c353..efc7daad52 100644
--- a/apps/builder/app/builder/features/command-panel/groups/data-variables-group.tsx
+++ b/apps/builder/app/builder/features/command-panel/groups/data-variables-group.tsx
@@ -25,6 +25,7 @@ import {
$usedVariablesInInstances,
} from "~/builder/shared/data-variable-utils";
import type { BaseOption } from "../shared/types";
+import { formatUsageCount, getUsageSearchTerms } from "../shared/usage-utils";
import { getInstanceLabel } from "~/builder/shared/instance-label";
import { $registeredComponentMetas } from "~/shared/nano-states";
@@ -63,6 +64,7 @@ export const $dataVariableOptions = computed(
"data",
dataSource.name,
instanceLabel,
+ ...getUsageSearchTerms(usages),
],
type: "dataVariable",
id: dataSource.id,
@@ -145,9 +147,7 @@ export const DataVariablesGroup = ({
<Text variant="labelsSentenceCase">
{option.name}{" "}
<Text as="span" color="moreSubtle">
- {option.usages === 0
- ? "unused"
- : `${option.usages} ${option.usages === 1 ? "usage" : "usages"}`}
+ {formatUsageCount(option.usages)}
</Text>
</Text>
<Text as="span" color="moreSubtle">
diff --git a/apps/builder/app/builder/features/command-panel/groups/tokens-group.tsx b/apps/builder/app/builder/features/command-panel/groups/tokens-group.tsx
index 6099ea3e7d..5223c771c2 100644
--- a/apps/builder/app/builder/features/command-panel/groups/tokens-group.tsx
+++ b/apps/builder/app/builder/features/command-panel/groups/tokens-group.tsx
@@ -25,6 +25,7 @@ import {
focusCommandPanel,
} from "../command-state";
import type { BaseOption } from "../shared/types";
+import { formatUsageCount, getUsageSearchTerms } from "../shared/usage-utils";
export type TokenOption = BaseOption & {
type: "token";
@@ -40,11 +41,12 @@ export const $tokenOptions = computed(
if (styleSource.type !== "token") {
continue;
}
+ const usages = styleSourceUsages.get(styleSource.id)?.size ?? 0;
tokenOptions.push({
- terms: ["tokens", styleSource.name],
+ terms: ["tokens", styleSource.name, ...getUsageSearchTerms(usages)],
type: "token",
token: styleSource,
- usages: styleSourceUsages.get(styleSource.id)?.size ?? 0,
+ usages,
});
}
return tokenOptions;
@@ -113,9 +115,7 @@ export const TokensGroup = ({ options }: { options: TokenOption[] }) => {
<Text variant="labelsTitleCase">
{token.name}{" "}
<Text as="span" color="moreSubtle">
- {usages === 0
- ? "unused"
- : `${usages} ${usages === 1 ? "usage" : "usages"}`}
+ {formatUsageCount(usages)}
</Text>
</Text>
</CommandItem>
diff --git a/apps/builder/app/builder/features/command-panel/shared/usage-utils.ts b/apps/builder/app/builder/features/command-panel/shared/usage-utils.ts
new file mode 100644
index 0000000000..9930ac1608
--- /dev/null
+++ b/apps/builder/app/builder/features/command-panel/shared/usage-utils.ts
@@ -0,0 +1,16 @@
+/**
+ * Formats usage count for display
+ */
+export const formatUsageCount = (usages: number): string => {
+ if (usages === 0) {
+ return "unused";
+ }
+ return `${usages} ${usages === 1 ? "usage" : "usages"}`;
+};
+
+/**
+ * Returns search terms for usage count
+ */
+export const getUsageSearchTerms = (usages: number): string[] => {
+ return usages === 0 ? ["unused"] : ["usage", "usages"];
+};