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) O3-3774: Add implementation for the Nav Group #1116

Merged
merged 19 commits into from
Sep 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export interface GenericLinkConfig {
}

export default function GenericLink() {
const config = useConfig() as GenericLinkConfig;
const config = useConfig<GenericLinkConfig>();
return <ConfigurableLink to={config.target}>{config.title}</ConfigurableLink>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Accordion, AccordionItem } from '@carbon/react';
import { ExtensionSlot, useConfig, Type } from '@openmrs/esm-framework';

export const navGroupFeatureName = 'Nav Group';

export const navGroupConfigSchema = {
title: {
_type: Type.String,
_description: 'The title of the nav group.',
_default: 'My Group',
},
slotName: {
_type: Type.String,
_description: 'The name of the slot to create, which links can be added to.',
},
isExpanded: {
_type: Type.Boolean,
_description: 'The boolean to determine whether the nav group is expanded or not.',
_default: false,
},
};

export interface NavGroupConfig {
title: string;
slotName: string;
isExpanded?: boolean;
}

interface NavGroupProps {
basePath?: string;
}

export function NavGroup({ basePath }: NavGroupProps) {
const { t } = useTranslation();
const { title, isExpanded, slotName } = useConfig<NavGroupConfig>();

return (
<Accordion>
<AccordionItem open={isExpanded} title={t(title)}>
<ExtensionSlot name={slotName ?? `nav-group-${title}`} state={{ basePath }} />
</AccordionItem>
</Accordion>
);
}
4 changes: 4 additions & 0 deletions packages/apps/esm-primary-navigation-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import primaryNavRootComponent from './root.component';
import userPanelComponent from './components/user-panel-switcher-item/user-panel-switcher.component';
import changeLanguageLinkComponent from './components/change-language/change-language-link.extension';
import offlineBannerComponent from './components/offline-banner/offline-banner.component';
import { NavGroup, navGroupConfigSchema } from './components/nav-group/nav-group.component';
import genericLinkComponent, { genericLinkConfigSchema } from './components/generic-link/generic-link.component';

export const importTranslation = require.context('../translations', false, /.json$/, 'lazy');
Expand All @@ -26,6 +27,7 @@ const options = {
export function startupApp() {
defineConfigSchema(moduleName, configSchema);
defineExtensionConfigSchema('link', genericLinkConfigSchema);
defineExtensionConfigSchema('global-nav-group', navGroupConfigSchema);

setupOfflineSync(userPropertyChange, [], syncUserLanguagePreference);
}
Expand All @@ -49,6 +51,8 @@ export const linkComponent = getSyncLifecycle(genericLinkComponent, {
moduleName,
});

export const navGroup = getSyncLifecycle(NavGroup, options);

export const changeLanguageModal = getAsyncLifecycle(
() => import('./components/change-language/change-language.modal'),
options,
Expand Down
6 changes: 6 additions & 0 deletions packages/apps/esm-primary-navigation-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
"component": "linkComponent",
"online": true,
"offline": true
},
{
"name": "nav-group",
"component": "navGroup",
"online": true,
"offline": true
}
],
"modals": [
Expand Down
10 changes: 5 additions & 5 deletions packages/framework/esm-framework/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/left-nav/index.tsx:31](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/left-nav/index.tsx#L31)
[packages/framework/esm-styleguide/src/left-nav/index.tsx:30](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/left-nav/index.tsx#L30)

___

Expand Down Expand Up @@ -6256,7 +6256,7 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/left-nav/index.tsx:19](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/left-nav/index.tsx#L19)
[packages/framework/esm-styleguide/src/left-nav/index.tsx:18](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/left-nav/index.tsx#L18)

___

Expand Down Expand Up @@ -6505,7 +6505,7 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/left-nav/index.tsx:23](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/left-nav/index.tsx#L23)
[packages/framework/esm-styleguide/src/left-nav/index.tsx:22](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/left-nav/index.tsx#L22)

___

Expand Down Expand Up @@ -7028,7 +7028,7 @@ ___

### useOpenmrsSWR

▸ **useOpenmrsSWR**<`DataType`, `ErrorType`\>(`key`, `options?`): `SWRResponse`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>, `ErrorType`, `undefined` \| `Partial`<`PublicConfiguration`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>, `ErrorType`, `BareFetcher`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>\>\>\>\>
▸ **useOpenmrsSWR**<`DataType`, `ErrorType`\>(`key`, `options?`): `SWRResponse`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>, `ErrorType`, `undefined` \| `SWRConfiguration`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>, `ErrorType`, `BareFetcher`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>\>\>\>

**`beta`**

Expand Down Expand Up @@ -7081,7 +7081,7 @@ function MyComponent() {

#### Returns

`SWRResponse`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>, `ErrorType`, `undefined` \| `Partial`<`PublicConfiguration`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>, `ErrorType`, `BareFetcher`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>\>\>\>\>
`SWRResponse`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>, `ErrorType`, `undefined` \| `SWRConfiguration`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>, `ErrorType`, `BareFetcher`<[`FetchResponse`](interfaces/FetchResponse.md)<`DataType`\>\>\>\>

#### Defined in

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Omit.autoFocus

#### Defined in

node_modules/@react-types/shared/src/events.d.ts:116
node_modules/@react-types/shared/src/events.d.ts:120

___

Expand All @@ -160,7 +160,7 @@ Omit.children

#### Defined in

node_modules/react-aria-components/dist/types.d.ts:54
node_modules/react-aria-components/dist/types.d.ts:56

___

Expand Down Expand Up @@ -544,7 +544,7 @@ Omit.shouldCloseOnSelect

#### Defined in

node_modules/@react-stately/datepicker/dist/types.d.ts:12
node_modules/@react-stately/datepicker/dist/types.d.ts:21

___

Expand Down Expand Up @@ -590,7 +590,7 @@ Omit.slot

#### Defined in

node_modules/react-aria-components/dist/types.d.ts:71
node_modules/react-aria-components/dist/types.d.ts:73

___

Expand All @@ -606,7 +606,7 @@ Omit.style

#### Defined in

node_modules/react-aria-components/dist/types.d.ts:48
node_modules/react-aria-components/dist/types.d.ts:50

___

Expand All @@ -626,7 +626,7 @@ Omit.validationBehavior

#### Defined in

node_modules/react-aria-components/dist/types.d.ts:82
node_modules/react-aria-components/dist/types.d.ts:84

___

Expand Down Expand Up @@ -690,7 +690,7 @@ Omit.onBlur

#### Defined in

node_modules/@react-types/shared/src/events.d.ts:81
node_modules/@react-types/shared/src/events.d.ts:85

___

Expand Down Expand Up @@ -760,7 +760,7 @@ Omit.onFocus

#### Defined in

node_modules/@react-types/shared/src/events.d.ts:79
node_modules/@react-types/shared/src/events.d.ts:83

___

Expand All @@ -786,7 +786,7 @@ Omit.onFocusChange

#### Defined in

node_modules/@react-types/shared/src/events.d.ts:83
node_modules/@react-types/shared/src/events.d.ts:87

___

Expand All @@ -812,7 +812,7 @@ Omit.onKeyDown

#### Defined in

node_modules/@react-types/shared/src/events.d.ts:72
node_modules/@react-types/shared/src/events.d.ts:76

___

Expand All @@ -838,7 +838,7 @@ Omit.onKeyUp

#### Defined in

node_modules/@react-types/shared/src/events.d.ts:74
node_modules/@react-types/shared/src/events.d.ts:78

___

Expand Down
2 changes: 1 addition & 1 deletion packages/framework/esm-styleguide/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfigSchema } from '@openmrs/esm-config';
import { defineConfigSchema, defineExtensionConfigSchema } from '@openmrs/esm-config';
import { setupLogo } from './logo';
import { setupIcons } from './icons/icon-registration';
import { setupBranding } from './brand';
Expand Down
1 change: 0 additions & 1 deletion packages/framework/esm-styleguide/src/left-nav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import React from 'react';
import { ExtensionSlot, useStore } from '@openmrs/esm-react-utils';
import { createGlobalStore } from '@openmrs/esm-state';
import type { SideNavProps } from '@carbon/react';
hadijahkyampeire marked this conversation as resolved.
Show resolved Hide resolved
import { SideNav } from '@carbon/react';
import styles from './left-nav.module.scss';

Expand Down
Loading