Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/browser-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bucketco/browser-sdk",
"version": "3.3.1",
"version": "3.3.2",
"packageManager": "yarn@4.1.1",
"license": "MIT",
"repository": {
Expand Down
6 changes: 6 additions & 0 deletions packages/browser-sdk/src/toolbar/Features.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
}
}

.feature-empty-cell {
width: 100%;
color: var(--gray500);
padding: 6px 0;
}

.feature-name-cell {
white-space: nowrap;
overflow: hidden;
Expand Down
33 changes: 29 additions & 4 deletions packages/browser-sdk/src/toolbar/Features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,42 @@ export function FeaturesTable({
isOpen: boolean;
setIsEnabledOverride: (key: string, isEnabled: boolean | null) => void;
}) {
const hasFeatures = features.length > 0;
const hasShownFeatures = features.some((feature) =>
feature.key
.toLocaleLowerCase()
.includes(searchQuery?.toLocaleLowerCase() ?? ""),
);

// List features that match the search query first then alphabetically
const searchedFeatures =
searchQuery === null
? features
: [...features].sort((a, _b) => (a.key.includes(searchQuery) ? -1 : 1));
: [...features].sort((a, b) => {
const aMatches = a.key.includes(searchQuery);
const bMatches = b.key.includes(searchQuery);

// If both match or both don't match, sort alphabetically
if (aMatches === bMatches) {
return a.key.localeCompare(b.key);
}

// Otherwise, matching features come first
return aMatches ? -1 : 1;
});

if (searchedFeatures.length === 0) {
return <div style={{ color: "var(--gray500)" }}>No features found</div>;
}
return (
<table class="features-table" style={{ "--n": searchedFeatures.length }}>
<tbody>
{(!hasFeatures || !hasShownFeatures) && (
<tr>
<td class="feature-empty-cell" colSpan={3}>
No features{" "}
{!hasShownFeatures ? `matching "${searchQuery} "` : ""}
found
</td>
</tr>
)}
{searchedFeatures.map((feature, index) => (
<FeatureRow
key={feature.key}
Expand Down
4 changes: 3 additions & 1 deletion packages/browser-sdk/src/toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function Toolbar({
position: ToolbarPosition;
}) {
const toggleToolbarRef = useRef<HTMLDivElement>(null);
const dialogContentRef = useRef<HTMLDivElement>(null);
const [features, setFeatures] = useState<Feature[]>([]);

const updateFeatures = useCallback(() => {
Expand Down Expand Up @@ -67,6 +68,7 @@ export default function Toolbar({
const [search, setSearch] = useState<string | null>(null);
const onSearch = (val: string) => {
setSearch(val === "" ? null : val);
dialogContentRef.current?.scrollTo({ top: 0 });
};

const sortedFeatures = [...features].sort((a, b) =>
Expand Down Expand Up @@ -102,7 +104,7 @@ export default function Toolbar({
<DialogHeader>
<FeatureSearch onSearch={onSearch} />
</DialogHeader>
<DialogContent>
<DialogContent innerRef={dialogContentRef}>
<FeaturesTable
appBaseUrl={appBaseUrl}
features={sortedFeatures}
Expand Down
16 changes: 14 additions & 2 deletions packages/browser-sdk/src/ui/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,28 @@ function DialogArrow({

export function DialogHeader({
children,
innerRef,
}: {
children: preact.ComponentChildren;
innerRef?: Ref<HTMLElement>;
}) {
return <header class="dialog-header">{children}</header>;
return (
<header ref={innerRef} class="dialog-header">
{children}
</header>
);
}

export function DialogContent({
children,
innerRef,
}: {
children: preact.ComponentChildren;
innerRef?: Ref<HTMLDivElement>;
}) {
return <div class="dialog-content">{children}</div>;
return (
<div ref={innerRef} class="dialog-content">
{children}
</div>
);
}
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,19 @@ __metadata:
languageName: node
linkType: hard

"@bucketco/browser-sdk@npm:3.3.1, @bucketco/browser-sdk@workspace:packages/browser-sdk":
"@bucketco/browser-sdk@npm:3.3.1":
version: 3.3.1
resolution: "@bucketco/browser-sdk@npm:3.3.1"
dependencies:
"@floating-ui/dom": "npm:^1.6.8"
canonical-json: "npm:^0.0.4"
js-cookie: "npm:^3.0.5"
preact: "npm:^10.22.1"
checksum: 10c0/30bd1fa0f084c7eee0a22f917bfe488667243013711787bc36c9befa0d3aa27a4aed6f0576416a098b3d3d64ff1cf873587022d4d9c07198e11d4f81f31380de
languageName: node
linkType: hard

"@bucketco/browser-sdk@workspace:packages/browser-sdk":
version: 0.0.0-use.local
resolution: "@bucketco/browser-sdk@workspace:packages/browser-sdk"
dependencies:
Expand Down