Merge pull request #7540 from SDA-SE/feat/welcome

Feat/welcome
This commit is contained in:
Fredrik Adelöw
2021-10-12 00:09:47 +02:00
committed by GitHub
13 changed files with 144 additions and 26 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';
@@ -0,0 +1,136 @@
{
"English": "Good afternoon",
"Abkhaz": "Уа, мшы бзиа",
"Adyghe": "Уимафэ шІу",
"Afrikaans": "Goeie middag",
"Albanian": "Mirëdita",
"Aleut": "Angaliichxizax̂",
"Aklan": "Mayad nga hapon",
"Alsatian": "Güete Nàchmittag",
"Arabic": "مساء الخير",
"Armenian": "Բարի կէսօր:",
"Assamese": "শুভ আবেলি",
"Asturian": "Bones tardes",
"Australian": "G'day",
"Azerbaijani": "Günortanız xeyir",
"Bashkir": "хәйерле көн",
"Basque": "Arratsalde on",
"Bavarian": "Guadn åmd",
"Bengali": "শুভ বিকাল",
"Bhojpuri": "राम राम",
"Bosnian": "Dobar dan",
"Breton": "Demat",
"Bulgarian": "Добър ден",
"Cebuano": "Maayong Hapon",
"Chamorro": "Buenas tåtdes",
"Chinese": "午安",
"Cornish": "Dohajydh da",
"Corsican": "Bonghjornu",
"Croatian": "Dobar dan",
"Cuyonon": "Mayad nga apon",
"Czech": "Dobré odpoledne",
"Danish": "God eftermiddag",
"Dutch": "Goedemiddag",
"Estonian": "Tere päevast",
"Ewe": "Ŋdɔ",
"Faroese": "Góðan dagin",
"Fijian": "Bula",
"Finnish": "Hyvää päivää",
"Flemish": "Ghoeie middagh",
"French": "Bon après-midi",
"Frisian (North)": "Moin",
"Frisian (West)": "Goeie middei",
"Friulian": "Bundì",
"Galician": "Boa tarde",
"Georgian": "დილა მშვიდობისა",
"German": "Guten Tag",
"Greek": "Καλό απόγευμα",
"Greenlandic": "Inuugujaq",
"Haitian Creole": "Bon apre-midi",
"Hausa": "Barka da yamma",
"Hawaiian": "Aloha ʻauinalā",
"Hebrew": "אחר צהריים טובים",
"Hindi": "नमस्कार",
"Icelandic": "Góðan dag",
"Iloko": "Naimbag a malem",
"Indonesian": "Selamat sore",
"Iñupiaq": "Unnusatkun",
"Gaelic": "Tráthnóna maith duit",
"Italian": "Buongiorno",
"Japanese": "こんにちは",
"Javanese": "Sugeng siang",
"Jèrriais": "Bouônjour",
"Kannada": "ಶುಭ ಮಧ್ಯಾಹ್ನ",
"Kazakh": "Kayırlı kun",
"Khmer": "ទិវាសួស្ដី",
"Korean": "안녕하세요",
"Kurdish": "Rojbash",
"Kyrgyz": "Кутмандуу күнүңүз менен",
"Latvian": "Labdien",
"Limburgish": "Gojemiddig",
"Lithuanian": "Laba diena",
"Low German": "Moin",
"Lozi": "Ki musihali",
"Lule Sámi": "Buorre biejvve",
"Luxembourgish": "Gudde Mëtteg",
"Macedonian": "Добар ден",
"Malagasy": "Manao ahoana e",
"Maltese": "Wara nofsinhar it-tajjeb",
"Mam": "Qalte",
"Manx": "Fastyr mie",
"Māori": "Kia ora",
"Middle Egyptian Hieroglyphs": "𓄤 𓅓𓈙𓂋𓅱𓇰",
"Nepali": "नमस्कार",
"Newari": "भिं न्हि",
"Northern Sámi": "Buorre beaivvi",
"Northern Sotho": "Dumêlang",
"Norwegian": "God ettermiddag",
"Occitan": "Bon vèspre",
"Odia": "ସୁଭ ଖରା ବେଳ",
"Papiamento": "Bon tardi",
"Pashto": "ورځ مو په خير",
"Polish": "Dzień dobry",
"Portuguese": "Boa tarde",
"Romanian": "Bună ziua",
"Russian": "Добрый день",
"Sakha": "Үтүө күнүнэн",
"Sardinian": "Bona sera",
"Scottish Gaelic": "Feasgar math",
"Scots": "Guid efternuin",
"Serbian": "Добар дан",
"Shona": "Masikati",
"Sicilian": "Bon jornu",
"Sinhala": "සුභ දවාලක්",
"Slovenian": "Dober dan",
"Somali": "Galab wanaagsan",
"Southern Sámi": "Buerie biejjie",
"Sumerian": "𒄭𒌓𒁀",
"Swahili": "Habari ya mchana",
"Swedish": "God eftermiddag",
"Swiss German": "Gueten Abig",
"Tagalog": "Magandang hapon po",
"Tamil": "மதிய வணக்கம்",
"Tatar": "Xäyerle kön",
"Telugu": "శుభ మద్యాహ్నం",
"Tetum": "Botarde",
"Thai": "สวัสดีครับ",
"Tibetan": "ཉིན་གུང་བདེ་ལེགས།",
"Tok Pisin": "Apinum",
"Tongan": "Mālō tau mau e hoata ni",
"Tsonga": "Indzengha",
"Tswana": "Thupama e e monate",
"Turkish": "Tünaydın",
"Ukrainian": "Доброго дня",
"Urdu": "روز بخير",
"Uzbek": "Xayrli kun",
"Venetian": "Bondì",
"Vietnamese": "Xin chào",
"Võro": "Hüvvä lõunaaigo",
"Welsh": "P'nawn da",
"Xhosa": "Uben' emva kwemini entle",
"Yapese": "Fal'e misii",
"Yiddish": "א גוט אָוונט",
"Yucatec Maya": "Ma'lob chi'inil K'iin",
"Zazaki": "Perocê şıma xeyr bo",
"Zulu": "Sawubona"
}
@@ -0,0 +1,102 @@
{
"Afrikaans": "Goeienaand",
"Aklanon": "Mayad nga gabi-i",
"Albanian": "Mirëmbrëma",
"Anglo-Saxon": "God æfen",
"Arabic": "Masaa al-khair",
"Aragonese": "Buena nuei",
"Armenian": "Pari yerego",
"Aromunian": "Bunã seara",
"Asante": "Maadwó",
"Asturian": "Bona nuechi",
"Ateso": "Akwar najokan",
"Australian": "G'day",
"Aymara": "Winas tartis",
"Azerbaijani": "Axşamınız xeyir",
"Basque": "Arratsalde on",
"Belorussian": "Dobry viechar",
"Bemba": "Cungulopo mukwai",
"Bengali": "Shuvo shandhya",
"Bilen": "Aja kunduKwma?",
"Breton": "Noz vat",
"Bulgarian": "Dobar vecher",
"Cantonese": "Maan ngon",
"Cassubian": "Dobri wieczór",
"Catalan": "Bona tarda",
"Chamorro": "Pupuengin maolek",
"Chechen": "Sürea dika yoila",
"Comoran": "Bariza massihou",
"Cornish": "Gorthugher da",
"Croatian": "Dobra večer",
"Czech": "Dobrý večer",
"Danish": "God aften",
"Dutch": "Goedenavond",
"Edo": "Ób’ótà",
"English": "Good evening",
"Esperanto": "Bonan vesperon",
"Estonian": "Tere õhtust",
"Faroese": "Gott kvøld",
"Farsi": "Shab beh'khayr",
"Fijian": "Ni sa bogi",
"Finnish": "Hyvää iltaa",
"French": "Bonsoir",
"Galician": "Boas noites",
"Georgian": "Saghamo mshvidobisa",
"German": "Guten Abend",
"Greek": "Kalinichta",
"Guarani": "Mba’éichapa ndepyhare",
"Hebrew": "Erev tov",
"Hungarian": "Jó estét",
"Icelandic": "Gott kvöld",
"Indonesian": "Selamat malam",
"Irish Gaelic": "Tráthnóna",
"Italian": "Buona sera",
"Japanese": "こんばんは",
"Japanese (Romanji)": "Konban wa",
"Kazakh": "Kayırlı keş",
"Kurdish": "Evarbash",
"Latvian": "Labvakar",
"Lithuanian": "Labas vakaras",
"Low German": "Moin",
"Luganda": "Osiibye otya nno",
"Luo": "Oimore",
"Luxembourgish": "Gudden Owend",
"Macedonian": "Dobra vecher",
"Malay": "Selamat malam",
"Maltese": "Il-lejla t-tajba",
"Mandarin": "Wan shang hao",
"Maori": "Kia orana i teia aiai",
"Marshallese": "Yokwe in jota",
"Mawe": "Awãe aiko",
"Middle Egyptian Hieroglyphs": "𓄤 𓅱𓃉𓇰",
"Mongolian": "Odoin mend",
"Norwegian [Bokmaal]": "God kveld",
"Odia": "ସୁଭସନ୍ଧ୍ୟା",
"Polish": "Dobry wieczór",
"Portuguese": "Boa noite",
"Quiché": "Xe qij",
"Romani [Sinte]": "Lashi rachi",
"Romanian": "Bunã seara",
"Russian": "Добрый вечер",
"Scottish Gaelic": "Feasgar mhath",
"Scots": "Guid eenin",
"Sesotho": "Fonane",
"Serbian": "Добро вече",
"Slovak": "Dober vecher",
"Slovenian": "Dober vecher",
"Somali": "Habeen wanaagsan",
"Spanish": "Buenas tardes",
"Sumerian": "𒄭𒈪",
"Swedish": "God afton",
"Tagalog": "Magandang gabi",
"Tatar": "Xäyerle kiç",
"Telugu": "శుభ సాయంత్రం",
"Thai": "Sawat-dii torn khum",
"Turkish": "İyi akşamlar",
"Ukrainian": "Добрий вечiр",
"Uzbek": "Xayrli kech",
"Welsh": "Noswaith dda",
"Yiddish": "Ah gutn ovnt",
"Chinese": "晚安",
"Valyrian": "sȳz bantis"
}
@@ -0,0 +1,66 @@
{
"English": "Good morning",
"Afrikaans": "Goeiemôre, Môre",
"Albanian": "Mirëmëngjes",
"Arabic": "صباح الخير",
"Armenian": "Paree looys",
"Australian": "G'day",
"Azerbaijani": "Sabahınız xeyir",
"Bengali": "shuprobhat",
"Bulgarian": "Dobro utro",
"Catalan": "Bon dia",
"Chinese": "早安",
"Croatian": "Dobro jutro",
"Czech": "Dobré ráno",
"Danish": "God morgen",
"Dutch": "Goedemorgen",
"Esperanto": "Bonan matenon",
"Estonian": "Tere hommikust",
"Finnish": "Hyvää huomenta",
"French": "Bonjour",
"German": "Guten Morgen",
"Greek": "Kaliméra",
"Kalaallisut": "Iterluarit",
"Hawaiian": "Aloha kakahiaka",
"Hebrew": "boker tov",
"Hindi": "Namaste",
"Hungarian": "Jó reggelt",
"Indonesian": "Selamat pagi",
"Irish": "Dia dhuit",
"Italian": "Buongiorno",
"Japanese": "おはよう",
"Korean": "안녕하세요",
"Kazakh": "Kayırlı tan",
"Kurdish": "Beyanî baş",
"Lithuanian": "Labas rytas",
"Low German": "Moin",
"Macedonian": "Добро утро",
"Malay": "Selamat pagi",
"Maltese": "Bonġu",
"Middle Egyptian Hieroglyphs": "𓄤 𓃀 𓂓 𓇳𓐅",
"Nepali": "subha prabhat",
"Norwegian": "God morgen",
"Odia": "ସୁପ୍ରଭାତ",
"Polish": "Dzień dobry",
"Portuguese": "Bom dia",
"Romanian": "Bună dimineaţa",
"Russian": "Доброе утро",
"Serbian": "Добро јутро",
"Spanish": "Buenos días",
"Sumerian": "𒄭𒌓",
"Swahili": "Habari ya asubuhi",
"Swedish": "God morgon",
"Tagalog": "Magandang umaga po",
"Taiwanese": "爻早",
"Tatar": "Xäyerle irtä",
"Telugu": "శుభోదయం",
"Thai": "สวัสดีครับ",
"Turkish": "Günaydın",
"Ukrainian": "Доброго ранку",
"Urdu": "صبح بخير",
"Uzbek": "Xayrli tong",
"Vietnamese": "Chào buổi sáng",
"Welsh": "Bore da",
"Latvian": "Labrīt",
"Valyrian": "Sȳz ñāqes"
}
@@ -0,0 +1,35 @@
/*
* Copyright 2020 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 { getTimeBasedGreeting } from './timeUtil';
describe('getTimeBasedGreeting', () => {
afterEach(() => jest.resetAllMocks());
it('has greeting and language', () => {
const greeting = getTimeBasedGreeting();
expect(greeting).toHaveProperty('greeting');
expect(greeting).toHaveProperty('language');
});
it('greets late at night', () => {
jest
.spyOn(global.Date, 'now')
.mockImplementationOnce(() => new Date('1970-01-01T23:00:00').valueOf());
const greeting = getTimeBasedGreeting();
expect(greeting.greeting).toBe('Get some rest');
});
});
@@ -0,0 +1,46 @@
/*
* Copyright 2020 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 goodMorning from './locales/goodMorning.locales.json';
import goodAfternoon from './locales/goodAfternoon.locales.json';
import goodEvening from './locales/goodEvening.locales.json';
// Select a large random integer at startup, to prevent the greetings to change
// every time the user navigates.
const greetingRandomSeed = Math.floor(Math.random() * 1000000);
export function getTimeBasedGreeting(): { language: string; greeting: string } {
const random = (array: string[]) => array[greetingRandomSeed % array.length];
const currentHour = new Date(Date.now()).getHours();
if (currentHour >= 23) {
return {
language: 'Seriously',
greeting: 'Get some rest',
};
}
const timeOfDay = (hour: number): { [language: string]: string } => {
if (hour < 12) return goodMorning;
if (hour < 17) return goodAfternoon;
return goodEvening;
};
const greetings = timeOfDay(currentHour);
const greetingsKey = random(Object.keys(greetings));
return {
language: greetingsKey,
greeting: greetings[greetingsKey],
};
}
+1
View File
@@ -27,6 +27,7 @@ export {
ComponentAccordion,
ComponentTabs,
ComponentTab,
WelcomeTitle,
} from './plugin';
export { SettingsModal } from './components';
export { createCardExtension } from './extensions';
+14
View File
@@ -64,6 +64,20 @@ export const ComponentTab = homePlugin.provide(
}),
);
/**
* A component to display a playful greeting for the user.
*
* @public
*/
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',