-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
while trying to consolidate implementations for the ServicesTable and the PodInstancesTable (we'll also later need to have a look at the ServicesInstancesContainer) these changes emerged. They help in comprehending what's going on and will be utterly helpful when fixing the FilterBar on that Table (which has several bugs, as i learned during this exercise).
- Loading branch information
1 parent
5a1ab89
commit 6a8701a
Showing
19 changed files
with
95 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 14 additions & 27 deletions
41
plugins/services/src/js/filters/PodInstanceStatusFilter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,40 @@ | ||
import DSLFilterTypes from "#SRC/js/constants/DSLFilterTypes"; | ||
import DSLFilter from "#SRC/js/structs/DSLFilter"; | ||
|
||
const LABEL = "is"; | ||
|
||
const LABEL_TO_STATUS = { | ||
active: "active", | ||
completed: "completed", | ||
}; | ||
const getStatus = (label) => | ||
({ | ||
active: "active", | ||
completed: "completed", | ||
}[label.toLowerCase()]); | ||
|
||
/** | ||
* This filter handles the `is:state` for instances | ||
*/ | ||
class PodInstanceStatusFilter extends DSLFilter { | ||
export default { | ||
/** | ||
* Handle all `is:XXXX` attribute filters that we can handle. | ||
* | ||
* @override | ||
*/ | ||
filterCanHandle(filterType, filterArguments) { | ||
filterCanHandle(filterType, { label, text }) { | ||
return ( | ||
filterType === DSLFilterTypes.ATTRIB && | ||
filterArguments.label === LABEL && | ||
LABEL_TO_STATUS[filterArguments.text.toLowerCase()] != null | ||
filterType === DSLFilterTypes.ATTRIB && label === "is" && getStatus(text) | ||
); | ||
} | ||
}, | ||
|
||
/** | ||
* Keep only instances whose state matches the value of | ||
* the `is` label | ||
* | ||
* @override | ||
* Keep only instances whose state matches the value of the `is` label | ||
*/ | ||
filterApply(resultSet, filterType, filterArguments) { | ||
const testStatus = LABEL_TO_STATUS[filterArguments.text.toLowerCase()]; | ||
filterApply(resultSet, _filterType, { text }) { | ||
const testStatus = getStatus(text); | ||
|
||
return resultSet.filterItems((instance) => { | ||
let instanceStatus = "completed"; | ||
|
||
if (instance.isStaging()) { | ||
instanceStatus = "staging"; | ||
} | ||
|
||
if (instance.isRunning()) { | ||
instanceStatus = "active"; | ||
} | ||
|
||
return instanceStatus === testStatus; | ||
}); | ||
} | ||
} | ||
|
||
export default PodInstanceStatusFilter; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 12 additions & 41 deletions
53
plugins/services/src/js/filters/PodInstancesRegionFilter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,23 @@ | ||
import DSLFilterTypes from "#SRC/js/constants/DSLFilterTypes"; | ||
import DSLFilter from "#SRC/js/structs/DSLFilter"; | ||
import InstanceUtil from "../utils/InstanceUtil"; | ||
|
||
const LABEL = "region"; | ||
|
||
/** | ||
* This filter handles the `region:XXXX` for instances | ||
*/ | ||
class PodInstancesRegionFilter extends DSLFilter { | ||
constructor(regions = []) { | ||
super(); | ||
this.regions = regions; | ||
} | ||
export default { | ||
/** | ||
* Handle all `region:XXXX` attribute filters that we can handle. | ||
* | ||
* @override | ||
*/ | ||
filterCanHandle(filterType, filterArguments) { | ||
const regions = this.regions; | ||
|
||
return ( | ||
filterType === DSLFilterTypes.ATTRIB && | ||
filterArguments.label === LABEL && | ||
regions.includes(filterArguments.text.toLowerCase()) | ||
); | ||
} | ||
filterCanHandle(filterType, { label }) { | ||
return filterType === DSLFilterTypes.ATTRIB && label === "region"; | ||
}, | ||
|
||
/** | ||
* Keep only instances whose region matches the value of | ||
* the `region` label | ||
* | ||
* @override | ||
*/ | ||
filterApply(resultSet, filterType, filterArguments) { | ||
let region = ""; | ||
const filterArgumentsValue = filterArguments.text.toLowerCase(); | ||
|
||
if (this.regions.includes(filterArgumentsValue)) { | ||
region = filterArgumentsValue; | ||
} | ||
|
||
return resultSet.filterItems((instance) => { | ||
const node = InstanceUtil.getNode(instance); | ||
|
||
return node && node.getRegionName().toLowerCase() === region; | ||
}); | ||
} | ||
} | ||
|
||
export default PodInstancesRegionFilter; | ||
filterApply(resultSet, _filterType, { text }) { | ||
const region = text.toLowerCase(); | ||
return resultSet.filterItems( | ||
(instance) => | ||
InstanceUtil.getNode(instance)?.getRegionName().toLowerCase() === region | ||
); | ||
}, | ||
}; |
Oops, something went wrong.