From 15da130211597e48a3c7c69ef15165350edd5adf Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Tue, 29 Sep 2020 10:55:45 +0200 Subject: [PATCH 1/7] create EmptyState --- .../src/components/EmptyState/EmptyState.tsx | 78 +++++++++++++++++++ packages/core/src/components/index.ts | 1 + 2 files changed, 79 insertions(+) create mode 100644 packages/core/src/components/EmptyState/EmptyState.tsx diff --git a/packages/core/src/components/EmptyState/EmptyState.tsx b/packages/core/src/components/EmptyState/EmptyState.tsx new file mode 100644 index 0000000000..f28c8521b0 --- /dev/null +++ b/packages/core/src/components/EmptyState/EmptyState.tsx @@ -0,0 +1,78 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { makeStyles, Typography, Grid } from '@material-ui/core'; +import { EmptyStateImage } from './EmptyStateImage'; +import Background from './assets/Background.svg'; + +const useStyles = makeStyles(theme => ({ + root: { + backgroundColor: theme.palette.background.default, + padding: theme.spacing(10, 0, 0, 0), + }, + action: { + marginTop: theme.spacing(2), + }, + imgPlacholder: { + position: 'relative', + }, + backgroundImage: { + position: 'absolute', + width: '100%', + }, +})); + +type Props = { + title: string; + description?: string; + type: 'missingAnnotation' | 'noInformation' | 'createComponent' | 'noBuild'; + action?: JSX.Element; +}; + +export const EmptyState = ({ title, description, type, action }: Props) => { + const classes = useStyles(); + return ( + + + + {title} + + + {description} + + + {action} + + + + background + + + + ); +}; diff --git a/packages/core/src/components/index.ts b/packages/core/src/components/index.ts index 6c070366c7..4f085ffd6a 100644 --- a/packages/core/src/components/index.ts +++ b/packages/core/src/components/index.ts @@ -34,3 +34,4 @@ export * from './Table'; export * from './Tabs'; export * from './TrendLine'; export * from './WarningPanel'; +export * from './EmptyState'; From 0d6c094d0c298754cbac9a6f4ab175dfa39aa459 Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Tue, 29 Sep 2020 11:07:19 +0200 Subject: [PATCH 2/7] add svgs and EmptyStateImage component --- .../components/EmptyState/EmptyStateImage.tsx | 74 +++++++++++++++++++ .../EmptyState/assets/Background.svg | 10 +++ .../EmptyState/assets/createComponent.svg | 35 +++++++++ .../EmptyState/assets/missingAnnotation.svg | 41 ++++++++++ .../components/EmptyState/assets/noBuild.svg | 43 +++++++++++ .../EmptyState/assets/noInformation.svg | 42 +++++++++++ 6 files changed, 245 insertions(+) create mode 100644 packages/core/src/components/EmptyState/EmptyStateImage.tsx create mode 100644 packages/core/src/components/EmptyState/assets/Background.svg create mode 100644 packages/core/src/components/EmptyState/assets/createComponent.svg create mode 100644 packages/core/src/components/EmptyState/assets/missingAnnotation.svg create mode 100644 packages/core/src/components/EmptyState/assets/noBuild.svg create mode 100644 packages/core/src/components/EmptyState/assets/noInformation.svg diff --git a/packages/core/src/components/EmptyState/EmptyStateImage.tsx b/packages/core/src/components/EmptyState/EmptyStateImage.tsx new file mode 100644 index 0000000000..08db0c4384 --- /dev/null +++ b/packages/core/src/components/EmptyState/EmptyStateImage.tsx @@ -0,0 +1,74 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 missingAnnotation from './assets/missingAnnotation.svg'; +import noInformation from './assets/noInformation.svg'; +import createComponent from './assets/createComponent.svg'; +import noBuild from './assets/noBuild.svg'; +import { makeStyles } from '@material-ui/core'; + +type Props = { + type: 'missingAnnotation' | 'noInformation' | 'createComponent' | 'noBuild'; +}; + +const useStyles = makeStyles(() => ({ + generalImg: { + width: '75%', + zIndex: 2, + position: 'absolute', + left: '50%', + top: '50%', + transform: 'translate(-50%, 15%)', + }, +})); + +export const EmptyStateImage = ({ type }: Props) => { + const classes = useStyles(); + switch (type) { + case 'missingAnnotation': + return ( + annotation is missing + ); + case 'noInformation': + return ( + no Information + ); + case 'createComponent': + return ( + create Component + ); + case 'noBuild': + return ( + no Build + ); + default: + return null; + } +}; diff --git a/packages/core/src/components/EmptyState/assets/Background.svg b/packages/core/src/components/EmptyState/assets/Background.svg new file mode 100644 index 0000000000..e2fa538f7f --- /dev/null +++ b/packages/core/src/components/EmptyState/assets/Background.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/packages/core/src/components/EmptyState/assets/createComponent.svg b/packages/core/src/components/EmptyState/assets/createComponent.svg new file mode 100644 index 0000000000..af2ddd5678 --- /dev/null +++ b/packages/core/src/components/EmptyState/assets/createComponent.svg @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/core/src/components/EmptyState/assets/missingAnnotation.svg b/packages/core/src/components/EmptyState/assets/missingAnnotation.svg new file mode 100644 index 0000000000..475cda9699 --- /dev/null +++ b/packages/core/src/components/EmptyState/assets/missingAnnotation.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/core/src/components/EmptyState/assets/noBuild.svg b/packages/core/src/components/EmptyState/assets/noBuild.svg new file mode 100644 index 0000000000..76a41749b9 --- /dev/null +++ b/packages/core/src/components/EmptyState/assets/noBuild.svg @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/core/src/components/EmptyState/assets/noInformation.svg b/packages/core/src/components/EmptyState/assets/noInformation.svg new file mode 100644 index 0000000000..e41cf94645 --- /dev/null +++ b/packages/core/src/components/EmptyState/assets/noInformation.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b25402d074d584bd552c5275ba2fe7a85aeb5947 Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Tue, 29 Sep 2020 11:09:34 +0200 Subject: [PATCH 3/7] add svgs and EmptyStateImage component --- packages/core/src/components/EmptyState/EmptyStateImage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/components/EmptyState/EmptyStateImage.tsx b/packages/core/src/components/EmptyState/EmptyStateImage.tsx index 08db0c4384..082ea8c581 100644 --- a/packages/core/src/components/EmptyState/EmptyStateImage.tsx +++ b/packages/core/src/components/EmptyState/EmptyStateImage.tsx @@ -25,7 +25,7 @@ type Props = { type: 'missingAnnotation' | 'noInformation' | 'createComponent' | 'noBuild'; }; -const useStyles = makeStyles(() => ({ +const useStyles = makeStyles({ generalImg: { width: '75%', zIndex: 2, @@ -34,7 +34,7 @@ const useStyles = makeStyles(() => ({ top: '50%', transform: 'translate(-50%, 15%)', }, -})); +}); export const EmptyStateImage = ({ type }: Props) => { const classes = useStyles(); From b0fbdf33c22a2a28f69ea8c7843518389dbae6aa Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Tue, 29 Sep 2020 11:10:06 +0200 Subject: [PATCH 4/7] add EmptyState test --- .../components/EmptyState/EmptyState.test.tsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packages/core/src/components/EmptyState/EmptyState.test.tsx diff --git a/packages/core/src/components/EmptyState/EmptyState.test.tsx b/packages/core/src/components/EmptyState/EmptyState.test.tsx new file mode 100644 index 0000000000..2053af8ba6 --- /dev/null +++ b/packages/core/src/components/EmptyState/EmptyState.test.tsx @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { EmptyState } from './EmptyState'; +import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils'; +import { Button } from '@material-ui/core'; + +describe('', () => { + it('render EmptyState component with type annotaion is missing', async () => { + const rendered = await renderWithEffects( + wrapInTestApp( + DOCS} + />, + ), + ); + expect( + rendered.getByText('Your plugin is missing an annotation'), + ).toBeInTheDocument(); + expect(rendered.getByLabelText('button')).toBeInTheDocument(); + expect(rendered.getByTestId('missingAnnotation')).toBeInTheDocument(); + }); +}); From 6149a3e8b186a6229788007652dd4178cf2f70f1 Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Tue, 29 Sep 2020 11:10:34 +0200 Subject: [PATCH 5/7] add EmptyState stories --- .../EmptyState/EmptyState.stories.tsx | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 packages/core/src/components/EmptyState/EmptyState.stories.tsx diff --git a/packages/core/src/components/EmptyState/EmptyState.stories.tsx b/packages/core/src/components/EmptyState/EmptyState.stories.tsx new file mode 100644 index 0000000000..e3902fbd17 --- /dev/null +++ b/packages/core/src/components/EmptyState/EmptyState.stories.tsx @@ -0,0 +1,81 @@ +import { Button } from '@material-ui/core'; +/* + * Copyright 2020 Spotify AB + * + * 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 { EmptyState } from './EmptyState'; + +export default { + title: 'EmptyState', + component: EmptyState, +}; + +const containerStyle = { width: '100%', height: '100vh' }; + +export const MissingAnnotation = () => ( +
+ +
+); + +export const NoInformation = () => ( +
+ +
+); + +export const CreateComponent = () => ( +
+ +
+); + +export const NoBuild = () => ( +
+ +
+); + +export const WithAction = () => ( +
+ {}} variant="contained"> + DOCS + + } + /> +
+); From f6d8a653871474b69adb3fea3f3515bc4ad09f0a Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Tue, 29 Sep 2020 11:11:08 +0200 Subject: [PATCH 6/7] export component --- .../core/src/components/EmptyState/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/core/src/components/EmptyState/index.ts diff --git a/packages/core/src/components/EmptyState/index.ts b/packages/core/src/components/EmptyState/index.ts new file mode 100644 index 0000000000..3774010467 --- /dev/null +++ b/packages/core/src/components/EmptyState/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { EmptyState } from './EmptyState'; From ea1cfdff516925f36252ca72ffefefda2d719db5 Mon Sep 17 00:00:00 2001 From: Samira Mokaram Date: Tue, 29 Sep 2020 14:10:03 +0200 Subject: [PATCH 7/7] resolve comments --- .../EmptyState/EmptyState.stories.tsx | 20 +++++++++---------- .../components/EmptyState/EmptyState.test.tsx | 2 +- .../src/components/EmptyState/EmptyState.tsx | 10 +++++----- .../components/EmptyState/EmptyStateImage.tsx | 14 ++++++------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/core/src/components/EmptyState/EmptyState.stories.tsx b/packages/core/src/components/EmptyState/EmptyState.stories.tsx index e3902fbd17..f3e40bd31c 100644 --- a/packages/core/src/components/EmptyState/EmptyState.stories.tsx +++ b/packages/core/src/components/EmptyState/EmptyState.stories.tsx @@ -1,4 +1,3 @@ -import { Button } from '@material-ui/core'; /* * Copyright 2020 Spotify AB * @@ -17,6 +16,7 @@ import { Button } from '@material-ui/core'; import React from 'react'; import { EmptyState } from './EmptyState'; +import { Button } from '@material-ui/core'; export default { title: 'EmptyState', @@ -28,9 +28,9 @@ const containerStyle = { width: '100%', height: '100vh' }; export const MissingAnnotation = () => (
); @@ -38,9 +38,9 @@ export const MissingAnnotation = () => ( export const NoInformation = () => (
); @@ -48,9 +48,9 @@ export const NoInformation = () => ( export const CreateComponent = () => (
); @@ -58,9 +58,9 @@ export const CreateComponent = () => ( export const NoBuild = () => (
); @@ -68,7 +68,7 @@ export const NoBuild = () => ( export const WithAction = () => (
', () => { const rendered = await renderWithEffects( wrapInTestApp( DOCS} />, diff --git a/packages/core/src/components/EmptyState/EmptyState.tsx b/packages/core/src/components/EmptyState/EmptyState.tsx index f28c8521b0..88becc7c90 100644 --- a/packages/core/src/components/EmptyState/EmptyState.tsx +++ b/packages/core/src/components/EmptyState/EmptyState.tsx @@ -27,7 +27,7 @@ const useStyles = makeStyles(theme => ({ action: { marginTop: theme.spacing(2), }, - imgPlacholder: { + imageContainer: { position: 'relative', }, backgroundImage: { @@ -39,11 +39,11 @@ const useStyles = makeStyles(theme => ({ type Props = { title: string; description?: string; - type: 'missingAnnotation' | 'noInformation' | 'createComponent' | 'noBuild'; + missing: 'field' | 'info' | 'content' | 'data'; action?: JSX.Element; }; -export const EmptyState = ({ title, description, type, action }: Props) => { +export const EmptyState = ({ title, description, missing, action }: Props) => { const classes = useStyles(); return ( { {action} - + background - + ); diff --git a/packages/core/src/components/EmptyState/EmptyStateImage.tsx b/packages/core/src/components/EmptyState/EmptyStateImage.tsx index 082ea8c581..49598ae6db 100644 --- a/packages/core/src/components/EmptyState/EmptyStateImage.tsx +++ b/packages/core/src/components/EmptyState/EmptyStateImage.tsx @@ -22,7 +22,7 @@ import noBuild from './assets/noBuild.svg'; import { makeStyles } from '@material-ui/core'; type Props = { - type: 'missingAnnotation' | 'noInformation' | 'createComponent' | 'noBuild'; + missing: 'field' | 'info' | 'content' | 'data'; }; const useStyles = makeStyles({ @@ -36,10 +36,10 @@ const useStyles = makeStyles({ }, }); -export const EmptyStateImage = ({ type }: Props) => { +export const EmptyStateImage = ({ missing }: Props) => { const classes = useStyles(); - switch (type) { - case 'missingAnnotation': + switch (missing) { + case 'field': return ( { data-testid="missingAnnotation" /> ); - case 'noInformation': + case 'info': return ( { className={classes.generalImg} /> ); - case 'createComponent': + case 'content': return ( { className={classes.generalImg} /> ); - case 'noBuild': + case 'data': return ( no Build );