Skip to content

Commit

Permalink
feat: expose upsertApp api
Browse files Browse the repository at this point in the history
Refs: SHELL-199 (#421)
Co-authored-by: Beatrice Guerra <[email protected]>
  • Loading branch information
CataldoMazzilli and beawar authored May 21, 2024
1 parent 7351433 commit b2e454a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
18 changes: 11 additions & 7 deletions api-extractor/carbonio-shell-ui.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/boot/app/app-loader-setters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export {
removePrimaryAccessoryView,
setRouteVisibility,
updateUtilityBadge,
updatePrimaryBadge
updatePrimaryBadge,
upsertApp
} from './boot/app/app-loader-setters';

export declare const getI18n: AppFunctions['getI18n'];
Expand Down
9 changes: 9 additions & 0 deletions src/store/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit b2e454a

Please sign in to comment.