Skip to content
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
22 changes: 0 additions & 22 deletions src/api/generic/linodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,6 @@ export const config = addParentRefs({
primaryKey: 'id',
endpoint: id => `/linode/instances/${id}`,
supports: [ONE, MANY, PUT, DELETE, POST],
properties: {
type: (linode) => function (_, getState) {
const types = getState().api.types.types || {};

return {
label: 'Unknown',
id: linode.type,
...types[linode.type] || {},
...linode.specs,
};
},
image: (linode) => function (_, getState) {
const images = getState().api.images.images || {};

return {
vendor: 'Unknown',
label: 'Unknown',
id: linode.image,
...images[linode.image],
};
},
},
subresources: {
_configs: {
name: 'configs',
Expand Down
39 changes: 11 additions & 28 deletions src/api/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ function parseIntIfActualInt(string) {
}

const actionCreatorGenerators = {
// These functions take a config and return Redux Action Creators
[ONE]: config => (resource, ...ids) => (dispatch) =>
dispatch({
[ONE]: c => (resource, ...ids) =>
({
resource,
dispatch,
type: `GEN@${fullyQualified(config)}/ONE`,
type: `GEN@${fullyQualified(c)}/ONE`,
ids: ids.map(parseIntIfActualInt),
}),
[MANY]: config => (page, ...ids) => (dispatch) =>
dispatch({
[MANY]: c => (page, ...ids) =>
({
page,
dispatch,
type: `GEN@${fullyQualified(config)}/MANY`,
type: `GEN@${fullyQualified(c)}/MANY`,
ids: ids.map(parseIntIfActualInt),
}),
[DELETE]: c => (...ids) =>
({
type: `GEN@${fullyQualified(c)}/DELETE`,
ids: ids.map(parseIntIfActualInt),
}),
[DELETE]: config => (...ids) =>
({ type: `GEN@${fullyQualified(config)}/DELETE`, ids: ids.map(parseIntIfActualInt) }),
};

/**
Expand Down Expand Up @@ -129,23 +129,6 @@ export class ReducerGenerator {

const combinedStateOne = { ...oldStateOne, ...newStateOne, __updatedAt: new Date() };

if (config.properties && action.dispatch) {
Object.keys(config.properties).forEach(function (property) {
const accessor = config.properties[property];

const stateWithoutPropertyDefined = newStateOne;
if (typeof stateWithoutPropertyDefined[property] !== 'undefined') {
Object.defineProperty(combinedStateOne, property, {
get: () => action.dispatch(accessor(newStateOne)),
});
}
});
}

(config.properiesMasks || []).forEach(function (property) {
delete combinedStateOne[property];
});

const newStateMany = {
...oldStateMany,
[config.name]: {
Expand Down
24 changes: 10 additions & 14 deletions src/api/internal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,35 @@ import { resource, page } from '~/data/reduxGen';

describe('internal', () => {
it('generates an action to update one resource', function () {
const dispatch = jest.fn();

const config = testConfigOne;

const actions = genActions(config);
const oneThunk = actions.one(resource, '23');
oneThunk(dispatch);
const actionOne = actions.one(resource, '23');

expect(dispatch.mock.calls[0][0].resource.label).toBe('nodebalancer-1');
expect(dispatch.mock.calls[0][0].type).toBe('GEN@nodebalancers/ONE');
expect(dispatch.mock.calls[0][0].ids[0]).toBe(23);
expect(actionOne.resource.label).toBe('nodebalancer-1');
expect(actionOne.type).toBe('GEN@nodebalancers/ONE');
expect(actionOne.ids[0]).toBe(23);
});

it('generates an action to update many resources', function () {
const dispatch = jest.fn();

const config = testConfigMany;

const actions = genActions(config);
const manyThunk = actions.many(page);
manyThunk(dispatch);
expect(dispatch.mock.calls[0][0].page.nodebalancers[0].label)
const actionMany = actions.many(page);

expect(actionMany.page.nodebalancers[0].label)
.toBe('nodebalancer-1');
expect(dispatch.mock.calls[0][0].page.nodebalancers[1].label)
expect(actionMany.page.nodebalancers[1].label)
.toBe('nodebalancer-2');
expect(dispatch.mock.calls[0][0].type).toBe('GEN@nodebalancers/MANY');
expect(actionMany.type).toBe('GEN@nodebalancers/MANY');
});

it('generates an action to delete a resource', function () {
const config = testConfigDelete;

const actions = genActions(config);
const deleteAction = actions.delete('23');

expect(deleteAction.ids[0]).toBe(23);
expect(deleteAction.type).toBe('GEN@nodebalancers/DELETE');
});
Expand Down
15 changes: 4 additions & 11 deletions src/data/linodes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { testType } from './types';
import { apiTestRegion } from './regions';
import { apiTestImage } from './images';

const stats = {
netv6: {
Expand Down Expand Up @@ -94,17 +95,13 @@ function createTestLinode(id) {
ipv4: [ipv4.address, secondIPv4.address],
ipv6: ipv6.address,
created: '2016-07-06T16:47:27',
type: testType,
type: testType.id,
status: 'running',
region: apiTestRegion.id,
memory: 2048,
disk: 20480,
vcpus: 2,
image: {
id: 'linode/ubuntu15.10',
vendor: 'Ubuntu',
label: 'Ubuntu 15.10',
},
image: apiTestImage.id,
alerts: {
cpu: 90,
io: 5000,
Expand Down Expand Up @@ -479,11 +476,7 @@ export const testLinode1245 = {

export const testLinode1246 = {
...createTestLinode(1246),
image: {
id: null,
label: 'Unknown',
vendor: 'unknown',
},
image: null,
};

const rdnsIP1247 = { ...createTestIPv4(1247), rdns: 'host.rdns.tld' };
Expand Down
12 changes: 6 additions & 6 deletions src/linodes/components/DistroStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import { distros as distroAssets } from '~/assets';


export default function DistroStyle(props) {
const { linode } = props;
const { image } = props;

if (!linode || !linode.image || !linode.image.vendor) {
if (!image.vendor) {
return <span className="distro-style">Unknown</span>;
}

const src = distroAssets[lowerCase(linode.image.vendor)];
const src = distroAssets[lowerCase(image.vendor)];

return (
<span className="distro-style">
{src ? <img
src={src}
alt={linode.image.vendor}
alt={image.vendor}
width="15" height="15"
/> : ''}
<span>{linode.image.label}</span>
<span>{image.label}</span>
</span>
);
}

DistroStyle.propTypes = {
linode: PropTypes.object,
image: PropTypes.object.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,7 @@ ShallowWrapper {
"group": "Test Group",
"hypervisor": "kvm",
"id": 1238,
"image": Object {
"id": "linode/ubuntu15.10",
"label": "Ubuntu 15.10",
"vendor": "Ubuntu",
},
"image": "linode/arch2016.05",
"ipv4": Array [
"97.107.143.15",
"97.107.143.16",
Expand All @@ -335,29 +331,7 @@ ShallowWrapper {
"memory": 2048,
"region": "us-east-1a",
"status": "offline",
"type": Object {
"_polling": false,
"addons": Object {
"backups": Object {
"price": Object {
"monthly": 2.5,
},
},
},
"class": "standard",
"disk": 24576,
"id": "linode2048.5",
"label": "Linode 2048",
"memory": 2048,
"network_out": 125,
"price": Object {
"hourly": 0.015,
"monthly": 10,
},
"service_type": "linode",
"transfer": 2000,
"vcpus": 2,
},
"type": "linode2048.5",
"vcpus": 2,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ ShallowWrapper {
"group": "Test Group",
"hypervisor": "kvm",
"id": 1236,
"image": Object {
"id": "linode/ubuntu15.10",
"label": "Ubuntu 15.10",
"vendor": "Ubuntu",
},
"image": "linode/arch2016.05",
"ipv4": Array [
"97.107.143.9",
"97.107.143.10",
Expand All @@ -251,29 +247,7 @@ ShallowWrapper {
"memory": 2048,
"region": "us-east-1a",
"status": "offline",
"type": Object {
"_polling": false,
"addons": Object {
"backups": Object {
"price": Object {
"monthly": 2.5,
},
},
},
"class": "standard",
"disk": 24576,
"id": "linode2048.5",
"label": "Linode 2048",
"memory": 2048,
"network_out": 125,
"price": Object {
"hourly": 0.015,
"monthly": 10,
},
"service_type": "linode",
"transfer": 2000,
"vcpus": 2,
},
"type": "linode2048.5",
"vcpus": 2,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/linodes/layouts/ListLinodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class ListLinodesPage extends Component {
powerOn = (linodes) => this.genericAction(powerOnLinode, linodes)
reboot = (linodes) => this.genericAction(rebootLinode, linodes, 'Reboot')

renderLinodes(linodes) {
renderLinodes(linodes, types) {
const { dispatch, selectedMap } = this.props;
const { filter } = this.state;

Expand Down Expand Up @@ -150,7 +150,7 @@ export class ListLinodesPage extends Component {
headerClassName: 'LabelColumn',
hrefFn: (linode) => `/linodes/${linode.label}`,
tooltipEnabled: true,
subtitleFn: linode => planStyle(linode.type),
subtitleFn: linode => planStyle(types[linode.type]),
},
{ cellComponent: IPAddressCell, headerClassName: 'LinodeIPAddressColumn' },
{
Expand Down Expand Up @@ -214,7 +214,7 @@ export class ListLinodesPage extends Component {
</div>
</header>
<div className="PrimaryPage-body">
{Object.keys(linodes).length ? this.renderLinodes(linodes) : (
{Object.keys(linodes).length ? this.renderLinodes(linodes, types) : (
<CreateHelper
label="Linodes"
linkText="Add a Linode"
Expand Down
Loading