This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from prydonius/restructure
restructuring actions, reducers, etc. to make more composable
- Loading branch information
Showing
32 changed files
with
192 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Dispatch } from 'redux'; | ||
import { createAction, getReturnOfExpression } from 'typesafe-actions'; | ||
|
||
import { StoreState, Chart } from '../shared/types'; | ||
import * as url from '../shared/url'; | ||
|
||
export const requestCharts = createAction('REQUEST_CHARTS'); | ||
export const receiveCharts = createAction('RECEIVE_CHARTS', (charts: Chart[]) => ({ | ||
type: 'RECEIVE_CHARTS', | ||
charts | ||
})); | ||
export const selectChart = createAction('SELECT_CHART', (chart: Chart) => ({ | ||
type: 'SELECT_CHART', | ||
chart | ||
})); | ||
|
||
const allActions = [requestCharts, receiveCharts, selectChart].map(getReturnOfExpression); | ||
export type ChartsAction = typeof allActions[number]; | ||
|
||
export function fetchCharts(repo: string) { | ||
return (dispatch: Dispatch<StoreState>): Promise<{}> => { | ||
dispatch(requestCharts()); | ||
return fetch(url.api.charts.list(repo)) | ||
.then(response => response.json()) | ||
.then(json => dispatch(receiveCharts(json.data))); | ||
}; | ||
} | ||
|
||
export function getChart(id: string) { | ||
return (dispatch: Dispatch<StoreState>): Promise<{}> => { | ||
dispatch(requestCharts()); | ||
return fetch(url.api.charts.get(id)) | ||
.then(response => response.json()) | ||
.then(json => dispatch(selectChart(json.data))); | ||
}; | ||
} | ||
|
||
export function deployChart(chart: Chart, releaseName: string, namespace: string) { | ||
return (dispatch: Dispatch<StoreState>): Promise<{}> => { | ||
return fetch(url.api.helmreleases.create(namespace), { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
apiVersion: 'helm.bitnami.com/v1', | ||
kind: 'HelmRelease', | ||
metadata: { | ||
name: releaseName, | ||
}, | ||
spec: { | ||
repoUrl: chart.attributes.repo.url, | ||
chartName: chart.attributes.name, | ||
version: chart.relationships.latestChartVersion.data.version, | ||
} | ||
}), | ||
}).then(response => response.json()) | ||
.then(json => { | ||
if (json.status === 'Failure') { | ||
throw new Error(json.message); | ||
} | ||
return json; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,5 @@ | ||
import { Dispatch } from 'redux'; | ||
import { createAction, getReturnOfExpression } from 'typesafe-actions'; | ||
import * as charts from './charts'; | ||
|
||
import { StoreState, Chart } from '../store/types'; | ||
|
||
export const requestCharts = createAction('REQUEST_CHARTS'); | ||
export const receiveCharts = createAction('RECEIVE_CHARTS', (charts: Chart[]) => ({ | ||
type: 'RECEIVE_CHARTS', | ||
export default { | ||
charts | ||
})); | ||
export const selectChart = createAction('SELECT_CHART', (chart: Chart) => ({ | ||
type: 'SELECT_CHART', | ||
chart | ||
})); | ||
|
||
export function fetchCharts(repo: string) { | ||
return (dispatch: Dispatch<StoreState>): Promise<{}> => { | ||
dispatch(requestCharts()); | ||
let url = '/api/chartsvc/v1/charts'; | ||
if (repo) { | ||
url = `${url}/${repo}`; | ||
} | ||
return fetch(url) | ||
.then(response => response.json()) | ||
.then(json => dispatch(receiveCharts(json.data))); | ||
}; | ||
} | ||
|
||
export function getChart(id: string) { | ||
return (dispatch: Dispatch<StoreState>): Promise<{}> => { | ||
dispatch(requestCharts()); | ||
return fetch(`/api/chartsvc/v1/charts/${id}`) | ||
.then(response => response.json()) | ||
.then(json => dispatch(selectChart(json.data))); | ||
}; | ||
} | ||
|
||
export function deployChart(chart: Chart, releaseName: string, namespace: string) { | ||
return (dispatch: Dispatch<StoreState>): Promise<{}> => { | ||
return fetch(`/api/kube/apis/helm.bitnami.com/v1/namespaces/${namespace}/helmreleases`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
apiVersion: 'helm.bitnami.com/v1', | ||
kind: 'HelmRelease', | ||
metadata: { | ||
name: releaseName, | ||
}, | ||
spec: { | ||
repoUrl: chart.attributes.repo.url, | ||
chartName: chart.attributes.name, | ||
version: chart.relationships.latestChartVersion.data.version, | ||
} | ||
}), | ||
}).then(response => response.json()) | ||
.then(json => { | ||
if (json.status === 'Failure') { | ||
throw new Error(json.message); | ||
} | ||
return json; | ||
}); | ||
}; | ||
} | ||
|
||
const allActions = [requestCharts, receiveCharts, selectChart].map(getReturnOfExpression); | ||
export type RootAction = typeof allActions[number]; | ||
}; |
2 changes: 1 addition & 1 deletion
2
src/components/ChartIcon.tsx → src/components/ChartIcon/ChartIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ChartIcon from './ChartIcon'; | ||
|
||
export default ChartIcon; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/components/ChartList.tsx → src/components/ChartList/ChartList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
src/components/ChartListItem.tsx → src/components/ChartList/ChartListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ChartList from './ChartList'; | ||
|
||
export default ChartList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/components/ChartView.tsx → src/components/ChartView/ChartView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ChartView from './ChartView'; | ||
|
||
export default ChartView; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Dashboard from './Dashboard'; | ||
|
||
export default Dashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Footer from './Footer'; | ||
|
||
export default Footer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Header from './Header'; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Layout from './Layout'; | ||
|
||
export default Layout; |
2 changes: 1 addition & 1 deletion
2
src/components/Sidebar.tsx → src/components/Sidebar/Sidebar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Sidebar from './Sidebar'; | ||
|
||
export default Sidebar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ChartList from './ChartListContainer'; | ||
|
||
export default ChartList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ChartView from './ChartViewContainer'; | ||
|
||
export default ChartView; |
Oops, something went wrong.