Skip to content

Commit 36bd05a

Browse files
committed
No more conditional rendering based on FFs
1 parent 94f6fd5 commit 36bd05a

File tree

7 files changed

+40
-52
lines changed

7 files changed

+40
-52
lines changed

src/button/button-contributions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export interface ButtonContributionParams {
108108
manipulations?: { element: string; removeClassName?: string; addClassName?: string; style?: Partial<CSSStyleDeclaration>, setAttribute?: { name: string, value: string }[] }[];
109109

110110
/**
111-
* A function that can be used to transform the URL that should be opened when the Gitpod button is clicked.
111+
* A function that can be used to transform the URL that should be opened when the Ona button is clicked.
112112
* @returns The transformed URL.
113113
*/
114114
urlTransformer?: (originalURL: string) => string;

src/button/button.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
max-width: fit-content;
4141
}
4242

43-
.gitpod-button {
43+
.ona-button {
4444
position: "relative";
4545
display: "inline-block";
4646
}

src/button/button.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { useStorage } from "@plasmohq/storage/hook";
22
import classNames from "classnames";
33
import { useEffect, useMemo, useRef, useState } from "react";
44
import { useHotkeys } from "react-hotkeys-hook";
5-
import Logo from "react:./logo-mark.svg";
65
import { DEFAULT_ONA_ENDPOINT, EVENT_CURRENT_URL_CHANGED } from "~constants";
7-
import { FeatureFlags, useFlag } from "~hooks/use-configcat";
86
import { OnaLettermark } from "~icons/OnaLettermark";
97
import { STORAGE_KEY_ADDRESS, STORAGE_KEY_ALWAYS_OPTIONS, STORAGE_KEY_NEW_TAB } from "~storage";
108
import { isOnaEndpoint } from "~utils/parse-endpoint";
@@ -22,7 +20,6 @@ export const OnaButton = ({ application, additionalClassNames, urlTransformer }:
2220
const [disableAutostart] = useStorage<boolean>(STORAGE_KEY_ALWAYS_OPTIONS, false);
2321
const [showDropdown, setShowDropdown] = useState(false);
2422
const [currentHref, setCurrentHref] = useState(window.location.href);
25-
const { value: isOnaEnabled } = useFlag(FeatureFlags.ONA_ENABLED, false);
2623

2724
const linkRef = useRef<HTMLAnchorElement | null>(null);
2825

@@ -88,9 +85,9 @@ export const OnaButton = ({ application, additionalClassNames, urlTransformer }:
8885

8986
return (
9087
<div
91-
id="gitpod-btn-nav"
92-
title={`Open with ${isOnaEnabled ? "Ona" : "Gitpod"}`}
93-
className={classNames("gitpod-button", application, ...(additionalClassNames ?? []))}
88+
id="ona-btn-nav"
89+
title={`Open with "Ona"`}
90+
className={classNames("ona-button", application, ...(additionalClassNames ?? []))}
9491
>
9592
<div className={classNames("button")}>
9693
<a
@@ -101,10 +98,7 @@ export const OnaButton = ({ application, additionalClassNames, urlTransformer }:
10198
ref={linkRef}
10299
>
103100
<span className={classNames("action-label")}>
104-
{isOnaEnabled ?
105-
<OnaLettermark className={classNames("action-logo")} width={14} height={14} /> :
106-
<Logo className={classNames("action-logo")} width={14} height={14} />
107-
}
101+
<OnaLettermark className={classNames("action-logo")} width={14} height={14} />
108102
{actions[0].label}
109103
</span>
110104
</a>

src/components/forms/Button.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,14 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
3333
},
3434
ref: ForwardedRef<HTMLButtonElement>,
3535
) => {
36-
const { value: isOnaEnabled } = useFlag(FeatureFlags.ONA_ENABLED, false);
37-
3836
return (
3937
<button
4038
type={htmlType}
4139
className={classNames(
4240
"inline-flex items-center whitespace-nowrap rounded-lg text-sm justify-center font-medium transition-colors focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 h-9 px-4 py-2",
4341
type === "primary" ?
4442
[
45-
"bg-gray-900 hover:bg-gray-800",
46-
"text-gray-50 dark:text-gray-900",
47-
{ "bg-[#1F1F1F] hover:bg-[#737373] dark:bg-[#FAFAFA] dark:hover:bg-[#A3A3A3]": isOnaEnabled },
43+
"text-gray-50 dark:text-gray-900 bg-[#1F1F1F] hover:bg-[#737373] dark:bg-[#FAFAFA] dark:hover:bg-[#A3A3A3]",
4844
]
4945
: null,
5046
type === "secondary" ?

src/components/forms/TextInputField.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import classNames from "classnames";
22
import React, { memo, useCallback, useId, type PropsWithChildren, type ReactNode } from "react";
3-
import { FeatureFlags, useFlag } from "~hooks/use-configcat";
43
import { InputField } from "./InputField";
54

65
type TextInputFieldTypes = "text" | "password" | "email" | "url";
@@ -91,8 +90,6 @@ export const TextInput = memo(
9190
onChange,
9291
onBlur,
9392
}: PropsWithChildren<TextInputProps>) => {
94-
const { value: isOnaEnabled } = useFlag(FeatureFlags.ONA_ENABLED, false);
95-
9693
const handleChange = useCallback(
9794
(e: React.ChangeEvent<HTMLInputElement>) => {
9895
onChange && onChange(e.target.value);
@@ -107,11 +104,11 @@ export const TextInput = memo(
107104
id={id}
108105
className={classNames(
109106
"w-full text-base",
110-
"block text-gray-600 dark:text-gray-400 dark:bg-gray-800 bg-white rounded-lg border border-gray-300 dark:border-gray-500 focus:border-gray-400 dark:focus:border-gray-400 focus:ring-0",
107+
"block text-gray-600 dark:text-gray-400 rounded-lg border border-gray-300 dark:border-gray-500 focus:border-gray-400 dark:focus:border-gray-400 focus:ring-0",
111108
"py-2 px-3",
112109
"placeholder:text-gray-400 dark:placeholder:text-gray-500",
113110
"disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:border disabled:border-gray-200 dark:disabled:border-gray-600 disabled:text-gray-400 dark:disabled:text-gray-500",
114-
{ "bg-white focus-visible:ring-2 focus-visible:ring-gray-400 dark:bg-[#262626]": isOnaEnabled },
111+
"bg-white focus-visible:ring-2 focus-visible:ring-gray-400 dark:bg-[#262626]",
115112
className,
116113
)}
117114
value={value}

src/popup.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import { CheckboxInputField } from "~components/forms/CheckboxInputField";
88
import { InputField } from "~components/forms/InputField";
99
import { TextInput } from "~components/forms/TextInputField";
1010
import { ALL_ORIGINS_WILDCARD, DEFAULT_ONA_ENDPOINT } from "~constants";
11-
import { ConfigCatProvider, configCatProviderConfig, FeatureFlags, useFlag } from "~hooks/use-configcat";
11+
import { ConfigCatProvider, configCatProviderConfig } from "~hooks/use-configcat";
1212
import { useTemporaryState } from "~hooks/use-temporary-state";
1313
import {
1414
STORAGE_AUTOMATICALLY_DETECT_GITPOD,
1515
STORAGE_KEY_ADDRESS,
1616
STORAGE_KEY_ALWAYS_OPTIONS,
1717
STORAGE_KEY_NEW_TAB,
1818
} from "~storage";
19-
import { hostToOrigin, parseEndpoint } from "~utils/parse-endpoint";
19+
import { hostToOrigin, isOnaEndpoint, parseEndpoint } from "~utils/parse-endpoint";
2020
import { canAccessAllSites } from "~utils/permissions";
2121
import "./popup.css";
2222

@@ -35,11 +35,10 @@ function PopupContent() {
3535
const [error, setError] = useState<string>();
3636

3737
const [storedAddress] = useStorage<string>(STORAGE_KEY_ADDRESS, DEFAULT_ONA_ENDPOINT);
38+
const isStoredAddressOna = isOnaEndpoint(storedAddress);
3839
const [address, setAddress] = useState<string>(storedAddress);
3940
const [justSaved, setJustSaved] = useTemporaryState(false, 2000);
4041

41-
const { value: isOnaEnabled } = useFlag(FeatureFlags.ONA_ENABLED, false);
42-
4342
const updateAddress = useCallback(
4443
(e: FormEvent) => {
4544
e.preventDefault();
@@ -97,12 +96,12 @@ function PopupContent() {
9796
minWidth: "360px",
9897
padding: "16px",
9998
}}
100-
className={`${isOnaEnabled && "ona"}`}
99+
className="ona"
101100
>
102101
<form className="w-full" onSubmit={updateAddress} action="#">
103102
<InputField
104-
label={`${isOnaEnabled ? "Ona" : "Gitpod"} URL`}
105-
hint={`${isOnaEnabled ? "Ona" : "Gitpod"} instance URL, e.g. ${DEFAULT_ONA_ENDPOINT}.`}
103+
label={`Ona URL`}
104+
hint={`Ona instance URL, e.g. ${DEFAULT_ONA_ENDPOINT}.`}
106105
topMargin={false}
107106
>
108107
<div className="flex w-full h-10 max-w-sm items-center space-x-2">
@@ -119,7 +118,7 @@ function PopupContent() {
119118
</div>
120119
</InputField>
121120
<CheckboxInputField
122-
label={`Open ${isOnaEnabled ? "Environments" : "Workspaces"} in a new tab`}
121+
label={`Open Environments in a new tab`}
123122
checked={openInNewTab}
124123
onChange={setOpenInNewTab}
125124
/>
@@ -144,13 +143,13 @@ function PopupContent() {
144143
<CheckboxInputField
145144
label="Always start with options"
146145
hint="Changes the primary button to always open with options"
147-
checked={isOnaEnabled ? true : disableAutostart}
146+
checked={isStoredAddressOna ? true : disableAutostart}
148147
onChange={setDisableAutostart}
149-
disabled={isOnaEnabled}
148+
disabled={isStoredAddressOna}
150149
/>
151150
<CheckboxInputField
152151
label="Automatic instance hopping"
153-
hint={`Changes the ${isOnaEnabled ? "Ona" : "Gitpod"} URL automatically when a${isOnaEnabled ? "n Ona" : " Gitpod"} instance is detected`}
152+
hint={`Changes the Ona URL automatically when an Ona instance is detected`}
154153
checked={enableInstanceHopping}
155154
onChange={setEnableInstanceHopping}
156155
/>

test/src/button-contributions-copy.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ export interface ButtonContributionParams {
105105
* Each manipulation contains a CSS selector (element) that is used to find the element to manipulate and optionally
106106
* the classnames to remove and add.
107107
*/
108-
manipulations?: { element: string; remove?: string; add?: string; style?: Partial<CSSStyleDeclaration> }[];
108+
manipulations?: { element: string; removeClassName?: string; addClassName?: string; style?: Partial<CSSStyleDeclaration>, setAttribute?: { name: string, value: string }[] }[];
109109

110110
/**
111-
* A function that can be used to transform the URL that should be opened when the Gitpod button is clicked.
111+
* A function that can be used to transform the URL that should be opened when the Ona button is clicked.
112112
* @returns The transformed URL.
113113
*/
114114
urlTransformer?: (originalURL: string) => string;
@@ -140,7 +140,7 @@ export const buttonContributions: ButtonContributionParams[] = [
140140
manipulations: [
141141
{
142142
element: "div.repos-files-header-commandbar.scroll-hidden",
143-
remove: "scroll-hidden",
143+
removeClassName: "scroll-hidden",
144144
},
145145
],
146146
urlTransformer(originalUrl) {
@@ -198,7 +198,7 @@ export const buttonContributions: ButtonContributionParams[] = [
198198
{
199199
// make the clone button secondary
200200
element: "#clone-dropdown",
201-
remove: "btn-confirm",
201+
removeClassName: "btn-confirm",
202202
},
203203
],
204204
},
@@ -224,7 +224,7 @@ export const buttonContributions: ButtonContributionParams[] = [
224224
// make the clone button secondary
225225
element:
226226
"#fileHolder > div.js-file-title.file-title-flex-parent > div.gl-display-flex.gl-flex-wrap.file-actions > div.gl-sm-ml-3.gl-mr-3 > div > button",
227-
remove: "btn-confirm",
227+
removeClassName: "btn-confirm",
228228
},
229229
],
230230
},
@@ -241,7 +241,7 @@ export const buttonContributions: ButtonContributionParams[] = [
241241
// make the clone button secondary
242242
element:
243243
"#content-body > div.merge-request .js-issuable-actions > div.dropdown.gl-dropdown > button",
244-
remove: "btn-confirm",
244+
removeClassName: "btn-confirm",
245245
},
246246
],
247247
},
@@ -267,6 +267,16 @@ export const buttonContributions: ButtonContributionParams[] = [
267267
containerElement: createElement("div", {}),
268268
additionalClassNames: ["medium"],
269269
application: "github",
270+
manipulations: [
271+
{
272+
// make the clone button secondary
273+
element:
274+
"xpath://button[contains(., 'Code')]",
275+
setAttribute: [
276+
{ name: "data-variant", value: "default" },
277+
],
278+
},
279+
],
270280
match: () => {
271281
const regex = /^https?:\/\/([^/]+)\/([^/]+)\/([^/]+)(\/(tree\/.*)?)?$/;
272282
return document.querySelector("div.file-navigation") === null && regex.test(window.location.href);
@@ -290,20 +300,12 @@ export const buttonContributions: ButtonContributionParams[] = [
290300
{
291301
id: "gh-issue",
292302
exampleUrls: ["https://github.com/svenefftinge/browser-extension-test/issues/1"],
293-
selector: "#partial-discussion-header > div.gh-header-show > div > div",
294-
containerElement: createElement("div", {
295-
order: "2",
296-
}),
303+
selector: "[data-component='PH_Actions'] > div", //
304+
insertBefore: "[data-component='PH_Actions'] > div > button",
305+
containerElement: createElement("div", {}),
297306
match: /\/issues\//,
298307
application: "github",
299-
manipulations: [
300-
{
301-
// make the code button secondary
302-
element: "#partial-discussion-header > div.gh-header-show > div > div > a",
303-
remove: "Button--primary",
304-
add: "Button--secondary",
305-
},
306-
],
308+
additionalClassNames: ["tall"],
307309
},
308310
{
309311
id: "gh-issue-new", // this isn't referring to "new issue", but to new "issue"
@@ -318,7 +320,7 @@ export const buttonContributions: ButtonContributionParams[] = [
318320
{
319321
id: "gh-pull",
320322
exampleUrls: ["https://github.com/svenefftinge/browser-extension-test/pull/2"],
321-
selector: "#partial-discussion-header > div.gh-header-show > div > div",
323+
selector: "#partial-discussion-header div.gh-header-show > div > div",
322324
containerElement: createElement("div", {
323325
order: "2",
324326
}),

0 commit comments

Comments
 (0)