type
stringclasses 7
values | content
stringlengths 4
9.55k
| repo
stringlengths 7
96
| path
stringlengths 4
178
| language
stringclasses 1
value |
---|---|---|---|---|
MethodDeclaration |
private evaluateExpression(expression: string): string {
return `node -e 'console.log((${expression})());'`;
} | Raisess/i3bcks-gen | src/Parser.ts | TypeScript |
FunctionDeclaration |
export async function calculateMinInterval(
{ args: { layers }, data }: XYChartProps,
getIntervalByColumn: DataPublicPluginStart['search']['aggs']['getDateMetaByDatatableColumn']
) {
const filteredLayers = getFilteredLayers(layers, data);
if (filteredLayers.length === 0) return;
const isTimeViz = data.dateRange && filteredLayers.every((l) => l.xScaleType === 'time');
if (!isTimeViz) return;
const dateColumn = data.tables[filteredLayers[0].layerId].columns.find(
(column) => column.id === filteredLayers[0].xAccessor
);
if (!dateColumn) return;
const dateMetaData = await getIntervalByColumn(dateColumn);
if (!dateMetaData) return;
const intervalDuration = search.aggs.parseInterval(dateMetaData.interval);
if (!intervalDuration) return;
return intervalDuration.as('milliseconds');
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
FunctionDeclaration |
function getValueLabelsStyling(isHorizontal: boolean) {
const VALUE_LABELS_MAX_FONTSIZE = 15;
const VALUE_LABELS_MIN_FONTSIZE = 10;
const VALUE_LABELS_VERTICAL_OFFSET = -10;
const VALUE_LABELS_HORIZONTAL_OFFSET = 10;
return {
displayValue: {
fontSize: { min: VALUE_LABELS_MIN_FONTSIZE, max: VALUE_LABELS_MAX_FONTSIZE },
fill: { textInverted: true, textBorder: 2 },
alignment: isHorizontal
? {
vertical: VerticalAlignment.Middle,
}
: { horizontal: HorizontalAlignment.Center },
offsetX: isHorizontal ? VALUE_LABELS_HORIZONTAL_OFFSET : 0,
offsetY: isHorizontal ? 0 : VALUE_LABELS_VERTICAL_OFFSET,
},
};
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
FunctionDeclaration |
function getIconForSeriesType(seriesType: SeriesType): IconType {
return visualizationTypes.find((c) => c.id === seriesType)!.icon || 'empty';
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
FunctionDeclaration |
export function XYChartReportable(props: XYChartRenderProps) {
const [state, setState] = useState({
isReady: false,
});
// It takes a cycle for the XY chart to render. This prevents
// reporting from printing a blank chart placeholder.
useEffect(() => {
setState({ isReady: true });
}, [setState]);
return (
<VisualizationContainer
className="lnsXyExpression__container"
isReady={state.isReady}
reportTitle={props.args.title}
reportDescription={props.args.description}
>
<MemoizedChart {...props} />
</VisualizationContainer>
);
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
FunctionDeclaration |
export function XYChart({
data,
args,
formatFactory,
timeZone,
chartsThemeService,
paletteService,
minInterval,
onClickValue,
onSelectRange,
renderMode,
}: XYChartRenderProps) {
const { legend, layers, fittingFunction, gridlinesVisibilitySettings, valueLabels } = args;
const chartTheme = chartsThemeService.useChartsTheme();
const chartBaseTheme = chartsThemeService.useChartsBaseTheme();
const filteredLayers = getFilteredLayers(layers, data);
if (filteredLayers.length === 0) {
const icon: IconType = layers.length > 0 ? getIconForSeriesType(layers[0].seriesType) : 'bar';
return <EmptyPlaceholder icon={icon} />;
}
// use formatting hint of first x axis column to format ticks
const xAxisColumn = data.tables[filteredLayers[0].layerId].columns.find(
({ id }) => id === filteredLayers[0].xAccessor
);
const xAxisFormatter = formatFactory(xAxisColumn && xAxisColumn.meta?.params);
const layersAlreadyFormatted: Record<string, boolean> = {};
// This is a safe formatter for the xAccessor that abstracts the knowledge of already formatted layers
const safeXAccessorLabelRenderer = (value: unknown): string =>
xAxisColumn && layersAlreadyFormatted[xAxisColumn.id]
? (value as string)
: xAxisFormatter.convert(value);
const chartHasMoreThanOneSeries =
filteredLayers.length > 1 ||
filteredLayers.some((layer) => layer.accessors.length > 1) ||
filteredLayers.some((layer) => layer.splitAccessor);
const shouldRotate = isHorizontalChart(filteredLayers);
const yAxesConfiguration = getAxesConfiguration(
filteredLayers,
shouldRotate,
data.tables,
formatFactory
);
const xTitle = args.xTitle || (xAxisColumn && xAxisColumn.name);
const axisTitlesVisibilitySettings = args.axisTitlesVisibilitySettings || {
x: true,
yLeft: true,
yRight: true,
};
const tickLabelsVisibilitySettings = args.tickLabelsVisibilitySettings || {
x: true,
yLeft: true,
yRight: true,
};
const filteredBarLayers = filteredLayers.filter((layer) => layer.seriesType.includes('bar'));
const chartHasMoreThanOneBarSeries =
filteredBarLayers.length > 1 ||
filteredBarLayers.some((layer) => layer.accessors.length > 1) ||
filteredBarLayers.some((layer) => layer.splitAccessor);
const isTimeViz = data.dateRange && filteredLayers.every((l) => l.xScaleType === 'time');
const isHistogramViz = filteredLayers.every((l) => l.isHistogram);
const xDomain = isTimeViz
? {
min: data.dateRange?.fromDate.getTime(),
max: data.dateRange?.toDate.getTime(),
minInterval,
}
: undefined;
const getYAxesTitles = (
axisSeries: Array<{ layer: string; accessor: string }>,
groupId: string
) => {
const yTitle = groupId === 'right' ? args.yRightTitle : args.yTitle;
return (
yTitle ||
axisSeries
.map(
(series) =>
data.tables[series.layer].columns.find((column) => column.id === series.accessor)?.name
)
.filter((name) => Boolean(name))[0]
);
};
const getYAxesStyle = (groupId: string) => {
const style = {
tickLabel: {
visible:
groupId === 'right'
? tickLabelsVisibilitySettings?.yRight
: tickLabelsVisibilitySettings?.yLeft,
},
axisTitle: {
visible:
groupId === 'right'
? axisTitlesVisibilitySettings?.yRight
: axisTitlesVisibilitySettings?.yLeft,
},
};
return style;
};
const shouldShowValueLabels =
// No stacked bar charts
filteredLayers.every((layer) => !layer.seriesType.includes('stacked')) &&
// No histogram charts
!isHistogramViz;
const valueLabelsStyling =
shouldShowValueLabels && valueLabels !== 'hide' && getValueLabelsStyling(shouldRotate);
const colorAssignments = getColorAssignments(args.layers, data, formatFactory);
const clickHandler: ElementClickListener = ([[geometry, series]]) => {
// for xyChart series is always XYChartSeriesIdentifier and geometry is always type of GeometryValue
const xySeries = series as XYChartSeriesIdentifier;
const xyGeometry = geometry as GeometryValue;
const layer = filteredLayers.find((l) =>
xySeries.seriesKeys.some((key: string | number) => l.accessors.includes(key.toString()))
);
if (!layer) {
return;
}
const table = data.tables[layer.layerId];
const points = [
{
row: table.rows.findIndex((row) => {
if (layer.xAccessor) {
if (layersAlreadyFormatted[layer.xAccessor]) {
// stringify the value to compare with the chart value
return xAxisFormatter.convert(row[layer.xAccessor]) === xyGeometry.x;
}
return row[layer.xAccessor] === xyGeometry.x;
}
}),
column: table.columns.findIndex((col) => col.id === layer.xAccessor),
value: xyGeometry.x,
},
];
if (xySeries.seriesKeys.length > 1) {
const pointValue = xySeries.seriesKeys[0];
points.push({
row: table.rows.findIndex(
(row) => layer.splitAccessor && row[layer.splitAccessor] === pointValue
),
column: table.columns.findIndex((col) => col.id === layer.splitAccessor),
value: pointValue,
});
}
const xAxisFieldName = table.columns.find((el) => el.id === layer.xAccessor)?.meta?.field;
const timeFieldName = xDomain && xAxisFieldName;
const context: LensFilterEvent['data'] = {
data: points.map((point) => ({
row: point.row,
column: point.column,
value: point.value,
table,
})),
timeFieldName,
};
onClickValue(desanitizeFilterContext(context));
};
const brushHandler: BrushEndListener = ({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
if (!xAxisColumn || !isHistogramViz) {
return;
}
const table = data.tables[filteredLayers[0].layerId];
const xAxisColumnIndex = table.columns.findIndex((el) => el.id === filteredLayers[0].xAccessor);
const timeFieldName = isTimeViz ? table.columns[xAxisColumnIndex]?.meta?.field : undefined;
const context: LensBrushEvent['data'] = {
range: [min, max],
table,
column: xAxisColumnIndex,
timeFieldName,
};
onSelectRange(context);
};
return (
<Chart>
<Settings
showLegend={
legend.isVisible && !legend.showSingleSeries
? chartHasMoreThanOneSeries
: legend.isVisible
}
legendPosition={legend.position}
showLegendExtra={false}
theme={{
...chartTheme,
barSeriesStyle: {
...chartTheme.barSeriesStyle,
...valueLabelsStyling,
},
background: {
color: undefined, // removes background for embeddables
},
}} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
FunctionDeclaration |
function getFilteredLayers(layers: LayerArgs[], data: LensMultiTable) {
return layers.filter(({ layerId, xAccessor, accessors, splitAccessor }) => {
return !(
!accessors.length ||
!data.tables[layerId] ||
data.tables[layerId].rows.length === 0 ||
(xAccessor &&
data.tables[layerId].rows.every((row) => typeof row[xAccessor] === 'undefined')) ||
// stacked percentage bars have no xAccessors but splitAccessor with undefined values in them when empty
(!xAccessor &&
splitAccessor &&
data.tables[layerId].rows.every((row) => typeof row[splitAccessor] === 'undefined'))
);
});
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
FunctionDeclaration |
function assertNever(x: never): never {
throw new Error('Unexpected series type: ' + x);
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
({ id }) => id | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(l) => l.xScaleType === 'time' | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(column) => column.id === filteredLayers[0].xAccessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(dependencies: {
formatFactory: Promise<FormatFactory>;
chartsThemeService: ChartsPluginSetup['theme'];
paletteService: PaletteRegistry;
getIntervalByColumn: DataPublicPluginStart['search']['aggs']['getDateMetaByDatatableColumn'];
timeZone: string;
}): ExpressionRenderDefinition<XYChartProps> => ({
name: 'lens_xy_chart_renderer',
displayName: 'XY chart',
help: i18n.translate('xpack.lens.xyChart.renderer.help', {
defaultMessage: 'X/Y chart renderer',
}),
validate: () => undefined,
reuseDomNode: true,
render: async (
domNode: Element,
config: XYChartProps,
handlers: ILensInterpreterRenderHandlers
) => {
handlers.onDestroy(() => ReactDOM.unmountComponentAtNode(domNode));
const onClickValue = (data: LensFilterEvent['data']) => {
handlers.event({ name: 'filter', data });
};
const onSelectRange = (data: LensBrushEvent['data']) => {
handlers.event({ name: 'brush', data });
};
const formatFactory = await dependencies.formatFactory;
ReactDOM.render(
<I18nProvider>
<XYChartReportable
{...config}
formatFactory={formatFactory}
chartsThemeService={dependencies.chartsThemeService}
paletteService={dependencies.paletteService}
timeZone={dependencies.timeZone}
minInterval={await calculateMinInterval(config, dependencies.getIntervalByColumn)}
onClickValue={onClickValue}
onSelectRange={onSelectRange}
renderMode={handlers.getRenderMode()}
/>
</I18nProvider>,
domNode,
() => handlers.done()
);
},
}) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
() => undefined | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
async (
domNode: Element,
config: XYChartProps,
handlers: ILensInterpreterRenderHandlers
) => {
handlers.onDestroy(() => ReactDOM.unmountComponentAtNode(domNode));
const onClickValue = (data: LensFilterEvent['data']) => {
handlers.event({ name: 'filter', data });
};
const onSelectRange = (data: LensBrushEvent['data']) => {
handlers.event({ name: 'brush', data });
};
const formatFactory = await dependencies.formatFactory;
ReactDOM.render(
<I18nProvider>
<XYChartReportable
{...config}
formatFactory={formatFactory}
chartsThemeService={dependencies.chartsThemeService}
paletteService={dependencies.paletteService}
timeZone={dependencies.timeZone}
minInterval={await calculateMinInterval(config, dependencies.getIntervalByColumn)}
onClickValue={onClickValue}
onSelectRange={onSelectRange}
renderMode={handlers.getRenderMode()}
/>
</I18nProvider>,
domNode,
() => handlers.done()
);
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
() => ReactDOM.unmountComponentAtNode(domNode) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(data: LensFilterEvent['data']) => {
handlers.event({ name: 'filter', data });
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(data: LensBrushEvent['data']) => {
handlers.event({ name: 'brush', data });
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
() => handlers.done() | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(c) => c.id === seriesType | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
() => {
setState({ isReady: true });
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
({ id }) => id === filteredLayers[0].xAccessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(value: unknown): string =>
xAxisColumn && layersAlreadyFormatted[xAxisColumn.id]
? (value as string)
: xAxisFormatter.convert(value) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(layer) => layer.accessors.length > 1 | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(layer) => layer.splitAccessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(layer) => layer.seriesType.includes('bar') | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(l) => l.isHistogram | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(
axisSeries: Array<{ layer: string; accessor: string }>,
groupId: string
) => {
const yTitle = groupId === 'right' ? args.yRightTitle : args.yTitle;
return (
yTitle ||
axisSeries
.map(
(series) =>
data.tables[series.layer].columns.find((column) => column.id === series.accessor)?.name
)
.filter((name) => Boolean(name))[0]
);
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(series) =>
data.tables[series.layer].columns.find((column) => column.id === series.accessor)?.name | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(column) => column.id === series.accessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(name) => Boolean(name) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(groupId: string) => {
const style = {
tickLabel: {
visible:
groupId === 'right'
? tickLabelsVisibilitySettings?.yRight
: tickLabelsVisibilitySettings?.yLeft,
},
axisTitle: {
visible:
groupId === 'right'
? axisTitlesVisibilitySettings?.yRight
: axisTitlesVisibilitySettings?.yLeft,
},
};
return style;
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(layer) => !layer.seriesType.includes('stacked') | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
([[geometry, series]]) => {
// for xyChart series is always XYChartSeriesIdentifier and geometry is always type of GeometryValue
const xySeries = series as XYChartSeriesIdentifier;
const xyGeometry = geometry as GeometryValue;
const layer = filteredLayers.find((l) =>
xySeries.seriesKeys.some((key: string | number) => l.accessors.includes(key.toString()))
);
if (!layer) {
return;
}
const table = data.tables[layer.layerId];
const points = [
{
row: table.rows.findIndex((row) => {
if (layer.xAccessor) {
if (layersAlreadyFormatted[layer.xAccessor]) {
// stringify the value to compare with the chart value
return xAxisFormatter.convert(row[layer.xAccessor]) === xyGeometry.x;
}
return row[layer.xAccessor] === xyGeometry.x;
}
}),
column: table.columns.findIndex((col) => col.id === layer.xAccessor),
value: xyGeometry.x,
},
];
if (xySeries.seriesKeys.length > 1) {
const pointValue = xySeries.seriesKeys[0];
points.push({
row: table.rows.findIndex(
(row) => layer.splitAccessor && row[layer.splitAccessor] === pointValue
),
column: table.columns.findIndex((col) => col.id === layer.splitAccessor),
value: pointValue,
});
}
const xAxisFieldName = table.columns.find((el) => el.id === layer.xAccessor)?.meta?.field;
const timeFieldName = xDomain && xAxisFieldName;
const context: LensFilterEvent['data'] = {
data: points.map((point) => ({
row: point.row,
column: point.column,
value: point.value,
table,
})),
timeFieldName,
};
onClickValue(desanitizeFilterContext(context));
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(l) =>
xySeries.seriesKeys.some((key: string | number) => l.accessors.includes(key.toString())) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(key: string | number) => l.accessors.includes(key.toString()) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(row) => {
if (layer.xAccessor) {
if (layersAlreadyFormatted[layer.xAccessor]) {
// stringify the value to compare with the chart value
return xAxisFormatter.convert(row[layer.xAccessor]) === xyGeometry.x;
}
return row[layer.xAccessor] === xyGeometry.x;
}
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(col) => col.id === layer.xAccessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(row) => layer.splitAccessor && row[layer.splitAccessor] === pointValue | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(col) => col.id === layer.splitAccessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(el) => el.id === layer.xAccessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(point) => ({
row: point.row,
column: point.column,
value: point.value,
table,
}) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
({ x }) => {
if (!x) {
return;
}
const [min, max] = x;
if (!xAxisColumn || !isHistogramViz) {
return;
}
const table = data.tables[filteredLayers[0].layerId];
const xAxisColumnIndex = table.columns.findIndex((el) => el.id === filteredLayers[0].xAccessor);
const timeFieldName = isTimeViz ? table.columns[xAxisColumnIndex]?.meta?.field : undefined;
const context: LensBrushEvent['data'] = {
range: [min, max],
table,
column: xAxisColumnIndex,
timeFieldName,
};
onSelectRange(context);
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(el) => el.id === filteredLayers[0].xAccessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(d) => safeXAccessorLabelRenderer(d.value) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(axis) => (
<Axis
key={axis.groupId} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(layer, layerIndex) =>
layer.accessors.map((accessor, accessorIndex) => {
const {
splitAccessor,
seriesType,
accessors,
xAccessor,
layerId,
columnToLabel,
yScaleType,
xScaleType,
isHistogram,
palette,
} = layer;
const columnToLabelMap: Record<string, string> = columnToLabel
? JSON.parse(columnToLabel)
: {};
const table = data.tables[layerId];
const isPrimitive = (value: unknown): boolean =>
value != null && typeof value !== 'object';
// what if row values are not primitive? That is the case of, for instance, Ranges
// remaps them to their serialized version with the formatHint metadata
// In order to do it we need to make a copy of the table as the raw one is required for more features (filters, etc...) later on
const tableConverted: Datatable = {
...table,
rows: table.rows.map((row: DatatableRow) => {
const newRow = { ...row };
for (const column of table.columns) {
const record = newRow[column.id];
if (record && !isPrimitive(record)) {
newRow[column.id] = formatFactory(column.meta.params).convert(record);
}
}
return newRow;
}),
};
// save the id of the layer with the custom table
table.columns.reduce<Record<string, boolean>>(
(alreadyFormatted: Record<string, boolean>, { id }) => {
if (alreadyFormatted[id]) {
return alreadyFormatted;
}
alreadyFormatted[id] = table.rows.some(
(row, i) => row[id] !== tableConverted.rows[i][id]
);
return alreadyFormatted;
},
layersAlreadyFormatted
);
// For date histogram chart type, we're getting the rows that represent intervals without data.
// To not display them in the legend, they need to be filtered out.
const rows = tableConverted.rows.filter(
(row) =>
!(xAccessor && typeof row[xAccessor] === 'undefined') &&
!(
splitAccessor &&
typeof row[splitAccessor] === 'undefined' &&
typeof row[accessor] === 'undefined'
)
);
if (!xAccessor) {
rows.forEach((row) => {
row.unifiedX = i18n.translate('xpack.lens.xyChart.emptyXLabel', {
defaultMessage: '(empty)',
});
});
}
const yAxis = yAxesConfiguration.find((axisConfiguration) =>
axisConfiguration.series.find((currentSeries) => currentSeries.accessor === accessor)
);
const seriesProps: SeriesSpec = {
splitSeriesAccessors: splitAccessor ? [splitAccessor] : [],
stackAccessors: seriesType.includes('stacked') ? [xAccessor as string] : [],
id: `${splitAccessor}-${accessor}`,
xAccessor: xAccessor || 'unifiedX',
yAccessors: [accessor],
data: rows,
xScaleType: xAccessor ? xScaleType : 'ordinal',
yScaleType,
color: ({ yAccessor, seriesKeys }) => {
const overwriteColor = getSeriesColor(layer, accessor);
if (overwriteColor !== null) {
return overwriteColor;
}
const colorAssignment = colorAssignments[palette.name];
const seriesLayers: SeriesLayer[] = [
{
name: splitAccessor ? String(seriesKeys[0]) : columnToLabelMap[seriesKeys[0]],
totalSeriesAtDepth: colorAssignment.totalSeriesCount,
rankAtDepth: colorAssignment.getRank(
layer,
String(seriesKeys[0]),
String(yAccessor)
),
},
];
return paletteService.get(palette.name).getColor(
seriesLayers,
{
maxDepth: 1,
behindText: false,
totalSeries: colorAssignment.totalSeriesCount,
},
palette.params
);
},
groupId: yAxis?.groupId,
enableHistogramMode:
isHistogram &&
(seriesType.includes('stacked') || !splitAccessor) &&
(seriesType.includes('stacked') ||
!seriesType.includes('bar') ||
!chartHasMoreThanOneBarSeries),
stackMode: seriesType.includes('percentage') ? StackMode.Percentage : undefined,
timeZone,
areaSeriesStyle: {
point: {
visible: !xAccessor,
radius: 5,
},
},
lineSeriesStyle: {
point: {
visible: !xAccessor,
radius: 5,
},
},
name(d) {
const splitHint = table.columns.find((col) => col.id === splitAccessor)?.meta?.params;
// For multiple y series, the name of the operation is used on each, either:
// * Key - Y name
// * Formatted value - Y name
if (accessors.length > 1) {
const result = d.seriesKeys
.map((key: string | number, i) => {
if (
i === 0 &&
splitHint &&
splitAccessor &&
!layersAlreadyFormatted[splitAccessor]
) {
return formatFactory(splitHint).convert(key);
}
return splitAccessor && i === 0 ? key : columnToLabelMap[key] ?? '';
})
.join(' - ');
return result;
}
// For formatted split series, format the key
// This handles splitting by dates, for example
if (splitHint) {
if (splitAccessor && layersAlreadyFormatted[splitAccessor]) {
return d.seriesKeys[0];
}
return formatFactory(splitHint).convert(d.seriesKeys[0]);
}
// This handles both split and single-y cases:
// * If split series without formatting, show the value literally
// * If single Y, the seriesKey will be the accessor, so we show the human-readable name
return splitAccessor ? d.seriesKeys[0] : columnToLabelMap[d.seriesKeys[0]] ?? '';
},
};
const index = `${layerIndex}-${accessorIndex}`;
switch (seriesType) {
case 'line':
return (
<LineSeries key={index} {...seriesProps | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(accessor, accessorIndex) => {
const {
splitAccessor,
seriesType,
accessors,
xAccessor,
layerId,
columnToLabel,
yScaleType,
xScaleType,
isHistogram,
palette,
} = layer;
const columnToLabelMap: Record<string, string> = columnToLabel
? JSON.parse(columnToLabel)
: {};
const table = data.tables[layerId];
const isPrimitive = (value: unknown): boolean =>
value != null && typeof value !== 'object';
// what if row values are not primitive? That is the case of, for instance, Ranges
// remaps them to their serialized version with the formatHint metadata
// In order to do it we need to make a copy of the table as the raw one is required for more features (filters, etc...) later on
const tableConverted: Datatable = {
...table,
rows: table.rows.map((row: DatatableRow) => {
const newRow = { ...row };
for (const column of table.columns) {
const record = newRow[column.id];
if (record && !isPrimitive(record)) {
newRow[column.id] = formatFactory(column.meta.params).convert(record);
}
}
return newRow;
}),
};
// save the id of the layer with the custom table
table.columns.reduce<Record<string, boolean>>(
(alreadyFormatted: Record<string, boolean>, { id }) => {
if (alreadyFormatted[id]) {
return alreadyFormatted;
}
alreadyFormatted[id] = table.rows.some(
(row, i) => row[id] !== tableConverted.rows[i][id]
);
return alreadyFormatted;
},
layersAlreadyFormatted
);
// For date histogram chart type, we're getting the rows that represent intervals without data.
// To not display them in the legend, they need to be filtered out.
const rows = tableConverted.rows.filter(
(row) =>
!(xAccessor && typeof row[xAccessor] === 'undefined') &&
!(
splitAccessor &&
typeof row[splitAccessor] === 'undefined' &&
typeof row[accessor] === 'undefined'
)
);
if (!xAccessor) {
rows.forEach((row) => {
row.unifiedX = i18n.translate('xpack.lens.xyChart.emptyXLabel', {
defaultMessage: '(empty)',
});
});
}
const yAxis = yAxesConfiguration.find((axisConfiguration) =>
axisConfiguration.series.find((currentSeries) => currentSeries.accessor === accessor)
);
const seriesProps: SeriesSpec = {
splitSeriesAccessors: splitAccessor ? [splitAccessor] : [],
stackAccessors: seriesType.includes('stacked') ? [xAccessor as string] : [],
id: `${splitAccessor}-${accessor}`,
xAccessor: xAccessor || 'unifiedX',
yAccessors: [accessor],
data: rows,
xScaleType: xAccessor ? xScaleType : 'ordinal',
yScaleType,
color: ({ yAccessor, seriesKeys }) => {
const overwriteColor = getSeriesColor(layer, accessor);
if (overwriteColor !== null) {
return overwriteColor;
}
const colorAssignment = colorAssignments[palette.name];
const seriesLayers: SeriesLayer[] = [
{
name: splitAccessor ? String(seriesKeys[0]) : columnToLabelMap[seriesKeys[0]],
totalSeriesAtDepth: colorAssignment.totalSeriesCount,
rankAtDepth: colorAssignment.getRank(
layer,
String(seriesKeys[0]),
String(yAccessor)
),
},
];
return paletteService.get(palette.name).getColor(
seriesLayers,
{
maxDepth: 1,
behindText: false,
totalSeries: colorAssignment.totalSeriesCount,
},
palette.params
);
},
groupId: yAxis?.groupId,
enableHistogramMode:
isHistogram &&
(seriesType.includes('stacked') || !splitAccessor) &&
(seriesType.includes('stacked') ||
!seriesType.includes('bar') ||
!chartHasMoreThanOneBarSeries),
stackMode: seriesType.includes('percentage') ? StackMode.Percentage : undefined,
timeZone,
areaSeriesStyle: {
point: {
visible: !xAccessor,
radius: 5,
},
},
lineSeriesStyle: {
point: {
visible: !xAccessor,
radius: 5,
},
},
name(d) {
const splitHint = table.columns.find((col) => col.id === splitAccessor)?.meta?.params;
// For multiple y series, the name of the operation is used on each, either:
// * Key - Y name
// * Formatted value - Y name
if (accessors.length > 1) {
const result = d.seriesKeys
.map((key: string | number, i) => {
if (
i === 0 &&
splitHint &&
splitAccessor &&
!layersAlreadyFormatted[splitAccessor]
) {
return formatFactory(splitHint).convert(key);
}
return splitAccessor && i === 0 ? key : columnToLabelMap[key] ?? '';
})
.join(' - ');
return result;
}
// For formatted split series, format the key
// This handles splitting by dates, for example
if (splitHint) {
if (splitAccessor && layersAlreadyFormatted[splitAccessor]) {
return d.seriesKeys[0];
}
return formatFactory(splitHint).convert(d.seriesKeys[0]);
}
// This handles both split and single-y cases:
// * If split series without formatting, show the value literally
// * If single Y, the seriesKey will be the accessor, so we show the human-readable name
return splitAccessor ? d.seriesKeys[0] : columnToLabelMap[d.seriesKeys[0]] ?? '';
},
};
const index = `${layerIndex}-${accessorIndex}`;
switch (seriesType) {
case 'line':
return (
<LineSeries key={index} { | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(value: unknown): boolean =>
value != null && typeof value !== 'object' | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(row: DatatableRow) => {
const newRow = { ...row };
for (const column of table.columns) {
const record = newRow[column.id];
if (record && !isPrimitive(record)) {
newRow[column.id] = formatFactory(column.meta.params).convert(record);
}
}
return newRow;
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(alreadyFormatted: Record<string, boolean>, { id }) => {
if (alreadyFormatted[id]) {
return alreadyFormatted;
}
alreadyFormatted[id] = table.rows.some(
(row, i) => row[id] !== tableConverted.rows[i][id]
);
return alreadyFormatted;
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(row, i) => row[id] !== tableConverted.rows[i][id] | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(row) =>
!(xAccessor && typeof row[xAccessor] === 'undefined') &&
!(
splitAccessor &&
typeof row[splitAccessor] === 'undefined' &&
typeof row[accessor] === 'undefined'
) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(row) => {
row.unifiedX = i18n.translate('xpack.lens.xyChart.emptyXLabel', {
defaultMessage: '(empty)',
});
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(axisConfiguration) =>
axisConfiguration.series.find((currentSeries) => currentSeries.accessor === accessor) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(currentSeries) => currentSeries.accessor === accessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
({ yAccessor, seriesKeys }) => {
const overwriteColor = getSeriesColor(layer, accessor);
if (overwriteColor !== null) {
return overwriteColor;
}
const colorAssignment = colorAssignments[palette.name];
const seriesLayers: SeriesLayer[] = [
{
name: splitAccessor ? String(seriesKeys[0]) : columnToLabelMap[seriesKeys[0]],
totalSeriesAtDepth: colorAssignment.totalSeriesCount,
rankAtDepth: colorAssignment.getRank(
layer,
String(seriesKeys[0]),
String(yAccessor)
),
},
];
return paletteService.get(palette.name).getColor(
seriesLayers,
{
maxDepth: 1,
behindText: false,
totalSeries: colorAssignment.totalSeriesCount,
},
palette.params
);
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(col) => col.id === splitAccessor | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(key: string | number, i) => {
if (
i === 0 &&
splitHint &&
splitAccessor &&
!layersAlreadyFormatted[splitAccessor]
) {
return formatFactory(splitHint).convert(key);
}
return splitAccessor && i === 0 ? key : columnToLabelMap[key] ?? '';
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(d: unknown) => yAxis?.formatter?.convert(d) || '' | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
({ layerId, xAccessor, accessors, splitAccessor }) => {
return !(
!accessors.length ||
!data.tables[layerId] ||
data.tables[layerId].rows.length === 0 ||
(xAccessor &&
data.tables[layerId].rows.every((row) => typeof row[xAccessor] === 'undefined')) ||
// stacked percentage bars have no xAccessors but splitAccessor with undefined values in them when empty
(!xAccessor &&
splitAccessor &&
data.tables[layerId].rows.every((row) => typeof row[splitAccessor] === 'undefined'))
);
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(row) => typeof row[xAccessor] === 'undefined' | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
ArrowFunction |
(row) => typeof row[splitAccessor] === 'undefined' | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
InterfaceDeclaration |
export interface XYChartProps {
data: LensMultiTable;
args: XYArgs;
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
InterfaceDeclaration |
export interface XYRender {
type: 'render';
as: 'lens_xy_chart_renderer';
value: XYChartProps;
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
TypeAliasDeclaration |
type InferPropType<T> = T extends React.FunctionComponent<infer P> ? P : T; | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
TypeAliasDeclaration |
type SeriesSpec = InferPropType<typeof LineSeries> &
InferPropType<typeof BarSeries> &
InferPropType<typeof AreaSeries>; | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
TypeAliasDeclaration |
type XYChartRenderProps = XYChartProps & {
chartsThemeService: ChartsPluginSetup['theme'];
paletteService: PaletteRegistry;
formatFactory: FormatFactory;
timeZone: string;
minInterval: number | undefined;
onClickValue: (data: LensFilterEvent['data']) => void;
onSelectRange: (data: LensBrushEvent['data']) => void;
renderMode: RenderMode;
}; | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
MethodDeclaration |
fn(data: LensMultiTable, args: XYArgs) {
return {
type: 'render',
as: 'lens_xy_chart_renderer',
value: {
data,
args,
},
};
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
MethodDeclaration |
getYAxesTitles(axis | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
MethodDeclaration |
getYAxesStyle(axis | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
MethodDeclaration |
name(d) {
const splitHint = table.columns.find((col) => col.id === splitAccessor)?.meta?.params;
// For multiple y series, the name of the operation is used on each, either:
// * Key - Y name
// * Formatted value - Y name
if (accessors.length > 1) {
const result = d.seriesKeys
.map((key: string | number, i) => {
if (
i === 0 &&
splitHint &&
splitAccessor &&
!layersAlreadyFormatted[splitAccessor]
) {
return formatFactory(splitHint).convert(key);
}
return splitAccessor && i === 0 ? key : columnToLabelMap[key] ?? '';
})
.join(' - ');
return result;
}
// For formatted split series, format the key
// This handles splitting by dates, for example
if (splitHint) {
if (splitAccessor && layersAlreadyFormatted[splitAccessor]) {
return d.seriesKeys[0];
}
return formatFactory(splitHint).convert(d.seriesKeys[0]);
}
// This handles both split and single-y cases:
// * If split series without formatting, show the value literally
// * If single Y, the seriesKey will be the accessor, so we show the human-readable name
return splitAccessor ? d.seriesKeys[0] : columnToLabelMap[d.seriesKeys[0]] ?? '';
} | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
MethodDeclaration |
getFitOptions(fittingFunction) | AlexanderWert/kibana | x-pack/plugins/lens/public/xy_visualization/expression.tsx | TypeScript |
FunctionDeclaration |
export default function CompanyDetails(props: CompanyDetailsProps) {
const { label = '', namePrefix, requiredFields, visibility } = props;
const { i18n } = useCoreContext();
const { handleChangeFor, triggerValidation, data, valid, errors, isValid } = useForm<CompanyDetailsSchema>({
schema: requiredFields,
rules: props.validationRules,
defaultData: props.data
});
const generateFieldName = (name: string): string => `${namePrefix ? `${namePrefix}.` : ''}${name}`;
const eventHandler = (mode: string): Function => (e: Event): void => {
const { name } = e.target as HTMLInputElement;
const key = name.split(`${namePrefix}.`).pop();
handleChangeFor(key, mode)(e);
};
useEffect(() => {
const formattedData = getFormattedData(data);
props.onChange({ data: formattedData, valid, errors, isValid });
}, [data, valid, errors, isValid]);
this.showValidation = triggerValidation;
if (visibility === 'hidden') return null;
if (visibility === 'readOnly') return <ReadOnlyCompanyDetails {...props} data={data} />;
return (
<Fieldset classNameModifiers={[label]} label={label}>
{requiredFields.includes('name') && (
<Field label={i18n.get('companyDetails.name')} classNameModifiers={['name']} errorMessage={!!errors.name} | Adyen/adyen-web | packages/lib/src/components/internal/CompanyDetails/CompanyDetails.tsx | TypeScript |
ArrowFunction |
(name: string): string => `${namePrefix ? `${namePrefix}.` : ''}${name}` | Adyen/adyen-web | packages/lib/src/components/internal/CompanyDetails/CompanyDetails.tsx | TypeScript |
ArrowFunction |
(mode: string): Function => (e: Event): void => {
const { name } = e.target as HTMLInputElement;
const key = name.split(`${namePrefix}.`).pop();
handleChangeFor(key, mode)(e);
} | Adyen/adyen-web | packages/lib/src/components/internal/CompanyDetails/CompanyDetails.tsx | TypeScript |
ArrowFunction |
(e: Event): void => {
const { name } = e.target as HTMLInputElement;
const key = name.split(`${namePrefix}.`).pop();
handleChangeFor(key, mode)(e);
} | Adyen/adyen-web | packages/lib/src/components/internal/CompanyDetails/CompanyDetails.tsx | TypeScript |
ArrowFunction |
() => {
const formattedData = getFormattedData(data);
props.onChange({ data: formattedData, valid, errors, isValid });
} | Adyen/adyen-web | packages/lib/src/components/internal/CompanyDetails/CompanyDetails.tsx | TypeScript |
MethodDeclaration |
renderFormField('text', {
name: generateFieldName | Adyen/adyen-web | packages/lib/src/components/internal/CompanyDetails/CompanyDetails.tsx | TypeScript |
ArrowFunction |
() => {
describe("with a new release", () => {
beforeEach(() => {
jest
.spyOn(updateSelectors, "getShouldRenderUpdateAvailableLink")
.mockReturnValue(true);
});
afterEach(() => jest.clearAllMocks());
it("renders the 'Update available' link when an update is available", () => {
const {
tree: { root }
} = testRender(<AppVersionItem item={item} style={{}} />);
const updateLink = root.findByType(Button);
expect(updateLink).toBeDefined();
expect(
updateLink.findByProps({ title: "Update available" })
).toBeDefined();
});
it("should navigate to the UpdateDetails screen on press", () => {
const { queryByTestId, navigation } = renderWithProviders(
<AppVersionItem item={item} style={{}} />
);
const updateLink = queryByTestId("versionItemDescription");
act(() => updateLink?.props.onPress());
expect(navigation.navigate).toHaveBeenCalledWith("UpdateDetails");
} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => {
beforeEach(() => {
jest
.spyOn(updateSelectors, "getShouldRenderUpdateAvailableLink")
.mockReturnValue(true);
});
afterEach(() => jest.clearAllMocks());
it("renders the 'Update available' link when an update is available", () => {
const {
tree: { root }
} = testRender(<AppVersionItem item={item} style={{}} />);
const updateLink = root.findByType(Button);
expect(updateLink).toBeDefined();
expect(
updateLink.findByProps({ title: "Update available" })
).toBeDefined();
} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => {
jest
.spyOn(updateSelectors, "getShouldRenderUpdateAvailableLink")
.mockReturnValue(true);
} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => jest.clearAllMocks() | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => {
const {
tree: { root }
} = testRender(<AppVersionItem item={item} style={{}} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => {
const { queryByTestId, navigation } = renderWithProviders(
<AppVersionItem item={item} style={{}} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => updateLink?.props.onPress() | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => {
mixpanelSpy = spy(analyticsUtils, "track");
const linkEvent =
analyticsUtils.Event.ControlledUpdateDetailsViewedFromAccount;
const { queryByTestId } = renderWithProviders(
<AppVersionItem item={item} style={{}} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => {
beforeEach(() => {
jest
.spyOn(updateSelectors, "getShouldRenderUpdateAvailableLink")
.mockReturnValue(false);
});
afterEach(() => jest.clearAllMocks());
it("should return null if getShould RenderUpdateAvailableLink selector is false", () => {
const { queryByLabelText } = renderWithProviders(
<AppVersionItem item={item} style={{}} />
);
const updateLink = queryByLabelText("App update available");
expect(updateLink).toBeNull();
} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => {
jest
.spyOn(updateSelectors, "getShouldRenderUpdateAvailableLink")
.mockReturnValue(false);
} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
() => {
const { queryByLabelText } = renderWithProviders(
<AppVersionItem item={item} style={{}} | ethanneff/MobileComponents | src/components/List/__tests__/AppVersionItem.spec.tsx | TypeScript |
ArrowFunction |
(props: WithExtractedCurrentUserProps) => !!props.currentUser | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
(props: WithStateProps<State> & WithCurrentUserProps) =>
async (post: Post) =>
{
const { setState, currentUser } = props;
// jw: if the current user is not the author, then there is nothing to do.
if (currentUser.oid !== post.author.oid) {
return;
}
setState(ss => ({ ...ss, postForDeletion: post }));
} | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
async (post: Post) =>
{
const { setState, currentUser } = props;
// jw: if the current user is not the author, then there is nothing to do.
if (currentUser.oid !== post.author.oid) {
return;
}
setState(ss => ({ ...ss, postForDeletion: post }));
} | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
ss => ({ ...ss, postForDeletion: post }) | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
(props: WithStateProps<State>) => async () => {
const { setState } = props;
setState(ss => ({ ...ss, postForDeletion: undefined }));
} | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
async () => {
const { setState } = props;
setState(ss => ({ ...ss, postForDeletion: undefined }));
} | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
ss => ({ ...ss, postForDeletion: undefined }) | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
(props: HandleDeletePostProps) => async () => {
const { deletePost, intl, onPostDeleted, setState, currentUser, state: { postForDeletion } } = props;
// jw: if we do not have a post to delete, there is nothing to do.
if (!postForDeletion) {
return;
}
// jw: if the current user is not the author then there is nothing to do.
if (currentUser.oid !== postForDeletion.author.oid) {
return;
}
setState(ss => ({ ...ss, isDeletingPost: true }));
try {
await deletePost(postForDeletion.oid);
if (onPostDeleted) {
onPostDeleted();
}
} catch (err) {
showValidationErrorDialogIfNecessary(intl.formatMessage(SharedComponentMessages.FormErrorTitle), err);
}
setState(ss => ({ ...ss, isDeletingPost: false, postForDeletion: undefined }));
} | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
async () => {
const { deletePost, intl, onPostDeleted, setState, currentUser, state: { postForDeletion } } = props;
// jw: if we do not have a post to delete, there is nothing to do.
if (!postForDeletion) {
return;
}
// jw: if the current user is not the author then there is nothing to do.
if (currentUser.oid !== postForDeletion.author.oid) {
return;
}
setState(ss => ({ ...ss, isDeletingPost: true }));
try {
await deletePost(postForDeletion.oid);
if (onPostDeleted) {
onPostDeleted();
}
} catch (err) {
showValidationErrorDialogIfNecessary(intl.formatMessage(SharedComponentMessages.FormErrorTitle), err);
}
setState(ss => ({ ...ss, isDeletingPost: false, postForDeletion: undefined }));
} | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
ss => ({ ...ss, isDeletingPost: true }) | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
ArrowFunction |
ss => ({ ...ss, isDeletingPost: false, postForDeletion: undefined }) | NarrativeCompany/narrative | react-ui/packages/web/src/shared/containers/withDeletePostController.ts | TypeScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.