Skip to content

Commit d5f2152

Browse files
committed
Fix making github primary code button secondary
1 parent 9fc7aba commit d5f2152

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

src/button/button-contributions.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ 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
/**
111111
* A function that can be used to transform the URL that should be opened when the Gitpod button is clicked.
@@ -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"

src/button/button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Props = {
1616
additionalClassNames?: string[];
1717
urlTransformer?: (url: string) => string;
1818
};
19-
export const GitpodButton = ({ application, additionalClassNames, urlTransformer }: Props) => {
19+
export const OnaButton = ({ application, additionalClassNames, urlTransformer }: Props) => {
2020
const [address] = useStorage<string>(STORAGE_KEY_ADDRESS, DEFAULT_ONA_ENDPOINT);
2121
const [openInNewTab] = useStorage<boolean>(STORAGE_KEY_NEW_TAB, true);
2222
const [disableAutostart] = useStorage<boolean>(STORAGE_KEY_ALWAYS_OPTIONS, false);

src/components/forms/TextInputField.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/**
2-
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3-
* Licensed under the GNU Affero General Public License (AGPL).
4-
* See License.AGPL.txt in the project root for license information.
5-
*/
6-
71
import classNames from "classnames";
82
import React, { memo, useCallback, useId, type PropsWithChildren, type ReactNode } from "react";
93
import { FeatureFlags, useFlag } from "~hooks/use-configcat";

src/contents/button.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import type { PlasmoCSConfig, PlasmoGetInlineAnchor } from "plasmo";
33
import React, { type ReactElement } from "react";
44
import { EVENT_CURRENT_URL_CHANGED } from "~constants";
55
import { ConfigCatProvider, configCatProviderConfig } from "~hooks/use-configcat";
6-
7-
import { GitpodButton } from "../button/button";
6+
import { OnaButton } from "../button/button";
87
import { buttonContributions, isSiteSuitable, type ButtonContributionParams } from "../button/button-contributions";
98

109
// keep in sync with DEFAULT_HOSTS in src/button/button-contributions.ts
@@ -43,7 +42,7 @@ class ButtonContributionManager {
4342
this.buttons.set(
4443
containerId,
4544
<ConfigCatProvider {...configCatProviderConfig}>
46-
<GitpodButton
45+
<OnaButton
4746
key={containerId}
4847
application={contribution.application}
4948
additionalClassNames={contribution.additionalClassNames}
@@ -158,11 +157,16 @@ class ButtonContributionManager {
158157
for (const manipulation of contrib.manipulations) {
159158
const element = this.lookupElement(manipulation.element);
160159
if (element) {
161-
if (manipulation.remove) {
162-
element.classList.remove(manipulation.remove);
160+
if (manipulation.removeClassName) {
161+
element.classList.remove(manipulation.removeClassName);
162+
}
163+
if (manipulation.addClassName) {
164+
element.classList.add(manipulation.addClassName);
163165
}
164-
if (manipulation.add) {
165-
element.classList.add(manipulation.add);
166+
if (manipulation.setAttribute) {
167+
for (const attribute of manipulation.setAttribute) {
168+
element.setAttribute(attribute.name, attribute.value);
169+
}
166170
}
167171
if (element instanceof HTMLElement && manipulation.style) {
168172
for (const key in manipulation.style) {

0 commit comments

Comments
 (0)