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

feat: expose upsertApp api #421

Merged
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
18 changes: 11 additions & 7 deletions api-extractor/carbonio-shell-ui.api.md
Original file line number Diff line number Diff line change
@@ -229,6 +229,7 @@ type AnyFunction = (...args: any[]) => any;
// @public (undocumented)
type AppActions = {
setApps: (apps: Array<Partial<CarbonioModule>>) => void;
upsertApp: (app: Pick<CarbonioModule, 'name' | 'display' | 'description'>) => void;
addRoute: (routeData: AppRouteDescriptor) => string;
setRouteVisibility: (id: string, visible: boolean) => void;
removeRoute: (id: string) => void;
@@ -1477,6 +1478,9 @@ export const updatePrimaryBadge: (badge: Partial<BadgeInfo_2>, id: string) => vo
// @public (undocumented)
export const updateUtilityBadge: (badge: Partial<BadgeInfo_2>, id: string) => void;

// @public
export const upsertApp: (app: Pick<CarbonioModule, "description" | "name" | "display">) => void;

// @public (undocumented)
export const useAction: <T>(type: string, id: string, target?: T | undefined) => [Action | undefined, boolean];

@@ -1665,13 +1669,13 @@ interface ZimletProp {
// lib/network/edit-settings.d.ts:9:5 - (ae-forgotten-export) The symbol "GrantRightsResponse" needs to be exported by the entry point lib.d.ts
// lib/settings/components/settings-header.d.ts:5:5 - (ae-forgotten-export) The symbol "RouteLeavingGuardProps" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:23:5 - (ae-forgotten-export) The symbol "CarbonioModule" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:24:5 - (ae-forgotten-export) The symbol "AppRouteDescriptor" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:29:5 - (ae-forgotten-export) The symbol "BoardView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:31:5 - (ae-forgotten-export) The symbol "SettingsView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:33:5 - (ae-forgotten-export) The symbol "SearchView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:35:5 - (ae-forgotten-export) The symbol "UtilityView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:37:5 - (ae-forgotten-export) The symbol "PrimaryAccessoryView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:39:5 - (ae-forgotten-export) The symbol "SecondaryAccessoryView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:25:5 - (ae-forgotten-export) The symbol "AppRouteDescriptor" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:30:5 - (ae-forgotten-export) The symbol "BoardView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:32:5 - (ae-forgotten-export) The symbol "SettingsView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:34:5 - (ae-forgotten-export) The symbol "SearchView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:36:5 - (ae-forgotten-export) The symbol "UtilityView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:38:5 - (ae-forgotten-export) The symbol "PrimaryAccessoryView" needs to be exported by the entry point lib.d.ts
// lib/store/app/store.d.ts:40:5 - (ae-forgotten-export) The symbol "SecondaryAccessoryView" needs to be exported by the entry point lib.d.ts
// lib/store/context-bridge.d.ts:4:5 - (ae-forgotten-export) The symbol "PackageDependentFunction" needs to be exported by the entry point lib.d.ts
// lib/store/context-bridge.d.ts:5:5 - (ae-forgotten-export) The symbol "AnyFunction" needs to be exported by the entry point lib.d.ts
// lib/store/integrations/store.d.ts:26:9 - (ae-forgotten-export) The symbol "Action_2" needs to be exported by the entry point lib.d.ts
14 changes: 13 additions & 1 deletion src/boot/app/app-loader-setters.ts
Original file line number Diff line number Diff line change
@@ -80,7 +80,19 @@ export const {
removeSearchView,
removeUtilityView,
removePrimaryAccessoryView,
removeSecondaryAccessoryView
removeSecondaryAccessoryView,
/**
* Add or update the translatable display and description labels for an app.
* These fields are the ones used in the UI.
* @param app - The app to update based on the name field
* @example
* upsertApp(\{
* name: 'carbonio-example-ui',
* display: t('label.app_name', 'Example')
* description: t('label.app_description', 'Example module')
* \});
*/
upsertApp
} = useAppStore.getState();

export const {
3 changes: 2 additions & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,8 @@ export {
removePrimaryAccessoryView,
setRouteVisibility,
updateUtilityBadge,
updatePrimaryBadge
updatePrimaryBadge,
upsertApp
} from './boot/app/app-loader-setters';

export declare const getI18n: AppFunctions['getI18n'];
9 changes: 9 additions & 0 deletions src/store/app/store.ts
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ export type AppState = {

export type AppActions = {
setApps: (apps: Array<Partial<CarbonioModule>>) => void;
upsertApp: (app: Pick<CarbonioModule, 'name' | 'display' | 'description'>) => void;
addRoute: (routeData: AppRouteDescriptor) => string;
setRouteVisibility: (id: string, visible: boolean) => void;
removeRoute: (id: string) => void;
@@ -166,6 +167,13 @@ export const useAppStore = create<AppState & AppActions>()((set, get) => ({
};
});
},
upsertApp: (app): void => {
set(
produce<AppState>((state) => {
state.apps[app.name] = { ...state.apps[app.name], ...app };
})
);
},
setAppContext:
(app) =>
(context): void => {
@@ -211,6 +219,7 @@ export const useAppStore = create<AppState & AppActions>()((set, get) => ({
component: routeData.appView
});
}
// TODO remove with SHELL-212
if (routeData.app && state.apps[routeData.app] && routeData.focusMode !== true) {
state.apps[routeData.app].display = routeData.label;
}