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

Enforce types #154

Merged
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0df8153
chore: move constants to central location
D-B-Hawk Apr 5, 2023
28e3810
chore: place overrides in declaration.d.ts file for accurate ts autoc…
D-B-Hawk Apr 5, 2023
e21e21e
chore: place utils in central location. add GithubUser,GithubUserPlan…
D-B-Hawk Apr 5, 2023
8a3ce61
refactor: update readiness slice to a more descriptive variable descr…
D-B-Hawk Apr 5, 2023
a3281eb
chore: remove selectors. state selection exposed by useAppSelector.
D-B-Hawk Apr 5, 2023
805c023
refactor: githubApi axed. githubUser slice state houses pertinent git…
D-B-Hawk Apr 5, 2023
3b6ea41
chore: getUser, getUserOrganization thunks made with tests to verify …
D-B-Hawk Apr 5, 2023
50748ea
chore: enforce types
D-B-Hawk Apr 5, 2023
24f0e80
refactor: update installation slice
D-B-Hawk Apr 6, 2023
ecdb6fc
chore: update some hooks
D-B-Hawk Apr 6, 2023
a327024
refactor: make controlled fields pass generic type to control for pro…
D-B-Hawk Apr 6, 2023
739efbd
refactor: a button is a button
D-B-Hawk Apr 6, 2023
5b232cf
chore: more accurate description of what component actually is
D-B-Hawk Apr 6, 2023
1cea010
chore: pull InstallationButtons into separate comp
D-B-Hawk Apr 6, 2023
80401a5
chore: pull InstallationCard into its own component
D-B-Hawk Apr 6, 2023
33235e7
chore: pull InstallationInfoCard into separate comp
D-B-Hawk Apr 6, 2023
47a4095
chore: create InstallationStepContainer
D-B-Hawk Apr 6, 2023
30bd7f9
chore: layout comps, odds and ends. no inherent comp styles to throw …
D-B-Hawk Apr 6, 2023
98011fa
refactor: update LocalSetupForm and LocalFormFlow
D-B-Hawk Apr 6, 2023
26d1c10
refactor: update aws github forms and flow.
D-B-Hawk Apr 6, 2023
b33575d
refactor: update aws gitlab forms and install flow
D-B-Hawk Apr 6, 2023
ba7821d
chore: add civo github readiness, setup forms and install flow
D-B-Hawk Apr 6, 2023
9a5a5c3
chore: add civo gitlab readiness, setup forms and install flow.
D-B-Hawk Apr 6, 2023
ab56cec
chore: remove dashboard implementation. layout change simplification.…
D-B-Hawk Apr 6, 2023
2b7e9f6
loosely hooked up installations for existing options. installations s…
D-B-Hawk Apr 6, 2023
d37569a
chore: merge conflicts
D-B-Hawk Apr 10, 2023
cd12d1e
fix: have forms validate before advancing step.
D-B-Hawk Apr 13, 2023
dae4572
chore: create NextLink comp because Link provided by next does not in…
D-B-Hawk Apr 13, 2023
b2ec077
fix: strip and import styles from .styled files. lowercase naming for…
D-B-Hawk Apr 14, 2023
09960c9
fix: pin node@16.15.1. nuke node_modules and re-install
D-B-Hawk Apr 14, 2023
bfe7022
fix: rename slices based off of pr review note. renamed getters and p…
D-B-Hawk Apr 14, 2023
d4994d1
fix: export generated hooks. add proper arg types to api mutations. s…
D-B-Hawk Apr 14, 2023
86a8f03
fix: drop form/form flow stories. seperate/import styles. move logic …
D-B-Hawk Apr 16, 2023
0691866
coerce boolean|undefined value to string for accepted input value.
D-B-Hawk Apr 16, 2023
b5c935d
adds updates to civo github
jarededwards Apr 19, 2023
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
Prev Previous commit
Next Next commit
refactor: update installation slice
D-B-Hawk committed Apr 6, 2023
commit 24f0e807cb518c60dbfeb7ba138d644a973a026c
24 changes: 0 additions & 24 deletions redux/actions/readiness.action.ts

This file was deleted.

10 changes: 0 additions & 10 deletions redux/actions/telemetry.action.ts

This file was deleted.

39 changes: 39 additions & 0 deletions redux/slices/__tests__/installation.slice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { installationReducer, setLocalInstallState, initialState } from '../installation.slice';

describe('redux/slices/installation.slice', () => {
test('setLocalInstallState works as expected', () => {
const localPayload = { githubToken: 'token' };

const updatedState = installationReducer(initialState, setLocalInstallState(localPayload));

expect(updatedState.local).toStrictEqual(localPayload);
});
test('setLocalInstallState will not overwrite existing local state', () => {
const reduxState = {
...initialState,
local: { ...initialState.local, githubToken: 'token' },
};

const localPayload = { gitOpsBranch: 'main' };

const updatedState = installationReducer(reduxState, setLocalInstallState(localPayload));

expect(updatedState.local).toStrictEqual({
githubToken: 'token',
gitOpsBranch: 'main',
});
});
test('setLocalInstallState will need to be passed undefined value to remove existing local value', () => {
const reduxState = {
...initialState,
local: { ...initialState.local, githubToken: 'token' },
};

const updatedState = installationReducer(
reduxState,
setLocalInstallState({ githubToken: undefined }),
);

expect(updatedState.local).toEqual({ githubToken: undefined });
});
});
4 changes: 4 additions & 0 deletions redux/slices/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { validMetaphorSitesReducer } from './validMetaphorSites.slice';
export { githubUserReducer } from './githubUser.slice';
export { configReducer } from './config.slice';
export { installationReducer } from './installation.slice';
112 changes: 60 additions & 52 deletions redux/slices/installation.slice.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,80 @@
import { createSlice } from '@reduxjs/toolkit';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

import { AWS_GIT_STEPS } from '../../enums/installation';

type LocalInstallation = {
githubToken: string;
gitOpsBranch: string;
templateRepoUrl: string;
};

type AWSGitInstallation = {
step: number;
profile?: string;
hostedZoneName?: string;
adminEmail?: string;
kbotPassword?: string;
region?: string;
clusterName?: string;
bucketName?: string;
githubToken?: string;
githubOrganization?: string;
awsNodesSpot?: boolean;
};
import {
LocalInstallValues,
InstallationType,
CivoGithubClusterValues,
AwsGithubClusterValues,
AwsClusterValues,
CivoClusterValues,
} from '../../types/redux';

export interface InstallationState {
local?: LocalInstallation;
awsGit?: AWSGitInstallation;
local?: LocalInstallValues;
awsGithub?: AwsGithubClusterValues;
awsGitlab?: AwsClusterValues;
civoGithub?: CivoGithubClusterValues;
civoGitlab?: CivoClusterValues;
installType: InstallationType;
installationStep: number;
}

export const initialState: InstallationState = {
local: undefined,
awsGit: undefined,
installType: InstallationType.LOCAL,
installationStep: 0,
};

const installationSlice = createSlice({
name: 'installation',
initialState,
reducers: {
setLocalValues(state, { payload }) {
const { githubToken, gitOpsBranch, templateRepoUrl } = payload;
setInstallationStep: (state, action: PayloadAction<number>) => {
state.installationStep = action.payload;
},
setLocalInstallState: (state, action: PayloadAction<LocalInstallValues>) => {
state.local = {
githubToken: githubToken,
gitOpsBranch: gitOpsBranch,
templateRepoUrl: templateRepoUrl,
...state.local,
...action.payload,
};
},
setAWSGitValues(state, { payload }) {
const { step } = payload;

if (step === AWS_GIT_STEPS.READINESS) {
const { profile, hostedZoneName } = payload;

state.awsGit = {
step,
profile,
hostedZoneName,
...state.awsGit,
};
} else if (step === AWS_GIT_STEPS.SETUP) {
state.awsGit = {
...payload,
...state.awsGit,
step,
};
}
setAWSGithubInstallState: (state, action: PayloadAction<AwsGithubClusterValues>) => {
state.awsGithub = {
...state.awsGithub,
...action.payload,
};
},
setAWSGitlabInstallState: (state, action: PayloadAction<AwsClusterValues>) => {
state.awsGitlab = {
...state.awsGitlab,
...action.payload,
};
},
setCivoGithubInstallState: (state, action: PayloadAction<CivoGithubClusterValues>) => {
state.civoGithub = {
...state.civoGithub,
...action.payload,
};
},
setCivoGitlabInstallState: (state, action: PayloadAction<CivoClusterValues>) => {
state.civoGitlab = {
...state.civoGitlab,
...action.payload,
};
},
setInstallType: (state, action: PayloadAction<InstallationType>) => {
state.installType = action.payload;
},
},
});

export const { setAWSGitValues, setLocalValues } = installationSlice.actions;
export const {
setInstallationStep,
setLocalInstallState,
setAWSGithubInstallState,
setAWSGitlabInstallState,
setCivoGithubInstallState,
setCivoGitlabInstallState,
setInstallType,
} = installationSlice.actions;

export default installationSlice.reducer;
export const installationReducer = installationSlice.reducer;
6 changes: 5 additions & 1 deletion redux/slices/validMetaphorSites.slice.ts
Original file line number Diff line number Diff line change
@@ -33,7 +33,11 @@ const validMetaphorSitesSlice = createSlice({
})
.addCase(checkReadiness.rejected, (state, action) => {
state.loading = false;
state.error = action.error.message ?? 'failed to check readiness';
if (action.payload) {
state.error = action.payload;
} else {
state.error = action.error.message ?? 'failed to check readiness';
}
});
},
});
20 changes: 10 additions & 10 deletions redux/store.ts
Original file line number Diff line number Diff line change
@@ -3,21 +3,21 @@ import { Action, configureStore, ThunkAction } from '@reduxjs/toolkit';
import { createWrapper } from 'next-redux-wrapper';

import { consoleApi } from './api';
// ToDo: we need to have just one api
// import { githubApi } from './api/github';
import configSlice from './slices/config.slice';
import installationSlice from './slices/installation.slice';
import githubSlice from './slices/github.slice';
import readinesSlice from './slices/readiness.slice';
import {
githubUserReducer,
configReducer,
installationReducer,
validMetaphorSitesReducer,
} from './slices';

export const makeStore = () =>
configureStore({
reducer: {
[consoleApi.reducerPath]: consoleApi.reducer,
config: configSlice,
installation: installationSlice,
github: githubSlice,
readiness: readinesSlice,
config: configReducer,
installation: installationReducer,
githubUser: githubUserReducer,
validMetaphorSites: validMetaphorSitesReducer,
},
middleware: (gDM) => gDM().concat(consoleApi.middleware),
});
21 changes: 21 additions & 0 deletions redux/thunks/readiness.thunk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createAsyncThunk } from '@reduxjs/toolkit';

import { getErrorMessage } from '../../utils/getErrorMessage';

export const checkReadiness = createAsyncThunk<string, string, { rejectValue: string }>(
'valid-metaphor-sites/check',
async (url, { rejectWithValue }) => {
if (url.includes('localdev.me')) {
try {
const res = await fetch(url, { mode: 'no-cors' });
if (!res.ok) {
throw Error('unable to ping url');
}
return url;
} catch (error) {
throw Error(getErrorMessage(error, 'check readiness fail'));
}
}
return rejectWithValue('url does not include localdev.me');
},
);
45 changes: 45 additions & 0 deletions types/redux/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { GithubUserOrganization } from '../github';

export interface GithubValues {
githubToken?: string;
githubOrganization?: GithubUserOrganization['login'];
}

export interface LocalInstallValues extends GithubValues {
gitOpsBranch?: string;
templateRepoUrl?: string;
}

export interface ClusterValues {
adminEmail?: string;
kbotPassword?: string;
region?: string;
clusterName?: string;
}

export interface AwsInstallValues {
profile?: string;
awsNodesSpot?: boolean;
hostedZoneValid?: boolean;
hostedZoneName?: string;
}

export type AwsClusterValues = AwsInstallValues & ClusterValues;

export type AwsGithubClusterValues = AwsClusterValues & GithubValues;

export interface CivoInstallValues {
hostedDomainName?: string;
hostedDomainValid?: boolean;
civoToken?: string;
}
export type CivoClusterValues = CivoInstallValues & ClusterValues;
export type CivoGithubClusterValues = CivoClusterValues & GithubValues;

export enum InstallationType {
LOCAL = 'local',
AWS_GITHUB = 'aws-github',
AWS_GITLAB = 'aws-gitlab',
CIVO_GITHUB = 'civo-github',
CIVO_GITLAB = 'civo-gitlab',
}
16 changes: 16 additions & 0 deletions utils/getErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function getErrorMessage(error: unknown, defaultMessage: string): string {
if (error instanceof Error) {
return error.message;
}

if (
error &&
typeof error === 'object' &&
'message' in error &&
typeof error.message === 'string'
) {
return error.message;
}

return defaultMessage;
}