Skip to content

feat: adds dynamic notices flag on config #2091

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

Merged
merged 2 commits into from
Jan 30, 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.
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 @@ -242,6 +242,7 @@ interface BaseResourceConfig {
filterCategories?: FilterConfig;
supportedSources?: SourcesConfig;
notices?: NoticesConfigType;
hasDynamicNoticesEnabled?: boolean;
searchHighlight?: ResourceHighlightConfig;
}

Expand Down
19 changes: 17 additions & 2 deletions frontend/amundsen_application/static/js/config/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import {
HomePageWidgetsConfig,
} from './config-types';

const DEFAULT_DYNAMIC_NOTICES_ENABLED_FLAG = false;
export const DEFAULT_DATABASE_ICON_CLASS = 'icon-database icon-color';
export const DEFAULT_DASHBOARD_ICON_CLASS = 'icon-dashboard icon-color';
const WILDCARD_SIGN = '*';
const RESOURCE_SEPARATOR = '.';
const ANNOUNCEMENTS_LINK_LABEL = 'Announcements';
const hasWildcard = (n) => n.indexOf(WILDCARD_SIGN) > -1;
const withComputedMessage = (notice: NoticeType, resourceName) => {
const hasWildcard = (n: string) => n.indexOf(WILDCARD_SIGN) > -1;
const withComputedMessage = (notice: NoticeType, resourceName: string) => {
if (typeof notice.messageHtml === 'function') {
notice.messageHtml = notice.messageHtml(resourceName);
}
Expand Down Expand Up @@ -148,6 +149,20 @@ export function getResourceNotices(
return false;
}

/**
* Communicates whether dynamic notices via API requests is enabled for a given resource
* @param resourceType Any resource type (except query)
* @returns Whether if the resource has dynamic notices
*/
export function getDynamicNoticesEnabledByResource(
resourceType: Exclude<ResourceType, ResourceType.query>
): boolean {
const { hasDynamicNoticesEnabled = DEFAULT_DYNAMIC_NOTICES_ENABLED_FLAG } =
AppConfig.resourceConfig[resourceType];

return hasDynamicNoticesEnabled;
}

/**
* Returns the displayName for the given resourceType
*/
Expand Down
64 changes: 64 additions & 0 deletions frontend/amundsen_application/static/js/config/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,70 @@ describe('getResourceNotices', () => {
});
});

describe('dynamicNoticesEnabled', () => {
describe('when resource type is Table', () => {
it('is false by default', () => {
const testResource = ResourceType.table;
const expected = false;
const actual =
ConfigUtils.getDynamicNoticesEnabledByResource(testResource);

expect(actual).toBe(expected);
});

describe('when set to true', () => {
it('should return true', () => {
const testResource = ResourceType.table;
const expected = true;

AppConfig.resourceConfig[testResource].hasDynamicNoticesEnabled = true;
const actual =
ConfigUtils.getDynamicNoticesEnabledByResource(testResource);

expect(actual).toBe(expected);
});
});
});

describe('when resource type is any of dashboard, user or feature', () => {
it.each([['dashboard'], ['user'], ['feature']])(
'it is false by default',
(resource: Exclude<ResourceType, ResourceType.query>) => {
const expected = false;
const actual = ConfigUtils.getDynamicNoticesEnabledByResource(resource);

expect(actual).toBe(expected);
}
);

describe('when set to true', () => {
it.each([['dashboard'], ['user'], ['feature']])(
'it should return true',
(resource: Exclude<ResourceType, ResourceType.query>) => {
const expected = true;

AppConfig.resourceConfig[resource].hasDynamicNoticesEnabled = true;
const actual =
ConfigUtils.getDynamicNoticesEnabledByResource(resource);

expect(actual).toBe(expected);
}
);
});
});

describe('when resource is query', () => {
it('fails on the TS level', () => {
const testResource = ResourceType.query;

expect(() => {
// @ts-expect-error
ConfigUtils.getDynamicNoticesEnabledByResource(testResource);
}).toThrow();
});
});
});

describe('getFilterConfigByResource', () => {
it('returns the filter categories for a given resource', () => {
const testResource = ResourceType.table;
Expand Down
25 changes: 23 additions & 2 deletions frontend/docs/application_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,27 @@ This feature's ultimate goal is to allow Amundsen administrators to point their

Learn more about the future developments for this feature in [its RFC](https://github.com/amundsen-io/rfcs/blob/master/rfcs/029-resource-notices.md).


### Dynamic Notices (WIP)
We are now going to allow for fetching dynamically the notices related to different resources like tables, dashboards, users, and features.

For that, you will first enabled the `hasDynamicNoticesEnabled` flag inside the `resourceConfig` object of the goal resource. This flag is optional and will default to `false` if not set.

Example of this option enabled on tables and dashboards:
```ts
resourceConfig: {
[ResourceType.table]: {
... //Table Resource Configuration
hasDynamicNoticesEnabled: true,
},
[ResourceType.dashboard]: {
... //Dashboard Resource Configuration
hasDynamicNoticesEnabled: true,
},
},
```


## Table Lineage

_TODO: Please add doc_
Expand Down Expand Up @@ -412,6 +433,6 @@ Where:
For "feature tours", the setup would be similar, but `isFeatureTour` would be true, and `disableBeacon` should be false (the default), so that users can start the tour.

## Homepage Widgets Config
By default, a set of features are available on the homepage (e.g. the search bar, bookmarks). These can be customized in config-custom.ts by providing an alternate `homePageWidgets` value. The value is a list of `Widget` objects. Non-OSS widgets can be provided in the `widget.options.path` property, and props passed to widget components can be customized with the `widget.options.aditionalProps` property.
By default, a set of features are available on the homepage (e.g. the search bar, bookmarks). These can be customized in config-custom.ts by providing an alternate `homePageWidgets` value. The value is a list of `Widget` objects. Non-OSS widgets can be provided in the `widget.options.path` property, and props passed to widget components can be customized with the `widget.options.aditionalProps` property.

If a custom `homePageWidgets` config is provided, the default config will be ignored. So, for example, if you wanted to have all the default widgets plus a custom non-OSS widget component, you should copy all the homePageWidgets from [config-default.ts](https://github.com/amundsen-io/amundsen/blob/main/frontend/amundsen_application/static/js/config/config-default.ts) to your config-custom.ts, and then append your custom component. To omit one of the default widgets, you would copy the default list, and then delete the widget you didn't want.
If a custom `homePageWidgets` config is provided, the default config will be ignored. So, for example, if you wanted to have all the default widgets plus a custom non-OSS widget component, you should copy all the homePageWidgets from [config-default.ts](https://github.com/amundsen-io/amundsen/blob/main/frontend/amundsen_application/static/js/config/config-default.ts) to your config-custom.ts, and then append your custom component. To omit one of the default widgets, you would copy the default list, and then delete the widget you didn't want.