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

Feature flags #1066

Merged
merged 1 commit into from
May 13, 2022
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
1 change: 1 addition & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ENV NEXTAUTH_URL $NEXTAUTH_URL
ENV NEXT_PUBLIC_URL $NEXT_PUBLIC_URL
ENV NEXT_PUBLIC_MAPBOX_API_TOKEN $NEXT_PUBLIC_MAPBOX_API_TOKEN
ENV NEXT_PUBLIC_API_URL $NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_FEATURE_FLAGS $NEXT_PUBLIC_FEATURE_FLAGS

RUN addgroup $USER && adduser -s /bin/bash -D -G $USER $USER

Expand Down
18 changes: 11 additions & 7 deletions app/components/features/selected-item/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useCallback, useMemo } from 'react';

import cx from 'classnames';

import { useFeatureFlags } from 'hooks/feature-flags';

import Button from 'components/button';
import Checkbox from 'components/forms/checkbox';
import Select from 'components/forms/select';
Expand Down Expand Up @@ -55,7 +57,6 @@ export const Item: React.FC<ItemProps> = ({
id,
name,
className,
description,
type,

splitSelected,
Expand All @@ -74,6 +75,11 @@ export const Item: React.FC<ItemProps> = ({
onMouseEnter,
onMouseLeave,
}: ItemProps) => {
const {
split,
strat,
} = useFeatureFlags();

// EVENTS
const onSplitChanged = useCallback(
(selected) => {
Expand Down Expand Up @@ -123,13 +129,13 @@ export const Item: React.FC<ItemProps> = ({
>
<header
className={cx({
'px-4 pt-2 pb-4 border-l-4': true,
'px-4 py-2 border-l-4': true,
'border-green-300': type === 'bioregional',
'border-yellow-300': type === 'species',
})}
>
<div className="flex items-start justify-between">
<h2 className="mt-1 text-sm font-heading">{name}</h2>
<h2 className="text-sm font-heading">{name}</h2>

{editable && (
<Button
Expand All @@ -141,11 +147,9 @@ export const Item: React.FC<ItemProps> = ({
Remove
</Button>
)}

</div>
<div className="mt-2 text-sm opacity-50 clamp-2">{description}</div>

{type === 'bioregional' && (
{type === 'bioregional' && split && (
<div>
<div className="flex items-center mt-3 space-x-2 tracking-wide font-heading">
<Icon icon={SPLIT_SVG} className="w-5 h-5 text-green-300" />
Expand Down Expand Up @@ -190,7 +194,7 @@ export const Item: React.FC<ItemProps> = ({
</div>
)}

{type === 'species' && editable && (
{type === 'species' && editable && strat && (
<div>
<div className="flex items-center mt-3 space-x-2 tracking-wide font-heading">
<Icon icon={INTERSECT_SVG} className="w-5 h-5 text-yellow-300" />
Expand Down
18 changes: 18 additions & 0 deletions app/hooks/feature-flags/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
useMemo,
} from 'react';

export function useFeatureFlags(): Record<string, boolean> {
const flags = useMemo(() => {
const FLAGS = (process.env.NEXT_PUBLIC_FEATURE_FLAGS || '').split(',');

return FLAGS.reduce((acc, flag) => {
return {
...acc,
[flag]: true,
};
}, {});
}, []);

return flags;
}