Skip to content

Commit

Permalink
Rename Quick Bar to match starter brick conventions (#8656)
Browse files Browse the repository at this point in the history
  • Loading branch information
twschiller authored Jun 21, 2024
1 parent 1bd8991 commit 209ab24
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 120 deletions.
12 changes: 6 additions & 6 deletions src/components/quickBar/quickBarRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ class QuickBarRegistry implements QuickBarProtocol {
/**
* Remove all actions added by a given extension point.
*/
removeExtensionPointActions(extensionPointId: RegistryId): void {
remove(this.actions, (x) => x.extensionPointId === extensionPointId);
removeStarterBrickActions(starterBrickId: RegistryId): void {
remove(this.actions, (x) => x.extensionPointId === starterBrickId);
this.notifyListeners();
}

/**
* Remove all actions added by a given extension.
* @param extensionId the ModComponentBase UUID
* Remove all actions added by a given mod component.
* @param modComponentId the ModComponentBase UUID
*/
removeExtensionActions(extensionId: UUID): void {
remove(this.actions, (x) => x.extensionId === extensionId);
removeModComponentActions(modComponentId: UUID): void {
remove(this.actions, (x) => x.extensionId === modComponentId);
this.notifyListeners();
}

Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/slices/editorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import {
checkAvailable,
} from "@/contentScript/messenger/api";
import { resolveExtensionInnerDefinitions } from "@/registry/internal";
import { QuickBarStarterBrickABC } from "@/starterBricks/quickBar/quickBarExtension";
import { QuickBarStarterBrickABC } from "@/starterBricks/quickBar/quickBarStarterBrick";
import { testMatchPatterns } from "@/bricks/available";
import { BusinessError } from "@/errors/businessErrors";
import { serializeError } from "serialize-error";
Expand Down Expand Up @@ -187,7 +187,7 @@ const checkAvailableInstalledExtensions = createAsyncThunk<

// QuickBar is installed on every page, need to filter by the documentUrlPatterns
if (
QuickBarStarterBrickABC.isQuickBarExtensionPoint(activatedStarterBrick)
QuickBarStarterBrickABC.isQuickBarStarterBrick(activatedStarterBrick)
) {
return testMatchPatterns(
activatedStarterBrick.documentUrlPatterns,
Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/starterBricks/formStateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
type QuickBarConfig,
type QuickBarDefaultOptions,
type QuickBarTargetMode,
} from "@/starterBricks/quickBar/types";
} from "@/starterBricks/quickBar/quickBarTypes";
import {
type SidebarConfig,
type Trigger as SidebarTrigger,
Expand All @@ -51,7 +51,7 @@ import { type Menus } from "webextension-polyfill";
import {
type QuickBarProviderConfig,
type QuickBarProviderDefaultOptions,
} from "@/starterBricks/quickBarProvider/types";
} from "@/starterBricks/quickBarProvider/quickBarProviderTypes";
import { type TourDefinition } from "@/starterBricks/tour/types";
import {
type BaseExtensionPointState,
Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/starterBricks/quickBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ import { omitEditorMetadata } from "./pipelineMapping";
import { type StarterBrickDefinitionLike } from "@/starterBricks/types";
import { faThLarge } from "@fortawesome/free-solid-svg-icons";
import { type ModComponentFormStateAdapter } from "@/pageEditor/starterBricks/modComponentFormStateAdapter";
import { QuickBarStarterBrickABC } from "@/starterBricks/quickBar/quickBarExtension";
import { QuickBarStarterBrickABC } from "@/starterBricks/quickBar/quickBarStarterBrick";
import QuickBarConfiguration from "@/pageEditor/tabs/quickBar/QuickBarConfiguration";
import type { DraftModComponent } from "@/contentScript/pageEditor/types";
import { type QuickBarFormState } from "./formStateTypes";
import { type SingleLayerReaderConfig } from "@/pageEditor/baseFormStateTypes";
import {
type QuickBarDefinition,
type QuickBarConfig,
} from "@/starterBricks/quickBar/types";
} from "@/starterBricks/quickBar/quickBarTypes";
import { assertNotNullish } from "@/utils/nullishUtils";

function fromNativeElement(url: string, metadata: Metadata): QuickBarFormState {
Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/starterBricks/quickBarProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ import { faPlusSquare } from "@fortawesome/free-solid-svg-icons";
import { type ModComponentFormStateAdapter } from "@/pageEditor/starterBricks/modComponentFormStateAdapter";
import type { DraftModComponent } from "@/contentScript/pageEditor/types";
import { type QuickBarProviderFormState } from "./formStateTypes";
import { QuickBarProviderStarterBrickABC } from "@/starterBricks/quickBarProvider/quickBarProviderExtension";
import { QuickBarProviderStarterBrickABC } from "@/starterBricks/quickBarProvider/quickBarProviderStarterBrick";
import QuickBarProviderConfiguration from "@/pageEditor/tabs/quickBarProvider/QuickBarProviderConfiguration";
import { type SingleLayerReaderConfig } from "@/pageEditor/baseFormStateTypes";
import {
type QuickBarProviderDefinition,
type QuickBarProviderConfig,
} from "@/starterBricks/quickBarProvider/types";
} from "@/starterBricks/quickBarProvider/quickBarProviderTypes";
import { assertNotNullish } from "@/utils/nullishUtils";

function fromNativeElement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import IconWidget from "@/components/fields/IconWidget";
import ExtraPermissionsSection from "@/pageEditor/tabs/ExtraPermissionsSection";
import { useField, useFormikContext } from "formik";
import FieldTemplate from "@/components/form/FieldTemplate";
import { type QuickBarProviderConfig } from "@/starterBricks/quickBarProvider/types";
import { type QuickBarProviderConfig } from "@/starterBricks/quickBarProvider/quickBarProviderTypes";
import { type QuickBarProviderFormState } from "@/pageEditor/starterBricks/formStateTypes";
import SwitchButtonWidget, {
type CheckBoxLike,
Expand Down
4 changes: 2 additions & 2 deletions src/starterBricks/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { fromJS as deserializeMenuItem } from "@/starterBricks/menuItem/menuItem
import { fromJS as deserializeTrigger } from "@/starterBricks/trigger/triggerStarterBrick";
import { fromJS as deserializeContextMenu } from "@/starterBricks/contextMenu/contextMenu";
import { fromJS as deserializeSidebar } from "@/starterBricks/sidebar/sidebarExtension";
import { fromJS as deserializeQuickBar } from "@/starterBricks/quickBar/quickBarExtension";
import { fromJS as deserializeQuickBarProvider } from "@/starterBricks/quickBarProvider/quickBarProviderExtension";
import { fromJS as deserializeQuickBar } from "@/starterBricks/quickBar/quickBarStarterBrick";
import { fromJS as deserializeQuickBarProvider } from "@/starterBricks/quickBarProvider/quickBarProviderStarterBrick";
import { fromJS as deserializeTour } from "@/starterBricks/tour/tourExtension";
import { type StarterBrick } from "@/types/starterBrickTypes";
import { type StarterBrickDefinitionLike } from "@/starterBricks/types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
tick,
} from "@/starterBricks/starterBrickTestUtils";
import blockRegistry from "@/bricks/registry";
import { fromJS } from "@/starterBricks/quickBar/quickBarExtension";
import { fromJS } from "@/starterBricks/quickBar/quickBarStarterBrick";
import { type Menus } from "webextension-polyfill";
import userEvent from "@testing-library/user-event";
import quickBarRegistry from "@/components/quickBar/quickBarRegistry";
Expand All @@ -46,7 +46,7 @@ import { getPlatform } from "@/platform/platformContext";
import {
type QuickBarDefinition,
type QuickBarConfig,
} from "@/starterBricks/quickBar/types";
} from "@/starterBricks/quickBar/quickBarTypes";

const rootReaderId = validateRegistryId("test/root-reader");

Expand Down Expand Up @@ -77,14 +77,14 @@ const starterBrickFactory = (definitionOverrides: UnknownObject = {}) =>
}),
});

const extensionFactory = define<ResolvedModComponent<QuickBarConfig>>({
const modComponentFactory = define<ResolvedModComponent<QuickBarConfig>>({
apiVersion: "v3",
_resolvedModComponentBrand: undefined as never,
id: uuidSequence,
extensionPointId: (n: number) =>
validateRegistryId(`test/starter-brick-${n}`),
_recipe: undefined,
label: "Test Extension",
label: "Test Mod Component",
config: define<QuickBarConfig>({
title: "Test Action",
action: () => [] as BrickPipeline,
Expand All @@ -105,7 +105,7 @@ beforeEach(() => {
const NUM_DEFAULT_QUICKBAR_ACTIONS = [...defaultActions, pageEditorAction]
.length;

describe("quickBarExtension", () => {
describe("quickBarStarterBrick", () => {
it("quick bar smoke test", async () => {
const user = userEvent.setup();

Expand All @@ -117,7 +117,7 @@ describe("quickBarExtension", () => {
const starterBrick = fromJS(getPlatform(), starterBrickFactory()());

starterBrick.registerModComponent(
extensionFactory({
modComponentFactory({
extensionPointId: starterBrick.id,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ import {
type QuickBarDefinition,
type QuickBarConfig,
type QuickBarTargetMode,
} from "@/starterBricks/quickBar/types";
} from "@/starterBricks/quickBar/quickBarTypes";
import { assertNotNullish } from "@/utils/nullishUtils";

export abstract class QuickBarStarterBrickABC extends StarterBrickABC<QuickBarConfig> {
static isQuickBarExtensionPoint(
extensionPoint: StarterBrick,
): extensionPoint is QuickBarStarterBrickABC {
static isQuickBarStarterBrick(
starterBrick: StarterBrick,
): starterBrick is QuickBarStarterBrickABC {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any
-- Need to a access a type specific property (QuickBarExtensionPoint._definition) on a base-typed entity (StarterBrick) */
return (extensionPoint as any)?._definition?.type === "quickBar";
-- Need to access a type specific property (QuickBarStarterBrick._definition) on a base-typed entity (StarterBrick) */
return (starterBrick as any)?._definition?.type === "quickBar";
}

abstract get targetMode(): QuickBarTargetMode;
Expand Down Expand Up @@ -106,22 +106,22 @@ export abstract class QuickBarStarterBrickABC extends StarterBrickABC<QuickBarCo
);

async getBricks(
extension: ResolvedModComponent<QuickBarConfig>,
modComponent: ResolvedModComponent<QuickBarConfig>,
): Promise<Brick[]> {
return collectAllBricks(extension.config.action);
return collectAllBricks(modComponent.config.action);
}

public get kind(): "quickBar" {
return "quickBar";
}

override uninstall(): void {
quickBarRegistry.removeExtensionPointActions(this.id);
quickBarRegistry.removeStarterBrickActions(this.id);
}

clearModComponentInterfaceAndEvents(extensionIds: UUID[]): void {
for (const extensionId of extensionIds) {
quickBarRegistry.removeAction(extensionId);
clearModComponentInterfaceAndEvents(modComponentIds: UUID[]): void {
for (const modComponentId of modComponentIds) {
quickBarRegistry.removeAction(modComponentId);
}
}

Expand All @@ -132,7 +132,7 @@ export abstract class QuickBarStarterBrickABC extends StarterBrickABC<QuickBarCo
);

await initQuickBarApp();
// Like for context menus, the match patterns for quick bar control which pages the extension point requires early
// Like for context menus, the match patterns for quick bar control which pages the starter brick requires early
// access to (so PixieBrix will ask for permissions). Whether a quick bar item actually appears is controlled by the
// documentUrlPatterns.
return true;
Expand Down Expand Up @@ -162,15 +162,15 @@ export abstract class QuickBarStarterBrickABC extends StarterBrickABC<QuickBarCo
private async syncActionsForUrl(): Promise<void> {
// Remove any actions that were available on the previous navigation, but are no longer available
if (!testMatchPatterns(this.documentUrlPatterns, null)) {
quickBarRegistry.removeExtensionPointActions(this.id);
quickBarRegistry.removeStarterBrickActions(this.id);
return;
}

const promises = this.modComponents.map(async (extension) => {
const promises = this.modComponents.map(async (modComponent) => {
try {
await this.registerExtensionAction(extension);
await this.registerModComponentAction(modComponent);
} catch (error) {
reportError(error, { context: selectEventData(extension) });
reportError(error, { context: selectEventData(modComponent) });
throw error;
}
});
Expand All @@ -189,39 +189,39 @@ export abstract class QuickBarStarterBrickABC extends StarterBrickABC<QuickBarCo
}

/**
* Add a QuickBar action for extension
* Add a QuickBar action for a mod component.
*/
private async registerExtensionAction(
extension: ResolvedModComponent<QuickBarConfig>,
private async registerModComponentAction(
modComponent: ResolvedModComponent<QuickBarConfig>,
): Promise<void> {
const {
title: name,
action: actionConfig,
icon: iconConfig,
} = extension.config;
} = modComponent.config;

const icon = iconConfig ? (
<Icon icon={iconConfig.id} library={iconConfig.library} />
) : (
<Icon />
); // Defaults to a box

const extensionLogger = this.logger.childLogger(
selectModComponentContext(extension),
const modComponentLogger = this.logger.childLogger(
selectModComponentContext(modComponent),
);

quickBarRegistry.addAction({
id: extension.id,
id: modComponent.id,
extensionPointId: this.id,
name,
icon,
perform: async () => {
reportEvent(Events.HANDLE_QUICK_BAR, selectEventData(extension));
reportEvent(Events.HANDLE_QUICK_BAR, selectEventData(modComponent));

try {
const reader = await this.getBaseReader();
const serviceContext = await makeIntegrationsContextFromDependencies(
extension.integrationDependencies,
modComponent.integrationDependencies,
);

const targetElement = guessSelectedElement() ?? document;
Expand All @@ -236,20 +236,20 @@ export abstract class QuickBarStarterBrickABC extends StarterBrickABC<QuickBarCo
input,
root: this.decideRoot(targetElement),
serviceContext,
optionsArgs: extension.optionsArgs,
optionsArgs: modComponent.optionsArgs,
};

await reduceExtensionPipeline(actionConfig, initialValues, {
logger: extensionLogger,
...apiVersionOptions(extension.apiVersion),
logger: modComponentLogger,
...apiVersionOptions(modComponent.apiVersion),
});
} catch (error) {
if (hasSpecificErrorCause(error, CancelError)) {
this.platform.toasts.showNotification(
DEFAULT_ACTION_RESULTS.cancel,
);
} else {
extensionLogger.error(error);
modComponentLogger.error(error);
this.platform.toasts.showNotification({
...DEFAULT_ACTION_RESULTS.error,
error, // Include more details in the notification
Expand All @@ -262,29 +262,29 @@ export abstract class QuickBarStarterBrickABC extends StarterBrickABC<QuickBarCo

console.debug(
"Register quick bar action handler for: %s (%s)",
extension.id,
extension.label ?? "No Label",
modComponent.id,
modComponent.label ?? "No Label",
{
extension,
modComponent,
},
);
}

async runModComponents(): Promise<void> {
if (this.modComponents.length === 0) {
console.debug(
`quickBar extension point ${this.id} has no installed extensions`,
`quickBar starter brick ${this.id} has no installed mod components`,
);
// Not sure if this is needed or not, but remove any straggler extension actions
quickBarRegistry.removeExtensionPointActions(this.id);
// Not sure if this is needed or not, but remove any straggler mod component actions
quickBarRegistry.removeStarterBrickActions(this.id);
return;
}

await this.syncActionsForUrl();
}
}

export class RemoteQuickBarExtensionPoint extends QuickBarStarterBrickABC {
export class RemoteQuickBarStarterBrick extends QuickBarStarterBrickABC {
private readonly _definition: QuickBarDefinition;

public readonly permissions: Permissions.Permissions;
Expand Down Expand Up @@ -365,5 +365,5 @@ export function fromJS(
throw new Error(`Expected type=quickBar, got ${type}`);
}

return new RemoteQuickBarExtensionPoint(platform, config);
return new RemoteQuickBarStarterBrick(platform, config);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { validateRegistryId } from "@/types/helpers";
import { mockAnimationsApi } from "jsdom-testing-mocks";
import { define } from "cooky-cutter";
import { fromJS } from "@/starterBricks/quickBarProvider/quickBarProviderExtension";
import { fromJS } from "@/starterBricks/quickBarProvider/quickBarProviderStarterBrick";
import { type BrickPipeline } from "@/bricks/types";
import {
getDocument,
Expand Down Expand Up @@ -46,7 +46,7 @@ import { getPlatform } from "@/platform/platformContext";
import {
type QuickBarProviderDefinition,
type QuickBarProviderConfig,
} from "@/starterBricks/quickBarProvider/types";
} from "@/starterBricks/quickBarProvider/quickBarProviderTypes";

const rootReaderId = validateRegistryId("test/root-reader");

Expand Down
Loading

0 comments on commit 209ab24

Please sign in to comment.