Skip to content

Commit

Permalink
Additional links configuration (#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
DementevNikita authored Jan 18, 2023
1 parent 771c735 commit f75fd54
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.opendatadiscovery.oddplatform.config;

import org.opendatadiscovery.oddplatform.config.properties.AdditionalLinkProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(AdditionalLinkProperties.class)
public class AdditionalLinkConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.opendatadiscovery.oddplatform.config.properties;

import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("odd")
public record AdditionalLinkProperties(List<Link> links) {
public record Link(String title, String url) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.opendatadiscovery.oddplatform.controller;

import java.util.Collections;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.opendatadiscovery.oddplatform.api.contract.api.LinksApi;
import org.opendatadiscovery.oddplatform.api.contract.model.Link;
import org.opendatadiscovery.oddplatform.api.contract.model.LinkList;
import org.opendatadiscovery.oddplatform.config.properties.AdditionalLinkProperties;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import static java.util.Collections.emptyList;

@RestController
@RequiredArgsConstructor
@Slf4j
public class LinksController implements LinksApi {
private final AdditionalLinkProperties linkProperties;

@Override
public Mono<ResponseEntity<LinkList>> getLinks(final ServerWebExchange exchange) {
if (CollectionUtils.isEmpty(linkProperties.links())) {
return Mono.just(ResponseEntity.ok(new LinkList().items(emptyList())));
}

final List<Link> links = linkProperties.links().stream()
.map(link -> new Link().title(link.title()).url(link.url()))
.toList();

return Mono.just(ResponseEntity.ok(new LinkList().items(links)));
}
}
21 changes: 21 additions & 0 deletions odd-platform-specification/components.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
components:
schemas:
Link:
type: object
properties:
title:
type: string
url:
type: string
required:
- title
- url

LinkList:
type: object
properties:
items:
type: array
items:
$ref: '#/components/schemas/Link'
required:
- items

Feature:
type: string
enum:
Expand Down
17 changes: 17 additions & 0 deletions odd-platform-specification/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,24 @@ tags:
- name: policy
- name: role
- name: permission
- name: links

paths:
/api/links:
get:
summary: Additional links
description: Gets additional links to be displayed in the UI
operationId: getLinks
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: './components.yaml/#/components/schemas/LinkList'
tags:
- links

/api/features/active:
get:
summary: Active features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SlackIcon,
} from 'components/shared/Icons';
import { useAppSelector } from 'redux/lib/hooks';
import { getVersion } from 'redux/selectors';
import { getAppLinks, getVersion } from 'redux/selectors';
import { Grid, Typography } from '@mui/material';
import { Link } from 'react-router-dom';
import AppIconButton from 'components/shared/AppIconButton/AppIconButton';
Expand All @@ -15,6 +15,7 @@ import * as S from './AppInfoMenuStyles';

const AppInfoMenu: React.FC = () => {
const version = useAppSelector(getVersion);
const links = useAppSelector(getAppLinks);

const gitbookLink = 'https://docs.opendatadiscovery.org/';
const slackLink = 'https://go.opendatadiscovery.org/slack';
Expand Down Expand Up @@ -86,6 +87,17 @@ const AppInfoMenu: React.FC = () => {
</S.MenuItem>
</Link>
)}
{links.length > 0 && (
<S.LinksContainer container>
{links.map(link => (
<Link to={{ pathname: link.url }} target='_blank'>
<S.MenuItem container onClick={handleAppMenuClose}>
<Typography variant='h3'>{link.title}</Typography>
</S.MenuItem>
</Link>
))}
</S.LinksContainer>
)}
</AppMenu>
</Grid>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ export const MenuItem = styled(Grid)(({ theme }) => ({
[`${Icon}`]: { backgroundColor: theme.palette.backgrounds.primary },
},
}));

export const LinksContainer = styled(Grid)(({ theme }) => ({
flexDirection: 'column',
paddingTop: theme.spacing(1),
borderTop: '1px solid',
borderTopColor: theme.palette.divider,
}));
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React, { type MouseEvent } from 'react';
import { Grid, Typography, useScrollTrigger } from '@mui/material';
import { getIdentity, getOwnership } from 'redux/selectors';
import { fetchActiveFeatures, fetchAppInfo, fetchIdentity } from 'redux/thunks';
import {
fetchActiveFeatures,
fetchAppInfo,
fetchAppLinks,
fetchIdentity,
} from 'redux/thunks';
import { useAppDispatch, useAppSelector } from 'redux/lib/hooks';
import { DropdownIcon } from 'components/shared/Icons';
import AppMenu from 'components/shared/AppMenu/AppMenu';
Expand Down Expand Up @@ -46,6 +51,7 @@ const AppToolbar: React.FC = () => {
dispatch(fetchIdentity());
dispatch(fetchAppInfo());
dispatch(fetchActiveFeatures());
dispatch(fetchAppLinks());
}, []);

return (
Expand Down
5 changes: 5 additions & 0 deletions odd-platform-ui/src/redux/actions/appInfo.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export const fetchActiveFeaturesActionType = createActionType(
appInfoActionPrefix,
'fetchActiveFeatures'
);

export const fetchAppLinksActionType = createActionType(
appInfoActionPrefix,
'fetchAppLinks'
);
2 changes: 2 additions & 0 deletions odd-platform-ui/src/redux/interfaces/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
Term,
TermDetails,
TermRef,
Link,
} from 'generated-sources';
// eslint-disable-next-line lodash/import-scope
import type { Dictionary } from 'lodash';
Expand Down Expand Up @@ -195,6 +196,7 @@ export interface OwnerAssociationState {
export interface AppInfoState {
appInfo: AppInfo;
activeFeatures: Feature[];
links: Link[];
}

export interface TermsState {
Expand Down
5 changes: 5 additions & 0 deletions odd-platform-ui/src/redux/selectors/appInfo.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ export const getActiveFeatures = createSelector(
appInfoState,
appInfo => appInfo.activeFeatures || emptyArr
);

export const getAppLinks = createSelector(
appInfoState,
appInfo => appInfo.links || emptyArr
);
6 changes: 5 additions & 1 deletion odd-platform-ui/src/redux/slices/appInfo.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createSlice } from '@reduxjs/toolkit';
import { appInfoActionPrefix } from 'redux/actions';
import * as thunks from 'redux/thunks';

export const initialState: AppInfoState = { appInfo: {}, activeFeatures: [] };
export const initialState: AppInfoState = { appInfo: {}, activeFeatures: [], links: [] };

export const appInfoSlice = createSlice({
name: appInfoActionPrefix,
Expand All @@ -17,6 +17,10 @@ export const appInfoSlice = createSlice({
builder.addCase(thunks.fetchActiveFeatures.fulfilled, (state, { payload }) => {
state.activeFeatures = payload;
});

builder.addCase(thunks.fetchAppLinks.fulfilled, (state, { payload }) => {
state.links = payload;
});
},
});

Expand Down
23 changes: 16 additions & 7 deletions odd-platform-ui/src/redux/thunks/appInfo.thunks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
Configuration,
AppInfoApi,
type AppInfo,
FeatureApi,
AppInfoApi,
Configuration,
type Feature,
FeatureApi,
type Link,
LinksApi,
} from 'generated-sources';
import * as actions from 'redux/actions';
import { BASE_PARAMS } from 'lib/constants';
Expand All @@ -12,13 +14,11 @@ import { handleResponseAsyncThunk } from 'redux/lib/handleResponseThunk';
const apiClientConf = new Configuration(BASE_PARAMS);
const appInfoApi = new AppInfoApi(apiClientConf);
const featureApi = new FeatureApi(apiClientConf);
const linksApi = new LinksApi(apiClientConf);

export const fetchAppInfo = handleResponseAsyncThunk<AppInfo>(
actions.fetchAppInfoActionType,
async () => {
const response = await appInfoApi.getAppInfo();
return response;
},
async () => await appInfoApi.getAppInfo(),
{}
);

Expand All @@ -30,3 +30,12 @@ export const fetchActiveFeatures = handleResponseAsyncThunk<Feature[]>(
},
{}
);

export const fetchAppLinks = handleResponseAsyncThunk<Link[]>(
actions.fetchAppLinksActionType,
async () => {
const { items } = await linksApi.getLinks();
return items;
},
{}
);

0 comments on commit f75fd54

Please sign in to comment.