mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 14:12:15 +08:00

* refactor(frontend): rename all @grafana/data/src imports to @grafana/data * feat(grafana-data): introduce internal entrypoint for sharing code only with grafana * feat(grafana-data): add test entrypoint for data test utils usage in core * refactor(frontend): update import paths to use grafana/data exports entrypoints * docs(grafana-data): update comment in internal/index.ts * refactor(frontend): prefer public namespaced exports over re-exporting via internal * chore(frontend): fix a couple more weird paths that typescript complains about
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { DataFrame, ActionModel, Field, InterpolateFunction, LinkModel } from '@grafana/data';
|
|
import { getActions } from 'app/features/actions/utils';
|
|
|
|
export const getDataLinks = (field: Field, rowIdx: number) => {
|
|
const links: Array<LinkModel<Field>> = [];
|
|
|
|
if ((field.config.links?.length ?? 0) > 0 && field.getLinks != null) {
|
|
const v = field.values[rowIdx];
|
|
const disp = field.display ? field.display(v) : { text: `${v}`, numeric: +v };
|
|
|
|
const linkLookup = new Set<string>();
|
|
|
|
field.getLinks({ calculatedValue: disp, valueRowIndex: rowIdx }).forEach((link) => {
|
|
const key = `${link.title}/${link.href}`;
|
|
if (!linkLookup.has(key)) {
|
|
links.push(link);
|
|
linkLookup.add(key);
|
|
}
|
|
});
|
|
}
|
|
|
|
return links;
|
|
};
|
|
|
|
export const getAllFrameActions = (dataFrame: DataFrame) => {};
|
|
|
|
export const getFieldActions = (
|
|
dataFrame: DataFrame,
|
|
field: Field,
|
|
replaceVars: InterpolateFunction,
|
|
rowIndex: number
|
|
) => {
|
|
const actions: Array<ActionModel<Field>> = [];
|
|
const actionLookup = new Set<string>();
|
|
|
|
const actionsModel = getActions(dataFrame, field, field.state!.scopedVars!, replaceVars, field.config.actions ?? [], {
|
|
valueRowIndex: rowIndex,
|
|
});
|
|
|
|
actionsModel.forEach((action) => {
|
|
const key = `${action.title}`;
|
|
if (!actionLookup.has(key)) {
|
|
actions.push(action);
|
|
actionLookup.add(key);
|
|
}
|
|
});
|
|
|
|
return actions;
|
|
};
|