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: add external nodes for statics #3115

Merged
merged 3 commits into from
Aug 8, 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
26 changes: 25 additions & 1 deletion docs/extensibility/statics.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ The version is a string value that defines in which version the extension is con

The **general** section is not required as static extensions present data that are not connected to any resource. Instead, they may use information from the page they are displayed on via variable `$embedResource`.

### _externalNodes_

The **externalNodes** parameter allows you to define optional links to external websites that appear in the navigation menu.

- **externalNodes** - an optional list of links to external websites.
- **category** - a category name.
- **scope** - either `namespace` or `cluster`. Defaults to `cluster`.
- **icon** - an optional icon. Go to [Icon Explorer](https://sdk.openui5.org/test-resources/sap/m/demokit/iconExplorer/webapp/index.html#/overview) to find the list of the available icons.
- **children** - a list of child Nodes containing details about the links.
- **label** - a displayed label
- **link** - a link to an external website. You can provide a [JSONata](jsonata.md) function.

### Example

```yaml
general:
externalNodes:
- category: My Category
icon: course-book
children:
- label: Example Node Label
link: 'https://github.com/kyma-project/busola'
```

## _injections_ section

For more information read the [widget injections overview](./70-widget-injection.md).
For more information, read the [widget injections overview](./70-widget-injection.md).
10 changes: 8 additions & 2 deletions src/state/navigation/extensibilityNodesExtSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RecoilValueReadOnly, selector } from 'recoil';
import { ExtResource, NavNode } from '../types';
import { getFetchFn } from '../utils/getFetchFn';
import { DataSources } from 'components/Extensibility/contexts/DataSources';
import { extensionsState } from 'state/navigation/extensionsAtom';
import { extensionsState, staticsState } from 'state/navigation/extensionsAtom';
import { ExtensibilityNodesExt } from 'state/types';

const createExternalNode = (
Expand Down Expand Up @@ -68,13 +68,19 @@ export const extensibilityNodesExtSelector: RecoilValueReadOnly<
key: 'extensibilityNodesExtSelector',
get: async ({ get }) => {
const extensions = get(extensionsState) || [];
const statics = get(staticsState) || [];

const fetchFn = getFetchFn(get);
if (!fetchFn) {
return null;
}

const extensibilityNodes = getExtensibilityNodesExt(extensions);
const staticsNodes = getExtensibilityNodesExt(statics);

const filteredExtNodes = [...extensibilityNodes.filter(n => n)];
const filteresStaticsNodes = [...staticsNodes.filter(n => n)];

return [...extensibilityNodes.filter(n => n)];
return [...filteredExtNodes.concat(filteresStaticsNodes)];
},
});
11 changes: 11 additions & 0 deletions src/state/navigation/extensionsAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export const useGetExtensions = () => {
const cluster = useRecoilValue(clusterState);
const auth = useRecoilValue(authDataState);
const setExtensions = useSetRecoilState(extensionsState);
const setStatics = useSetRecoilState(staticsState);
const setAllExtensions = useSetRecoilState(allExtensionsState);
const setInjections = useSetRecoilState(injectionsState);
const setWizard = useSetRecoilState(wizardState);
Expand Down Expand Up @@ -414,6 +415,7 @@ export const useGetExtensions = () => {
const manageExtensions = async () => {
if (!cluster) {
setExtensions([]);
setStatics([]);
setAllExtensions([]);
setInjections([]);
setWizard([]);
Expand Down Expand Up @@ -476,6 +478,7 @@ export const useGetExtensions = () => {
}

if (!filteredConfigs && !statics) {
setStatics([]);
setInjections([]);
} else {
let injectionsConfigs: ExtInjectionConfig[] = [];
Expand All @@ -500,6 +503,7 @@ export const useGetExtensions = () => {
}),
),
);
setStatics(statics);
if (isExtensibilityInjectionsEnabled) {
setInjections(injectionsConfigs);
}
Expand All @@ -520,6 +524,13 @@ export const extensionsState: RecoilState<ExtResource[] | null> = atom<
default: defaultValue,
});

export const staticsState: RecoilState<ExtResource[] | null> = atom<
ExtResource[] | null
>({
key: 'staticsState',
default: defaultValue,
});

export const allExtensionsState: RecoilState<ExtResource[] | null> = atom<
ExtResource[] | null
>({
Expand Down
Loading