From 7814f83b36187ec94299bced73525c84efc54bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Mon, 7 Oct 2019 02:06:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Switch=20FilterOptions=20to=20us?= =?UTF-8?q?e=20useOvermind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../overmind/namespaces/dashboard/actions.ts | 12 +- .../Filters/FilterOptions/elements.ts | 148 +++++++++--------- .../Sandboxes/Filters/FilterOptions/index.tsx | 101 ++++++------ .../Content/Sandboxes/Filters/index.tsx | 22 +-- .../Dashboard/Content/Sandboxes/index.tsx | 142 +++++++++-------- .../Dashboard/Content/Sandboxes/types.ts | 6 - 6 files changed, 214 insertions(+), 217 deletions(-) delete mode 100644 packages/app/src/app/pages/Dashboard/Content/Sandboxes/types.ts diff --git a/packages/app/src/app/overmind/namespaces/dashboard/actions.ts b/packages/app/src/app/overmind/namespaces/dashboard/actions.ts index c27b0aadf06..7f90eef7296 100755 --- a/packages/app/src/app/overmind/namespaces/dashboard/actions.ts +++ b/packages/app/src/app/overmind/namespaces/dashboard/actions.ts @@ -30,16 +30,16 @@ export const orderByChanged: Action<{ orderBy: OrderBy }> = ( state.dashboard.orderBy = orderBy; }; -export const blacklistedTemplateAdded: Action<{ template: string }> = ( +export const blacklistedTemplateAdded: Action = ( { state }, - { template } + template ) => { state.dashboard.filters.blacklistedTemplates.push(template); }; -export const blacklistedTemplateRemoved: Action<{ template: string }> = ( +export const blacklistedTemplateRemoved: Action = ( { state }, - { template } + template ) => { state.dashboard.filters.blacklistedTemplates = state.dashboard.filters.blacklistedTemplates.filter( currentTemplate => currentTemplate !== template @@ -50,9 +50,9 @@ export const blacklistedTemplatesCleared: Action = ({ state }) => { state.dashboard.filters.blacklistedTemplates = []; }; -export const blacklistedTemplatesChanged: Action<{ templates: string[] }> = ( +export const blacklistedTemplatesChanged: Action = ( { state }, - { templates } + templates ) => { state.dashboard.filters.blacklistedTemplates = templates; }; diff --git a/packages/app/src/app/pages/Dashboard/Content/Sandboxes/Filters/FilterOptions/elements.ts b/packages/app/src/app/pages/Dashboard/Content/Sandboxes/Filters/FilterOptions/elements.ts index f0c1e5edc8f..adfc226c56c 100644 --- a/packages/app/src/app/pages/Dashboard/Content/Sandboxes/Filters/FilterOptions/elements.ts +++ b/packages/app/src/app/pages/Dashboard/Content/Sandboxes/Filters/FilterOptions/elements.ts @@ -1,20 +1,21 @@ import styled, { css } from 'styled-components'; export const Container = styled.div<{ hideFilters: boolean }>` - transition: 0.3s ease opacity; - position: relative; - color: rgba(255, 255, 255, 0.6); - font-size: 0.875rem; - - margin-right: 1rem; - vertical-align: middle; - - ${props => - props.hideFilters && - css` - opacity: 0.5; - pointer-events: none; - `}; + ${({ hideFilters }) => css` + transition: 0.3s ease opacity; + position: relative; + color: rgba(255, 255, 255, 0.6); + font-size: 0.875rem; + + margin-right: 1rem; + vertical-align: middle; + + ${hideFilters && + css` + opacity: 0.5; + pointer-events: none; + `}; + `}; `; export const TemplatesName = styled.span` @@ -29,21 +30,23 @@ export const TemplatesName = styled.span` `; export const OverlayContainer = styled.div` - overflow: hidden; - box-sizing: border-box; - right: 0; - text-align: left; - line-height: 1.6; - width: 300px; - padding: 1rem; - z-index: 10; - color: rgba(255, 255, 255, 0.8); - font-size: 0.875rem; - - border-radius: 2px; - box-shadow: 0 3px 3px rgba(0, 0, 0, 0.3); - - background-color: ${props => props.theme.background}; + ${({ theme }) => css` + overflow: hidden; + box-sizing: border-box; + right: 0; + text-align: left; + line-height: 1.6; + width: 300px; + padding: 1rem; + z-index: 10; + color: rgba(255, 255, 255, 0.8); + font-size: 0.875rem; + + border-radius: 2px; + box-shadow: 0 3px 3px rgba(0, 0, 0, 0.3); + + background-color: ${theme.background}; + `}; `; export const OptionName = styled.span` @@ -52,62 +55,61 @@ export const OptionName = styled.span` `; export const Option = styled.div<{ selected: boolean }>` - transition: 0.3s ease color; - cursor: pointer; - color: ${props => - props.theme.light ? 'rgba(0, 0, 0, 0.7)' : 'rgba(255, 255, 255, 0.7)'}; + ${({ selected, theme }) => css` + transition: 0.3s ease color; + cursor: pointer; + color: ${theme.light ? 'rgba(0, 0, 0, 0.7)' : 'rgba(255, 255, 255, 0.7)'}; - margin-bottom: 0.25rem; + margin-bottom: 0.25rem; - &:hover { - color: rgba(255, 255, 255, 0.9); + &:hover { + color: rgba(255, 255, 255, 0.9); - ${props => - !props.selected && - css` - span { - border-color: rgba(255, 255, 255, 0.1); - } - `}; - } + ${!selected && + css` + span { + border-color: rgba(255, 255, 255, 0.1); + } + `}; + } - &:last-child { - margin-bottom: 0; - } + &:last-child { + margin-bottom: 0; + } - ${props => - props.selected && - css` - color: white; - `}; + ${selected && + css` + color: white; + `}; + `}; `; -export const CheckBox = styled.span<{ selected: boolean; color: string }>` - ${props => - props.selected +export const CheckBox = styled.span<{ color: string; selected: boolean }>` + ${({ color, selected }) => css` + ${selected ? css` - background: ${props.color} url('') no-repeat 50%/10px; + background: ${color} url('') no-repeat 50%/10px; background-image: url("data:image/svg+xml;utf8,"); ` : css` background: rgba(0, 0, 0, 0.3) url('') no-repeat 50%/10px; background-image: url("data:image/svg+xml;utf8, = ({ +}; +export const FilterOptions: FunctionComponent = ({ possibleTemplates, hideFilters, -}: IFilterOptionsProps) => { +}) => { const { - state: { - dashboard: { isTemplateSelected, filters }, - }, actions: { dashboard: { blacklistedTemplateAdded, blacklistedTemplateRemoved, - blacklistedTemplatesCleared, blacklistedTemplatesChanged, + blacklistedTemplatesCleared, + }, + }, + state: { + dashboard: { + filters: { blacklistedTemplates }, + isTemplateSelected, }, }, } = useOvermind(); const toggleTemplate = (name: string, select: boolean) => - select - ? blacklistedTemplateRemoved({ - template: name, - }) - : blacklistedTemplateAdded({ - template: name, - }); - - const allSelected = possibleTemplates.every(t => isTemplateSelected(t.id)); + select ? blacklistedTemplateRemoved(name) : blacklistedTemplateAdded(name); + const allSelected = possibleTemplates.every(({ id }) => + isTemplateSelected(id) + ); const Overlay = () => ( {possibleTemplates.length > 0 ? ( <> - {orderBy(possibleTemplates, 'niceName').map(template => { - const selected = isTemplateSelected(template.id); + {orderBy(possibleTemplates, 'niceName').map( + ({ color, id, name, niceName }) => { + const selected = isTemplateSelected(id); - return ( - - ); - })} + return ( + + ); + } + )} ); - const { blacklistedTemplates } = filters; const templateCount = possibleTemplates.length - blacklistedTemplates.length; const templateMessage = templateCount === possibleTemplates.length && templateCount > 0 @@ -92,7 +97,7 @@ const FilterOptionsComponent: React.FC = ({ }`; return ( - + {open => ( Showing{' '} @@ -102,5 +107,3 @@ const FilterOptionsComponent: React.FC = ({ ); }; - -export const FilterOptions = FilterOptionsComponent; diff --git a/packages/app/src/app/pages/Dashboard/Content/Sandboxes/Filters/index.tsx b/packages/app/src/app/pages/Dashboard/Content/Sandboxes/Filters/index.tsx index 2c4d8c9f967..e512bf3cb56 100644 --- a/packages/app/src/app/pages/Dashboard/Content/Sandboxes/Filters/index.tsx +++ b/packages/app/src/app/pages/Dashboard/Content/Sandboxes/Filters/index.tsx @@ -1,27 +1,27 @@ -import React from 'react'; +import React, { ComponentProps, FunctionComponent } from 'react'; import { SortOptions } from './SortOptions'; import { FilterOptions } from './FilterOptions'; import { Container } from './elements'; -import { ITemplate } from '../types'; -interface Props { - possibleTemplates: ITemplate[]; +type Props = { hideOrder?: boolean; - hideFilters?: boolean; -} - -export const Filters = ({ - possibleTemplates, - hideOrder, +} & Pick< + ComponentProps, + 'hideFilters' | 'possibleTemplates' +>; +export const Filters: FunctionComponent = ({ hideFilters, -}: Props) => ( + hideOrder, + possibleTemplates, +}) => ( + ); diff --git a/packages/app/src/app/pages/Dashboard/Content/Sandboxes/index.tsx b/packages/app/src/app/pages/Dashboard/Content/Sandboxes/index.tsx index 303ba10bda1..5933ee86632 100644 --- a/packages/app/src/app/pages/Dashboard/Content/Sandboxes/index.tsx +++ b/packages/app/src/app/pages/Dashboard/Content/Sandboxes/index.tsx @@ -1,87 +1,85 @@ -import React from 'react'; +import React, { ComponentProps, ComponentType, FunctionComponent } from 'react'; + import { DelayedAnimation } from 'app/components/DelayedAnimation'; + import { Container, HeaderContainer, HeaderTitle } from '../elements'; import { SandboxGrid } from '../SandboxGrid'; -import { Filters } from './Filters'; + import { DashboardActions } from './Actions'; -import { ITemplate } from './types'; +import { Filters } from './Filters'; -interface Props { +type Props = { sandboxes: any[]; - Header: React.ComponentType; - SubHeader: React.ComponentType; - ExtraElement: React.ComponentType; + Header: ComponentType; + SubHeader: ComponentType; + ExtraElement: ComponentType; - possibleTemplates: ITemplate[]; isLoading?: boolean; - hideOrder?: boolean; - hideFilters?: boolean; page?: number; actions?: any[]; -} - -// eslint-disable-next-line react/prefer-stateless-function -export class Content extends React.Component { - render() { - const { - sandboxes, - Header, - SubHeader, - isLoading, - ExtraElement, - hideOrder, - hideFilters, - possibleTemplates = [], - page, - actions = [], - } = this.props; - - return ( - - - - {Header}{' '} - {sandboxes && !isLoading && ( - - {sandboxes.length} - - )} - - - - - {SubHeader} - {isLoading ? ( - , + 'hideFilters' | 'hideOrder' | 'possibleTemplates' +>; +export const Content: FunctionComponent = ({ + sandboxes, + Header, + SubHeader, + isLoading, + ExtraElement, + hideOrder, + hideFilters, + possibleTemplates = [], + page, + actions = [], +}) => ( + + + + {Header}{' '} + {sandboxes && !isLoading && ( + - Fetching Sandboxes... - - ) : ( - + {sandboxes.length} + )} - - ); - } -} + + + + + + + + {SubHeader} + + {isLoading ? ( + + Fetching Sandboxes... + + ) : ( + + )} + +); diff --git a/packages/app/src/app/pages/Dashboard/Content/Sandboxes/types.ts b/packages/app/src/app/pages/Dashboard/Content/Sandboxes/types.ts deleted file mode 100644 index 9a3cd839ab1..00000000000 --- a/packages/app/src/app/pages/Dashboard/Content/Sandboxes/types.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface ITemplate { - id: string; - name: string; - color: string; - niceName: string; -}