DataSources: minor typescript cleanups and comments (#16860)

* datasource interface cleanup

* more types

* use PluginInclude
This commit is contained in:
Ryan McKinley
2019-05-02 21:26:30 -07:00
committed by Torkel Ödegaard
parent 3e6104f45a
commit ece4d2201c
6 changed files with 23 additions and 78 deletions

View File

@@ -105,7 +105,11 @@ export function deleteDataSource(): ThunkResult<void> {
};
}
export function nameExits(dataSources, name) {
interface ItemWithName {
name: string;
}
export function nameExits(dataSources: ItemWithName[], name: string) {
return (
dataSources.filter(dataSource => {
return dataSource.name.toLowerCase() === name.toLowerCase();
@@ -113,7 +117,7 @@ export function nameExits(dataSources, name) {
);
}
export function findNewName(dataSources, name) {
export function findNewName(dataSources: ItemWithName[], name: string) {
// Need to loop through current data sources to make sure
// the name doesn't exist
while (nameExits(dataSources, name)) {
@@ -143,18 +147,18 @@ function updateFrontendSettings() {
});
}
function nameHasSuffix(name) {
function nameHasSuffix(name: string) {
return name.endsWith('-', name.length - 1);
}
function getLastDigit(name) {
function getLastDigit(name: string) {
return parseInt(name.slice(-1), 10);
}
function incrementLastDigit(digit) {
function incrementLastDigit(digit: number) {
return isNaN(digit) ? 1 : digit + 1;
}
function getNewName(name) {
function getNewName(name: string) {
return name.slice(0, name.length - 1);
}