Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes allowing user to toggle between show all branches #141

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Storage = {
KUBECONFIG_CONTEXT: 'KUBECONFIG_CONTEXT',
RELEASE_NAME: 'RELEASE_NAME',
OPS_PATH: 'OPS_PATH',
SHOW_ALL_BRANCHES: 'SHOW_ALL_BRANCHES',
PASSWORD_KEY: generateUUID()
}

Expand Down
13 changes: 11 additions & 2 deletions src/renderer/components/GitView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Channels from 'constants/Channels'
import Storage from 'constants/Storage'
import { cloneCluster } from 'models/Cluster'
import { useSnackbar } from 'notistack'
import { useConfigFileState } from 'renderer/services/ConfigFileService'
Expand Down Expand Up @@ -42,9 +43,17 @@ const GitView = ({ name, repoType, sx }: Props) => {
let branches: string[] = []
const gitData = currentDeployment.gitStatus[repoType].data
if (gitData) {
const allowedBranches = ['dev', '/dev', 'master', '/master']
const showAllBranches = localStorage.getItem(Storage.SHOW_ALL_BRANCHES) ?? 'false'

branches = gitData.branches.filter((item) => allowedBranches.some((allowed) => item.endsWith(allowed)))
if (showAllBranches === 'true') {
branches = gitData.branches.map((item) => item) // Doing map here so that a clone is created rather than referencing original object
} else {
const allowedBranches = ['dev', '/dev', 'master', '/master']
branches = gitData.branches.filter((item) => allowedBranches.some((allowed) => item.endsWith(allowed)))
}

console.log(branches)
console.log(gitData.tags)
branches.push(...gitData.tags)

const current = gitData.current
Expand Down
33 changes: 33 additions & 0 deletions src/renderer/components/Setting/AdditionalConfigsView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Storage from 'constants/Storage'

import { Box, FormControlLabel, Switch, SxProps, Theme, Typography } from '@mui/material'

import InfoTooltip from '../../common/InfoTooltip'

interface Props {
localFlags: Record<string, string>
onChange: (key: string, value: string) => void
sx?: SxProps<Theme>
}

const AdditionalConfigsView = ({ localFlags, onChange, sx }: Props) => {
return (
<Box sx={sx}>
<FormControlLabel
labelPlacement="start"
label={
<Box sx={{ display: 'flex', alignItems: 'top', flexDirection: 'row' }}>
<Typography variant="body2">{Storage.SHOW_ALL_BRANCHES.replaceAll('_', ' ')}</Typography>
<InfoTooltip message="This will show all Ethereal Engine branches. If switched off then it will show only dev & master branches." />
</Box>
}
sx={{ marginTop: 1, marginLeft: 0 }}
control={<Switch checked={localFlags[Storage.SHOW_ALL_BRANCHES] === 'true'} sx={{ marginLeft: 4 }} />}
value={localFlags[Storage.SHOW_ALL_BRANCHES] === 'true'}
onChange={(_event, checked) => onChange(Storage.SHOW_ALL_BRANCHES, checked ? 'true' : 'false')}
/>
</Box>
)
}

export default AdditionalConfigsView
24 changes: 23 additions & 1 deletion src/renderer/dialogs/SettingsDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Storage from 'constants/Storage'
import UIEnabled from 'constants/UIEnabled'
import { ClusterModel, ClusterType } from 'models/Cluster'
import { useSnackbar } from 'notistack'
import { useState } from 'react'
import AdditionalConfigsView from 'renderer/components/Setting/AdditionalConfigsView'
import MicroK8sView from 'renderer/components/Setting/MicroK8sView'
import { ConfigFileService, useConfigFileState } from 'renderer/services/ConfigFileService'
import { DeploymentService } from 'renderer/services/DeploymentService'
Expand Down Expand Up @@ -45,6 +47,12 @@ const SettingsDialog = ({ onClose }: Props) => {
const [tempConfigs, setTempConfigs] = useState({} as Record<string, string>)
const [tempVars, setTempVars] = useState({} as Record<string, string>)

const showAllBranches = localStorage.getItem(Storage.SHOW_ALL_BRANCHES) as string | undefined
const defaultFlags = {
[Storage.SHOW_ALL_BRANCHES]: showAllBranches ? showAllBranches : 'false'
} as Record<string, string>
const [localFlags, setLocalFlags] = useState(defaultFlags)

if (!selectedCluster) {
enqueueSnackbar('Please select a cluster.', { variant: 'error' })
onClose()
Expand All @@ -61,6 +69,12 @@ const SettingsDialog = ({ onClose }: Props) => {
localVars[key] = key in tempVars ? tempVars[key] : selectedCluster.variables[key]
}

const changeFlag = async (key: string, value: string) => {
const newFlags = { ...localFlags }
newFlags[key] = value
setLocalFlags(newFlags)
}

const changeConfig = async (key: string, value: string) => {
const newConfigs = { ...tempConfigs }
newConfigs[key] = value
Expand Down Expand Up @@ -88,6 +102,8 @@ const SettingsDialog = ({ onClose }: Props) => {
updatedCluster.variables[key] = tempVars[key]
}

localStorage.setItem(Storage.SHOW_ALL_BRANCHES, localFlags[Storage.SHOW_ALL_BRANCHES])

const saved = await ConfigFileService.insertOrUpdateConfig(updatedCluster)
if (saved) {
onClose()
Expand Down Expand Up @@ -129,6 +145,7 @@ const SettingsDialog = ({ onClose }: Props) => {
onChange={changeConfig}
sx={{ display: 'flex', flexDirection: 'column', alignItems: 'start' }}
/>
<AdditionalConfigsView localFlags={localFlags} onChange={changeFlag} />
</TabPanel>
)}
{UIEnabled[selectedCluster.type].settings.variables && (
Expand Down Expand Up @@ -176,7 +193,12 @@ const SettingsDialog = ({ onClose }: Props) => {
<Button onClick={onClose}>Cancel</Button>
<Button
type="submit"
disabled={loading || (Object.keys(tempConfigs).length === 0 && Object.keys(tempVars).length === 0)}
disabled={
loading ||
(Object.keys(tempConfigs).length === 0 &&
Object.keys(tempVars).length === 0 &&
JSON.stringify(defaultFlags) === JSON.stringify(localFlags))
}
onClick={saveSettings}
>
Save
Expand Down