Skip to content

Commit

Permalink
feat: create New Resource wizard component and logic to open from nav…
Browse files Browse the repository at this point in the history
…igator titlebar
  • Loading branch information
devcatalin committed Aug 25, 2021
1 parent fd8f7ed commit 90a12de
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
StartupModal,
HotKeysHandler,
PaneManager,
NewResourceWizard,
} from '@organisms';
import {Size} from '@models/window';
import {useWindowSize} from '@utils/hooks';
Expand Down Expand Up @@ -39,6 +40,7 @@ const App = () => {
</Layout>
<DiffModal />
<StartupModal />
<NewResourceWizard />
<HotKeysHandler />
</div>
</AppContext.Provider>
Expand Down
33 changes: 28 additions & 5 deletions src/components/organisms/NavigatorPane/NavigatorPane.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React, {useState, useContext, useEffect} from 'react';
import {Row, Skeleton} from 'antd';
import {Row, Skeleton, Button} from 'antd';
import styled from 'styled-components';
import {useSelector} from 'react-redux';
import {isInClusterModeSelector, helmChartsSelector, helmValuesSelector, kustomizationsSelector} from '@redux/selectors';
import {
isInClusterModeSelector,
helmChartsSelector,
helmValuesSelector,
kustomizationsSelector,
} from '@redux/selectors';

import {HelmValuesFile} from '@models/helm';
import Colors, {BackgroundColors} from '@styles/Colors';
import {useAppSelector} from '@redux/hooks';
import {useAppSelector, useAppDispatch} from '@redux/hooks';
import {MonoPaneTitle, MonoPaneTitleCol, PaneContainer, MonoSectionTitle} from '@atoms';
import {MinusSquareOutlined, PlusSquareOutlined} from '@ant-design/icons';
import {MinusSquareOutlined, PlusSquareOutlined, PlusOutlined} from '@ant-design/icons';
import {openNewResourceWizard} from '@redux/reducers/ui';

import {NAVIGATOR_HEIGHT_OFFSET} from '@constants/constants';

Expand Down Expand Up @@ -79,10 +85,17 @@ const TitleBarContainer = styled.div`
justify-content: space-between;
`;

const RightButtons = styled.div`
float: right;
display: flex;
`;

const NavigatorPaneContainer = styled(PaneContainer)`
white-space: nowrap;
`;

const StyledPlusButton = styled(Button)``;

const SectionHeader = (props: {
title: string;
isExpanded: boolean;
Expand Down Expand Up @@ -120,6 +133,7 @@ const SectionHeader = (props: {
};

const NavigatorPane = () => {
const dispatch = useAppDispatch();
const {windowSize} = useContext(AppContext);
const windowHeight = windowSize.height;
const navigatorHeight = windowHeight - NAVIGATOR_HEIGHT_OFFSET;
Expand Down Expand Up @@ -147,6 +161,10 @@ const NavigatorPane = () => {
return expandedSections.indexOf(sectionName) !== -1;
};

const onClickNewResource = () => {
dispatch(openNewResourceWizard());
};

useEffect(() => {
if (kustomizations.some(kustomization => kustomization.id === selectedResourceId)) {
expandSection('kustomizations');
Expand All @@ -160,6 +178,9 @@ const NavigatorPane = () => {
<MonoPaneTitle>
<TitleBarContainer>
<span>Navigator</span>
<RightButtons>
<StyledPlusButton onClick={onClickNewResource} type="link" size="small" icon={<PlusOutlined />} />
</RightButtons>
</TitleBarContainer>
</MonoPaneTitle>
</MonoPaneTitleCol>
Expand All @@ -186,7 +207,9 @@ const NavigatorPane = () => {
isSelected={
!isSectionExpanded('helmcharts') &&
Object.values(helmCharts).some(h =>
h.valueFileIds.map(v => helmValues[v]).some((valuesFile: HelmValuesFile) => valuesFile.isSelected)
h.valueFileIds
.map(v => helmValues[v])
.some((valuesFile: HelmValuesFile) => valuesFile.isSelected)
)
}
/>
Expand Down
35 changes: 35 additions & 0 deletions src/components/organisms/NewResourceWizard/NewResourceWizard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import {Modal, Form, Input, Select} from 'antd';
import {InfoCircleOutlined} from '@ant-design/icons';
import {useAppSelector, useAppDispatch} from '@redux/hooks';
import {closeNewResourceWizard} from '@redux/reducers/ui';

const NewResourceWizard = () => {
const dispatch = useAppDispatch();
const isNewResourceWizardOpen = useAppSelector(state => state.ui.isNewResourceWizardOpen);

const onCancel = () => {
dispatch(closeNewResourceWizard());
};

return (
<Modal title="Add New Resource" visible={isNewResourceWizardOpen} onCancel={onCancel}>
<Form layout="vertical">
<Form.Item label="Name" required>
<Input />
</Form.Item>
<Form.Item label="Kind" required tooltip={{title: 'Select the resource kind', icon: <InfoCircleOutlined />}}>
<Select />
</Form.Item>
<Form.Item label="Version" tooltip={{title: 'Enter the version', icon: <InfoCircleOutlined />}}>
<Input />
</Form.Item>
<Form.Item label="Namespace" tooltip={{title: 'Select the namespace', icon: <InfoCircleOutlined />}}>
<Select />
</Form.Item>
</Form>
</Modal>
);
};

export default NewResourceWizard;
1 change: 1 addition & 0 deletions src/components/organisms/NewResourceWizard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from './NewResourceWizard';
1 change: 1 addition & 0 deletions src/components/organisms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export {default as PageHeader} from './PageHeader';
export {default as SettingsDrawer} from './SettingsDrawer';
export {default as HotKeysHandler} from './HotKeysHandler';
export {default as PaneManager} from './PaneManager';
export {default as NewResourceWizard} from './NewResourceWizard';
1 change: 1 addition & 0 deletions src/models/ui.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type UiState = {
isSettingsOpen: boolean;
isNewResourceWizardOpen: boolean;
isFolderLoading: boolean;
leftMenu: {
selection: string;
Expand Down
1 change: 1 addition & 0 deletions src/redux/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const initialLogsState: LogsState = {
const initialUiState: UiState = {
isSettingsOpen: false,
isFolderLoading: false,
isNewResourceWizardOpen: false,
leftMenu: {
selection: 'file-explorer',
isActive: true,
Expand Down
17 changes: 15 additions & 2 deletions src/redux/reducers/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export const uiSlice = createSlice({
setRightMenuSelection: (state: Draft<UiState>, action: PayloadAction<string>) => {
state.rightMenu.selection = action.payload;
},
openNewResourceWizard: (state: Draft<UiState>) => {
state.isNewResourceWizardOpen = true;
},
closeNewResourceWizard: (state: Draft<UiState>) => {
state.isNewResourceWizardOpen = false;
},
},
extraReducers: builder => {
builder
Expand All @@ -37,6 +43,13 @@ export const uiSlice = createSlice({
},
});

export const {toggleSettings, toggleLeftMenu, toggleRightMenu, setLeftMenuSelection, setRightMenuSelection} =
uiSlice.actions;
export const {
toggleSettings,
toggleLeftMenu,
toggleRightMenu,
setLeftMenuSelection,
setRightMenuSelection,
openNewResourceWizard,
closeNewResourceWizard,
} = uiSlice.actions;
export default uiSlice.reducer;

0 comments on commit 90a12de

Please sign in to comment.