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

Add secondary button config to store #342

Merged
merged 2 commits into from Jan 26, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions how-to/customize-workspace/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## v11

- Added default secondary buttons config for store

## v10

- Added support for new themes format with light and dark schemes
Expand Down
@@ -1,4 +1,9 @@
import type { StorefrontFooter, Image, StorefrontNavigationItemDetails } from "@openfin/workspace";
import type {
StorefrontFooter,
Image,
StorefrontNavigationItemDetails,
StoreButtonConfig
} from "@openfin/workspace";

export interface StorefrontSettingsNavigationItem {
/**
Expand Down Expand Up @@ -77,4 +82,14 @@ export interface StorefrontProviderOptions {
}[];
/** The configuration of the footer for the store */
footer: StorefrontFooter;

/**
* The action triggered when the primary button is clicked, defaults to launching the app.
*/
primaryButton?: StoreButtonConfig;

/**
* Secondary buttons added to all store entries.
*/
secondaryButtons?: StoreButtonConfig[];
}
36 changes: 27 additions & 9 deletions how-to/customize-workspace/client/src/framework/workspace/store.ts
Expand Up @@ -15,6 +15,7 @@ import { createLogger } from "../logger-provider";
import { getSettings } from "../settings";
import type {
CustomSettings,
StorefrontProviderOptions,
StorefrontSettingsLandingPageRow,
StorefrontSettingsNavigationItem
} from "../shapes";
Expand Down Expand Up @@ -178,7 +179,7 @@ async function getStoreProvider(): Promise<StorefrontProvider> {
getNavigation: getNavigation.bind(this),
getLandingPage: getLandingPage.bind(this),
getFooter: getFooter.bind(this),
getApps: async () => getApps({ private: false }),
getApps: async () => addButtons(settings.storefrontProvider, await getApps({ private: false })),
launchApp: launch
};
}
Expand Down Expand Up @@ -279,14 +280,10 @@ async function getLandingPage(): Promise<StorefrontLandingPage> {
)}. Only ${middleRowAppLimit} will be shown.`
);
}
const validatedMiddleRowApps = middleRowApps.slice(0, middleRowAppLimit) as [
PlatformApp?,
PlatformApp?,
PlatformApp?,
PlatformApp?,
PlatformApp?,
PlatformApp?
];
const validatedMiddleRowApps = addButtons(
settings.storefrontProvider,
middleRowApps.slice(0, middleRowAppLimit)
) as [PlatformApp?, PlatformApp?, PlatformApp?, PlatformApp?, PlatformApp?, PlatformApp?];
landingPage.middleRow = {
title: middleRow.title,
apps: validatedMiddleRowApps
Expand Down Expand Up @@ -407,3 +404,24 @@ async function getLandingPageRow(definition: StorefrontSettingsLandingPageRow, l
items: detailedNavigationItems
};
}

function addButtons(options: StorefrontProviderOptions, apps: PlatformApp[]): PlatformApp[] {
if (options.primaryButton || Array.isArray(options.secondaryButtons)) {
return apps.map((app) => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be the other way around?

If an app specifies a primary or secondary button then we don't override it with the default buttons.

If a common primary button is defined don't we need the same logic (i.e. pass the app to whatever action id is specified)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first if just checks if there are any options set before processing, I have update to maintain existing primary or secondary if an app has them

...app,
primaryButton: app.primaryButton ?? options.primaryButton,
secondaryButtons:
app.secondaryButtons ?? Array.isArray(options.secondaryButtons)
? options.secondaryButtons.map((secondary) => ({
title: secondary.title,
action: {
id: secondary.action.id,
customData: secondary.action.customData ?? app
}
}))
: undefined
}));
}

return apps;
}
54 changes: 54 additions & 0 deletions how-to/customize-workspace/public/schemas/settings.schema.json
Expand Up @@ -1834,6 +1834,60 @@
},
"type": "array"
},
"primaryButtonAction": {
"additionalProperties": false,
"description": "The action triggered when the primary button is clicked, defaults to launching the app.",
"properties": {
"customData": {
"description": "Any data necessary for the functioning of specified custom action"
},
"id": {
"description": "Identifier of a custom action defined at platform initialization",
"type": "string"
}
},
"required": [
"id"
],
"type": "object"
},
"primaryButtonTitle": {
"description": "The title to show on the primary button, defaults to \"Launch\".",
"type": "string"
},
"secondaryButtons": {
"description": "Secondary buttons added to all store entries.",
"items": {
"additionalProperties": false,
"properties": {
"action": {
"additionalProperties": false,
"properties": {
"customData": {
"description": "Any data necessary for the functioning of specified custom action"
},
"id": {
"description": "Identifier of a custom action defined at platform initialization",
"type": "string"
}
},
"required": [
"id"
],
"type": "object"
},
"title": {
"type": "string"
}
},
"required": [
"title",
"action"
],
"type": "object"
},
"type": "array"
},
"title": {
"description": "The title for the store which will show up in the store dropdown",
"type": "string"
Expand Down
10 changes: 9 additions & 1 deletion how-to/customize-workspace/public/settings.json
Expand Up @@ -761,7 +761,15 @@
"url": "https://www.youtube.com/user/OpenFinTech"
}
]
}
},
"secondaryButtons": [
{
"title": "Toggle Scheme",
"action": {
"id": "toggle-scheme"
}
}
]
},
"dockProvider": {
"id": "customize-workspace",
Expand Down