The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/manage-dashboards/utils/validation.ts

59 lines
1.8 KiB

import { t } from 'app/core/internationalization';
import { getDashboardAPI } from 'app/features/dashboard/api/dashboard_api';
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
import { validationSrv } from '../services/ValidationSrv';
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
export const validateDashboardJson = (json: string) => {
let dashboard;
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
try {
dashboard = JSON.parse(json);
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
} catch (error) {
i18n: dashboard import page (#75664) * add translation for filezone primary and secondary text * add translation for Grafana.com field label * update translation keys * add translation for load button * update required translation * Format utils for invalid-dashboard * add extracted translations * add pseudo translations * add translation for json validation * json field label translation * add translation for required json field * add translation for cancel key * add extracted translations * Add pseudo locale translation * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * update translations * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * update link component * add new translations --------- Co-authored-by: Ashley Harrison <ashharrison90@gmail.com>
2 years ago
return t('dashboard.validation.invalid-json', 'Not valid JSON');
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
}
if (dashboard && dashboard.hasOwnProperty('tags')) {
if (Array.isArray(dashboard.tags)) {
const hasInvalidTag = dashboard.tags.some((tag: string) => typeof tag !== 'string');
if (hasInvalidTag) {
i18n: dashboard import page (#75664) * add translation for filezone primary and secondary text * add translation for Grafana.com field label * update translation keys * add translation for load button * update required translation * Format utils for invalid-dashboard * add extracted translations * add pseudo translations * add translation for json validation * json field label translation * add translation for required json field * add translation for cancel key * add extracted translations * Add pseudo locale translation * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * update translations * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * update link component * add new translations --------- Co-authored-by: Ashley Harrison <ashharrison90@gmail.com>
2 years ago
return t('dashboard.validation.tags-expected-strings', 'tags expected array of strings');
}
} else {
i18n: dashboard import page (#75664) * add translation for filezone primary and secondary text * add translation for Grafana.com field label * update translation keys * add translation for load button * update required translation * Format utils for invalid-dashboard * add extracted translations * add pseudo translations * add translation for json validation * json field label translation * add translation for required json field * add translation for cancel key * add extracted translations * Add pseudo locale translation * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * update translations * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * update link component * add new translations --------- Co-authored-by: Ashley Harrison <ashharrison90@gmail.com>
2 years ago
return t('dashboard.validation.tags-expected-array', 'tags expected array');
}
}
return true;
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
};
export const validateGcomDashboard = (gcomDashboard: string) => {
// From DashboardImportCtrl
const match = /(^\d+$)|dashboards\/(\d+)/.exec(gcomDashboard);
i18n: dashboard import page (#75664) * add translation for filezone primary and secondary text * add translation for Grafana.com field label * update translation keys * add translation for load button * update required translation * Format utils for invalid-dashboard * add extracted translations * add pseudo translations * add translation for json validation * json field label translation * add translation for required json field * add translation for cancel key * add extracted translations * Add pseudo locale translation * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/utils/validation.ts Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * update translations * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * Update public/app/features/manage-dashboards/DashboardImportPage.tsx Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> * update link component * add new translations --------- Co-authored-by: Ashley Harrison <ashharrison90@gmail.com>
2 years ago
return match && (match[1] || match[2])
? true
: t('dashboard.validation.invalid-dashboard-id', 'Could not find a valid Grafana.com ID');
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
};
export const validateTitle = (newTitle: string, folderUid: string) => {
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
return validationSrv
.validateNewDashboardName(folderUid, newTitle)
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
.then(() => {
return true;
})
.catch((error) => {
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
if (error.type === 'EXISTING') {
return error.message;
}
});
};
export const validateUid = (value: string) => {
return getDashboardAPI()
.getDashboardDTO(value)
.then((existingDashboard) => {
return `Dashboard named '${existingDashboard?.dashboard.title}' in folder '${existingDashboard?.meta.folderTitle}' has the same UID`;
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
})
.catch((error) => {
Migration: Migrate Dashboard Import to React (#22338) * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * first things * introduce headers and moving buttons * adding reducer and action for gcom dashboard * action working * continue building on import form * change dashboard title * add prop to not render a label * import form layout * break out form to component * add actions and reader for file upload * fix upload issue * modified data types to handle both gcom and file upload * import dashboard json * save dashboard * start change uid * change dashboard uid * fix spacing and date format * fix import from json * handle uid and title change * revert change in panelinspect * redo fileupload component * after review * redo forms to use Forms functionality * first attempt on async validation * use ternary on uid input * removed unused actions, fixed async validation on form * post form if invalid, break out form to component * sync file with master * fix after merge * nits * export formapi type * redo page to use forms validation * fix inputs and validation * readd post * add guards on data source and constants * type checks and strict nulls * strict nulls * validate onchange and fix import button when valid * shorten validate call * reexport OnSubmit type * add comment for overwrite useEffect * move validation functions to util * fix button imports * remove angular import * move title and uid validation
6 years ago
error.isHandled = true;
return true;
});
};