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

Add defaultSizeKey #129

Merged
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
4 changes: 4 additions & 0 deletions docs/docs/packages/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ interface Handlers {

#### `port?: number`

#### `defaultSizeKey?: string`

The default size type used to represent files. For example, `gzip` or `brotli`.

### Database integration

The following options should generally be handled by a [Build Tracker plugin](/docs/plugins). You can always override them or write your own custom queries and DB setup if you like.
Expand Down
11 changes: 10 additions & 1 deletion src/app/src/store/__tests__/reducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const initialState: State = Object.freeze({
hideAttribution: false,
name: 'Tacos!',
snacks: [],
defaultSizeKey: 'stat',
sizeKey: '',
url: 'https://build-tracker.local'
});
Expand Down Expand Up @@ -90,8 +91,16 @@ describe('reducer', () => {
expect(state.sizeKey).toBe('stat');
});

test('resets the sizeKey if it the current is not in the new set', () => {
test('resets the sizeKey to the default if the current is not in the new set', () => {
const state = reducer({ ...initialState, sizeKey: 'foobar' }, Actions.setBuilds([buildA, buildB]));
expect(state.sizeKey).toBe('stat');
});

test('resets the sizeKey to the first in list if both the current and the default are not in the new set', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

const state = reducer(
{ ...initialState, defaultSizeKey: 'abc', sizeKey: 'foobar' },
Actions.setBuilds([buildA, buildB])
);
expect(state.sizeKey).toBe('gzip');
});

Expand Down
6 changes: 5 additions & 1 deletion src/app/src/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export default function reducer(state: State, action: Actions): State {

const graphType = builds.length <= 10 ? GraphType.STACKED_BAR : state.graphType;

const sizeKey = comparator.sizeKeys.includes(state.sizeKey) ? state.sizeKey : comparator.sizeKeys[0];
const sizeKey = comparator.sizeKeys.includes(state.sizeKey)
? state.sizeKey
: comparator.sizeKeys.includes(state.defaultSizeKey)
? state.defaultSizeKey
: comparator.sizeKeys[0];
return { ...state, activeComparator, activeArtifacts, builds, comparator, graphType, sizeKey };
}

Expand Down
1 change: 1 addition & 0 deletions src/app/src/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface State {
hoveredArtifacts: Array<string>;
name: string;
snacks: Array<string>;
defaultSizeKey?: string;
sizeKey: string;
url: string;
}
Expand Down
3 changes: 2 additions & 1 deletion src/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const props = (config: AppConfig, url: string): RequestHandler => (
url,
artifactConfig: Object.assign({}, { budgets: {}, filters: [], groups: [] }, config.artifacts || {}),
hideAttribution: !!config.hideAttribution,
name: config.name || 'Build Tracker'
name: config.name || 'Build Tracker',
defaultSizeKey: config.defaultSizeKey
};
next();
};
Expand Down
1 change: 1 addition & 0 deletions src/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ export interface AppConfig {
budgets?: Array<Budget>;
hideAttribution?: boolean;
name?: string;
defaultSizeKey?: string;
}