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

Storybook #509

Merged
merged 20 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9eadf99
frontend: Add icons into repo, stop regenerating
illume Oct 18, 2021
6503620
frontend: Remove unecessary src/js folder, move files
illume Oct 18, 2021
5393876
frontend: Move Main..tsx to Main.tsx
illume Oct 19, 2021
254c1e6
frontend: Add in themes.ts handling from Headlamp
illume Oct 19, 2021
49832b6
frontend: Add storybook configuration
illume Oct 19, 2021
c9cfd75
frontend: Add storyshots for testing
illume Oct 19, 2021
128a0cf
frontend: Add Card.stories to replace Card.spec.js
illume Oct 20, 2021
5ad9340
frontend ColorPicker: Add stories and interface docs
illume Oct 28, 2021
022b5e4
frontend: Add AutoCompletePicker.stories and docs
illume Oct 28, 2021
563f40a
frontend: Fix Stores to init on demand not on import
illume Oct 29, 2021
53c2751
frontend: Add Channel stories and interface docs
illume Oct 29, 2021
3c0e70f
frontend: Remove Channels/*.spec as covered by stories
illume Oct 29, 2021
df481bf
backend: Add id field to Activity response
illume Nov 2, 2021
2d67561
frontend i18n/dateTime: Add default locale+TZ under test
illume Jan 7, 2022
bac576d
frontend: Add Activity stories and interface docs
illume Nov 2, 2021
6612f69
frontend: Add APIContext for overriding API in stories
illume Nov 4, 2021
ae915cf
frontend: Add Applications stories and interface docs
illume Nov 4, 2021
4580cce
docker: Ignore frontend/*.stories.* and *.tests.*
illume Nov 8, 2021
d3dc16b
frontend: Add Groups stories and interface docs
illume Nov 8, 2021
2c2ef3a
frontend: Add coverage testing to make test and CI
illume May 11, 2022
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ bin/nebraska
backend/tools/
backend/bin
charts/
frontend/**/*.stories.*
frontend/**/*.test.*
3 changes: 3 additions & 0 deletions backend/api/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,7 @@ components:
activity:
type: object
required:
- id
- appID
- groupID
- createdTs
Expand All @@ -1834,6 +1835,8 @@ components:
- channelName
- instanceID
properties:
id:
type: string
illume marked this conversation as resolved.
Show resolved Hide resolved
appID:
type: string
x-oapi-codegen-extra-tags:
Expand Down
3 changes: 2 additions & 1 deletion backend/pkg/api/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (

// Activity represents a Nebraska activity entry.
type Activity struct {
ID string `db:"id" json:"id"`
AppID null.String `db:"application_id" json:"app_id"`
GroupID null.String `db:"group_id" json:"group_id"`
CreatedTs time.Time `db:"created_ts" json:"created_ts"`
Expand Down Expand Up @@ -115,7 +116,7 @@ func (api *API) activityQuery(teamID string, p ActivityQueryParams, countSelect
query = query.Select(goqu.L(`count(a)`))
} else {
query = query.Select(
"a.application_id", "a.group_id", "a.created_ts", "a.class",
"a.id", "a.application_id", "a.group_id", "a.created_ts", "a.class",
"a.severity", "a.version", "a.instance_id",
goqu.I("app.name").As("application_name"), goqu.I("g.name").
As("group_name"), goqu.I("c.name").As("channel_name"))
Expand Down
20 changes: 20 additions & 0 deletions backend/pkg/api/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ func TestGetGroupsFiltered(t *testing.T) {
}
}

func TestVersionBreakDownEmpty(t *testing.T) {
a := newForTest(t)
defer a.Close()

tTeam, _ := a.AddTeam(&Team{Name: "test_team"})
tApp, _ := a.AddApp(&Application{Name: "test_app", TeamID: tTeam.ID})
tPkg, _ := a.AddPackage(&Package{Type: PkgTypeOther, URL: "http://sample.url/pkg", Version: "12.1.0", ApplicationID: tApp.ID})
tChannel, _ := a.AddChannel(&Channel{Name: "test_channel", Color: "blue", ApplicationID: tApp.ID, PackageID: null.StringFrom(tPkg.ID)})
_, err := a.AddGroup(&Group{Name: "test_group1", ApplicationID: tApp.ID, ChannelID: null.StringFrom(tChannel.ID), PolicyUpdatesEnabled: true, PolicySafeMode: true, PolicyPeriodInterval: "15 minutes", PolicyMaxUpdatesPerPeriod: 2, PolicyUpdateTimeout: "60 minutes"})
assert.NoError(t, err)

groups, err := a.GetGroups(tApp.ID, 0, 0)
assert.NoError(t, err)
g := groups[0]

versionBreakdown, vbErr := a.GetGroupVersionBreakdown(g.ID)
assert.NoError(t, vbErr)
assert.Len(t, versionBreakdown, 0)
}

func TestGetVersionCountTimeline(t *testing.T) {
a := newForTest(t)
defer a.Close()
Expand Down
136 changes: 68 additions & 68 deletions backend/pkg/codegen/spec.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pkg/codegen/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions backend/pkg/handler/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (h *Handler) GetGroupInstanceStats(ctx echo.Context, appID string, groupID

func (h *Handler) GetGroupVersionBreakdown(ctx echo.Context, appID string, groupID string) error {
versionBreakdown, err := h.db.GetGroupVersionBreakdown(groupID)

if err != nil {
if err == sql.ErrNoRows {
return ctx.NoContent(http.StatusNotFound)
Expand All @@ -196,6 +197,10 @@ func (h *Handler) GetGroupVersionBreakdown(ctx echo.Context, appID string, group
return ctx.NoContent(http.StatusInternalServerError)
}

if len(versionBreakdown) == 0 {
// WAT?: because otherwise it serializes to null not []
return ctx.JSON(http.StatusOK, []string{})
}
return ctx.JSON(http.StatusOK, versionBreakdown)
}

Expand Down
5 changes: 3 additions & 2 deletions backend/test/api/flatcar_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"testing"

"github.com/google/uuid"
"github.com/kinvolk/nebraska/backend/pkg/config"
"github.com/kinvolk/nebraska/backend/pkg/server"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/kinvolk/nebraska/backend/pkg/config"
"github.com/kinvolk/nebraska/backend/pkg/server"
)

func TestHostFlatcarPackage(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions frontend/.storybook/NebraskaTheme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// https://storybook.js.org/docs/react/configure/theming#create-a-theme-quickstart
// To workaround a bug at time of writing, where theme is not refreshed,
// you may need to `npm run storybook --no-manager-cache`
import { create } from '@storybook/theming';
import logoUrl from '../../docs/nebraska-logo.svg';

export default create({
base: 'light',
brandTitle: 'Nebraska is an update manager for Flatcar Container Linux and Kubernetes.',
brandUrl: 'https://kinvolk.io/docs/nebraska/latest/development/',
brandImage: logoUrl,
});
8 changes: 8 additions & 0 deletions frontend/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/preset-create-react-app',
],
};
6 changes: 6 additions & 0 deletions frontend/.storybook/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { addons } from '@storybook/addons';
import theme from './NebraskaTheme';

addons.setConfig({
theme: theme,
});
52 changes: 52 additions & 0 deletions frontend/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import themesConf from '../src/lib/themes';
import { StylesProvider } from '@material-ui/core/styles';
import '../src/i18n/config';
import ThemeProviderNexti18n from '../src/i18n/ThemeProviderNexti18n';

const darkTheme = themesConf['dark'];
const lightTheme = themesConf['light'];

const withThemeProvider = (Story, context) => {
const backgroundColor = context.globals.backgrounds ? context.globals.backgrounds.value : 'light';
const theme = backgroundColor !== 'dark' ? lightTheme : darkTheme;

const ourThemeProvider = (
<ThemeProviderNexti18n theme={theme}>
<Story {...context} />
</ThemeProviderNexti18n>
);
if (process.env.NODE_ENV !== 'test') {
return ourThemeProvider;
} else {
const generateClassName = (rule, styleSheet) =>
`${styleSheet?.options.classNamePrefix}-${rule.key}`;

return (
<StylesProvider generateClassName={generateClassName}>{ourThemeProvider}</StylesProvider>
);
}
};
export const decorators = [withThemeProvider];

export const globalTypes = {
theme: {
name: 'Theme',
description: 'Global theme for components',
defaultValue: 'light',
toolbar: {
icon: 'circlehollow',
items: ['light', 'dark'],
},
},
};

export const parameters = {
backgrounds: {
values: [
{ name: 'light', value: 'light' },
{ name: 'dark', value: 'dark' },
],
},
actions: { argTypesRegex: '^on[A-Z].*' },
};
2 changes: 1 addition & 1 deletion frontend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ build: install

.PHONY: test
test:
npm run test
npm run test -- --coverage

.PHONY: lint
lint:
Expand Down
Loading