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

feat(new-vm): show resource set limits #1563

Merged
merged 7 commits into from
Sep 21, 2016
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
20 changes: 20 additions & 0 deletions src/common/usage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,23 @@ Element.propTypes = {
value: PropTypes.number.isRequired
}
export { Element as UsageElement }

export const Limits = ({ used, toBeUsed, limit }) => {
const available = limit - used

return <span className='limits'>
<span
className='limits-used'
style={{ width: ((used || 0) / limit) * 100 + '%' }}
/>
<span
className={toBeUsed > available ? 'limits-over-used' : 'limits-to-be-used'}
style={{ width: (Math.min((toBeUsed || 0), available) / limit) * 100 + '%' }}
/>
</span>
}
Limits.propTypes = {
used: PropTypes.number,
toBeUsed: PropTypes.number,
limit: PropTypes.number.isRequired
}
57 changes: 31 additions & 26 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,38 +361,43 @@ export function rethrow (cb) {

// ===================================================================

export const resolveResourceSets = resourceSets => (
map(resourceSets, resourceSet => {
const { objects, ...attrs } = resourceSet
const resolvedObjects = {}
const resolvedSet = {
...attrs,
missingObjects: [],
objectsByType: resolvedObjects
}
const state = store.getState()
export const resolveResourceSet = resourceSet => {
if (!resourceSet) {
return
}

forEach(objects, id => {
const object = getObject(state, id, true) // true: useResourceSet to bypass permissions
const { objects, ...attrs } = resourceSet
const resolvedObjects = {}
const resolvedSet = {
...attrs,
missingObjects: [],
objectsByType: resolvedObjects
}
const state = store.getState()

// Error, missing resource.
if (!object) {
resolvedSet.missingObjects.push(id)
return
}
forEach(objects, id => {
const object = getObject(state, id, true) // true: useResourceSet to bypass permissions

const { type } = object
// Error, missing resource.
if (!object) {
resolvedSet.missingObjects.push(id)
return
}

if (!resolvedObjects[type]) {
resolvedObjects[type] = [ object ]
} else {
resolvedObjects[type].push(object)
}
})
const { type } = object

return resolvedSet
if (!resolvedObjects[type]) {
resolvedObjects[type] = [ object ]
} else {
resolvedObjects[type].push(object)
}
})
)

return resolvedSet
}

export const resolveResourceSets = resourceSets =>
map(resourceSets, resolveResourceSet)

// -------------------------------------------------------------------

Expand Down
33 changes: 1 addition & 32 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ $fa-font-path: "./";

// -------------------------------------------------------------------


@import "./chartist";
@import "./meter";
@import "./icons";
@import "./usage";

// ROOT STYLES =================================================================

Expand Down Expand Up @@ -194,37 +194,6 @@ $select-input-height: 40px; // Bootstrap input height
background: $gray-lighter;
}

// MEMORY/DISK BAR STYLE =======================================================

.usage {
@extend .progress;
background-color: #eee;
height: 2em;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
margin-top: 1em;
margin-bottom: 2em;
}

.usage-element {
background-color: #5cb85c;
box-shadow: -1px 0 0 0 white;
height: 2em;
display: inline-block;
transition: all 0.3s ease 0s;
}

.usage-element-highlight {
background-color: $brand-primary;
}

.usage-element-others {
background-color: $brand-info;
}

.usage-element:hover {
opacity: 0.6;
}

// NOTIFICATIONS STYLE =========================================================

.notify-container {
Expand Down
62 changes: 62 additions & 0 deletions src/usage.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Usage

.usage {
@extend .progress;
background-color: #eee;
height: 2em;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
margin-top: 1em;
margin-bottom: 2em;
}

.usage-element {
background-color: #5cb85c;
box-shadow: -1px 0 0 0 white;
height: 2em;
display: inline-block;
transition: all 0.3s ease 0s;
}

.usage-element-highlight {
background-color: $brand-primary;
}

.usage-element-others {
background-color: $brand-info;
}

.usage-element:hover {
opacity: 0.6;
}

// Limits

.limits {
@extend .progress;
background-color: #eee;
height: 1.1em;
width: 100%;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}

.limits-element {
background-color: #5cb85c;
height: 100%;
display: inline-block;
transition: all 0.3s ease 0s;
}

.limits-used {
@extend .limits-element;
background-color: $brand-primary;
}

.limits-to-be-used {
@extend .limits-element;
background-color: $brand-success;
}

.limits-over-used {
@extend .limits-element;
background-color: $brand-danger;
}
Loading