Add <WelcomeTitle> component

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-10-11 10:13:25 +02:00
parent beaa5ed291
commit ef5bf4235a
12 changed files with 116 additions and 10 deletions
@@ -0,0 +1,32 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { renderInTestApp } from '@backstage/test-utils';
import React from 'react';
import { WelcomeTitle } from './WelcomeTitle';
describe('<WelcomeTitle>', () => {
afterEach(() => jest.resetAllMocks());
test('should greet user', async () => {
jest
.spyOn(global.Date, 'now')
.mockImplementation(() => new Date('1970-01-01T23:00:00').valueOf());
const { getByText } = await renderInTestApp(<WelcomeTitle />);
expect(getByText(/Get some rest, Guest/)).toBeInTheDocument();
});
});
@@ -0,0 +1,32 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { identityApiRef, useApi } from '@backstage/core-plugin-api';
import { Tooltip } from '@material-ui/core';
import React, { useMemo } from 'react';
import { getTimeBasedGreeting } from './timeUtil';
export const WelcomeTitle = () => {
const identityApi = useApi(identityApiRef);
const profile = identityApi.getProfile();
const userId = identityApi.getUserId();
const greeting = useMemo(() => getTimeBasedGreeting(), []);
return (
<Tooltip title={greeting.language}>
<span>{`${greeting.greeting}, ${profile.displayName || userId}!`}</span>
</Tooltip>
);
};
@@ -0,0 +1,16 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { WelcomeTitle } from './WelcomeTitle';
+1
View File
@@ -27,6 +27,7 @@ export {
ComponentAccordion,
ComponentTabs,
ComponentTab,
WelcomeTitle,
} from './plugin';
export { SettingsModal } from './components';
export { createCardExtension } from './extensions';
+9
View File
@@ -60,6 +60,15 @@ export const ComponentTab = homePlugin.provide(
}),
);
export const WelcomeTitle = homePlugin.provide(
createComponentExtension({
component: {
lazy: () =>
import('./homePageComponents/WelcomeTitle').then(m => m.WelcomeTitle),
},
}),
);
export const HomePageRandomJoke = homePlugin.provide(
createCardExtension<{ defaultCategory?: 'any' | 'programming' }>({
title: 'Random Joke',