Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: launchdarkly not syntax #1614

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions packages/ui/app/src/atoms/launchdarkly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@ const SET_LAUNCH_DARKLY_INFO_ATOM = atom(undefined, async (get, set, info: Launc
});

// TODO: support non-boolean flags
export const useLaunchDarklyFlag = (flag: string): boolean => {
export const useLaunchDarklyFlag = (flag: string, not = false): boolean => {
useInitLaunchDarklyClient();

const client = useAtomValue(LD_CLIENT_ATOM);

// TODO: bootstrap the flag value from the server, and/or local storage
const getFlagEnabled = useCallback(() => {
if (!client) {
return false;
return not;
}
// force the flag to be a boolean:
return !!client.variation(flag, false);
}, [client, flag]);
const isTrue = !!client.variation(flag, false);
return not ? !isTrue : isTrue;
}, [client, flag, not]);

const [enabled, setEnabled] = useState(getFlagEnabled);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ import { LinkPreloadApiRoute } from "../../../components/LinkPreload";

export interface LaunchDarklyProps {
flag: string;
not?: boolean;
}

export function LaunchDarkly({ flag, children }: PropsWithChildren<LaunchDarklyProps>): ReactNode {
const ldClient = useLaunchDarklyFlag(flag);

if (!ldClient) {
return null;
}
export function LaunchDarkly({ not = false, flag, children }: PropsWithChildren<LaunchDarklyProps>): ReactNode {
const show = useLaunchDarklyFlag(flag, not);

return (
<>
<LinkPreloadApiRoute href="/api/fern-docs/integrations/launchdarkly" />
{children}
{show && children}
</>
);
}
Loading