Merge pull request #14114 from awanlin/topic/remove-homepagetime

Removed the HomepageTimer and related Config
This commit is contained in:
Johan Haals
2022-10-19 16:14:26 +02:00
committed by GitHub
10 changed files with 15 additions and 217 deletions
+5
View File
@@ -89,6 +89,11 @@ export interface Config {
name?: string;
};
/**
* This config was used by the HomepageTimer but has been replaced by the HeaderWorldClock in the home plugin
*
* @deprecated in favor of the HeaderWorldClock which is found in the home plugin
*/
homepage?: {
clocks?: Array<{
/** @visibility frontend */
-3
View File
@@ -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';