Removed the HomepageTimer
Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'@backstage/core-app-api': patch
|
||||
'@backstage/core-components': patch
|
||||
'@backstage/plugin-config-schema': patch
|
||||
---
|
||||
|
||||
Removed the `HomepageTimer` and its related config as it has been replaced by the `HeaderWorldClock` in the Home plugin and was deprecated over a year ago
|
||||
@@ -420,16 +420,6 @@ costInsights:
|
||||
kind: 'PINTS_OF_ICE_CREAM'
|
||||
unit: 'ice cream pint'
|
||||
rate: 5.5
|
||||
homepage:
|
||||
clocks:
|
||||
- label: UTC
|
||||
timezone: UTC
|
||||
- label: NYC
|
||||
timezone: 'America/New_York'
|
||||
- label: STO
|
||||
timezone: 'Europe/Stockholm'
|
||||
- label: TYO
|
||||
timezone: 'Asia/Tokyo'
|
||||
pagerduty:
|
||||
eventsBaseUrl: 'https://events.pagerduty.com/v2'
|
||||
jenkins:
|
||||
|
||||
Vendored
-9
@@ -89,15 +89,6 @@ export interface Config {
|
||||
name?: string;
|
||||
};
|
||||
|
||||
homepage?: {
|
||||
clocks?: Array<{
|
||||
/** @visibility frontend */
|
||||
label: string;
|
||||
/** @visibility frontend */
|
||||
timezone: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration that provides information on available configured authentication providers.
|
||||
*/
|
||||
|
||||
@@ -495,9 +495,6 @@ export type HeaderTabsClassKey =
|
||||
// @public (undocumented)
|
||||
export function HelpIcon(props: IconComponentProps): JSX.Element;
|
||||
|
||||
// @public @deprecated
|
||||
export function HomepageTimer(_props: {}): JSX.Element | null;
|
||||
|
||||
// Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts
|
||||
//
|
||||
// @public
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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 {
|
||||
renderWithEffects,
|
||||
TestApiProvider,
|
||||
withLogCollector,
|
||||
} from '@backstage/test-utils';
|
||||
import { HomepageTimer } from './HomepageTimer';
|
||||
import React from 'react';
|
||||
import { lightTheme } from '@backstage/theme';
|
||||
import { ThemeProvider } from '@material-ui/core/styles';
|
||||
import { ConfigReader } from '@backstage/core-app-api';
|
||||
import { ConfigApi, configApiRef } from '@backstage/core-plugin-api';
|
||||
|
||||
it('changes default timezone to GMT', async () => {
|
||||
const configApi: ConfigApi = new ConfigReader({
|
||||
homepage: {
|
||||
clocks: [
|
||||
{
|
||||
label: 'New York',
|
||||
timezone: 'America/New_Pork',
|
||||
},
|
||||
],
|
||||
},
|
||||
context: 'test',
|
||||
});
|
||||
|
||||
const { warn } = await withLogCollector(async () => {
|
||||
const rendered = await renderWithEffects(
|
||||
<ThemeProvider theme={lightTheme}>
|
||||
<TestApiProvider apis={[[configApiRef, configApi]]}>
|
||||
<HomepageTimer />
|
||||
</TestApiProvider>
|
||||
</ThemeProvider>,
|
||||
);
|
||||
|
||||
expect(rendered.getByText('GMT')).toBeInTheDocument();
|
||||
});
|
||||
expect(warn).toEqual([
|
||||
'The timezone America/New_Pork is invalid. Defaulting to GMT',
|
||||
]);
|
||||
});
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* 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 React from 'react';
|
||||
import { HeaderLabel } from '../HeaderLabel';
|
||||
import { ConfigApi, useApi, configApiRef } from '@backstage/core-plugin-api';
|
||||
|
||||
const timeFormat: Intl.DateTimeFormatOptions = {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
};
|
||||
|
||||
type TimeObj = {
|
||||
time: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
function getTimes(configApi: ConfigApi) {
|
||||
const d = new Date();
|
||||
const lang = window.navigator.language;
|
||||
|
||||
const clocks: TimeObj[] = [];
|
||||
|
||||
if (!configApi.has('homepage.clocks')) {
|
||||
return clocks;
|
||||
}
|
||||
|
||||
const clockConfigs = configApi.getConfigArray('homepage.clocks');
|
||||
|
||||
for (const clock of clockConfigs) {
|
||||
if (clock.has('label') && clock.has('timezone')) {
|
||||
let label = clock.getString('label');
|
||||
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
timeZone: clock.getString('timezone'),
|
||||
...timeFormat,
|
||||
};
|
||||
|
||||
try {
|
||||
new Date().toLocaleString(lang, options);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`The timezone ${options.timeZone} is invalid. Defaulting to GMT`,
|
||||
);
|
||||
options.timeZone = 'GMT';
|
||||
label = 'GMT';
|
||||
}
|
||||
|
||||
const time = d.toLocaleTimeString(lang, options);
|
||||
clocks.push({ time, label });
|
||||
}
|
||||
}
|
||||
return clocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Please use the HeaderWorldClock in the home plugin
|
||||
*
|
||||
* @public
|
||||
* @deprecated in favor of the HeaderWorldClock which is found in the to home plugin
|
||||
*/
|
||||
export function HomepageTimer(_props: {}) {
|
||||
const configApi = useApi(configApiRef);
|
||||
|
||||
const defaultTimes: TimeObj[] = [];
|
||||
const [clocks, setTimes] = React.useState(defaultTimes);
|
||||
|
||||
React.useEffect(() => {
|
||||
setTimes(getTimes(configApi));
|
||||
|
||||
const intervalId = setInterval(() => {
|
||||
setTimes(getTimes(configApi));
|
||||
}, 1000);
|
||||
|
||||
return () => {
|
||||
clearInterval(intervalId);
|
||||
};
|
||||
}, [configApi]);
|
||||
|
||||
if (clocks.length !== 0) {
|
||||
return (
|
||||
<>
|
||||
{clocks.map(clock => (
|
||||
<HeaderLabel
|
||||
label={clock.label}
|
||||
value={clock.time}
|
||||
key={clock.label}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export { HomepageTimer } from './HomepageTimer';
|
||||
@@ -23,7 +23,6 @@ export * from './Header';
|
||||
export * from './HeaderActionMenu';
|
||||
export * from './HeaderLabel';
|
||||
export * from './HeaderTabs';
|
||||
export * from './HomepageTimer';
|
||||
export * from './InfoCard';
|
||||
export * from './ItemCard';
|
||||
export * from './Page';
|
||||
|
||||
@@ -499,28 +499,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"homepage": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"clocks": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["label", "timezone"],
|
||||
"properties": {
|
||||
"label": {
|
||||
"visibility": "frontend",
|
||||
"type": "string"
|
||||
},
|
||||
"timezone": {
|
||||
"visibility": "frontend",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"integrations": {
|
||||
"description": "Configuration for integrations towards various external repository provider systems",
|
||||
"type": "object",
|
||||
|
||||
Reference in New Issue
Block a user