chore(frontend): migrate easy JS/JSX files to TypeScript (#36713)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2025-12-17 17:12:02 -08:00
committed by GitHub
parent ae584c8886
commit 2f4f64dfe8
15 changed files with 50 additions and 21 deletions

View File

@@ -18,13 +18,17 @@
*/
import { IN_COMPONENT_ELEMENT_TYPES } from './constants';
export default function getChartAndLabelComponentIdFromPath(directPathToChild) {
const result = {};
export default function getChartAndLabelComponentIdFromPath(
directPathToChild: (string | undefined)[],
): Record<string, string> {
const result: Record<string, string> = {};
if (directPathToChild.length > 0) {
const currentPath = directPathToChild.slice().filter(x => x !== undefined);
const currentPath = directPathToChild
.slice()
.filter((x): x is string => x !== undefined);
while (currentPath.length) {
const componentId = currentPath.pop();
const componentId = currentPath.pop()!;
const componentType = componentId.split('-')[0];
result[componentType.toLowerCase()] = componentId;

View File

@@ -16,15 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
export default function getFilterScopeParentNodes(nodes = [], depthLimit = -1) {
const parentNodes = [];
const traverse = (currentNode, depth) => {
interface FilterScopeTreeNode {
value?: string | number;
children?: FilterScopeTreeNode[];
}
export default function getFilterScopeParentNodes(
nodes: FilterScopeTreeNode[] = [],
depthLimit = -1,
): string[] {
const parentNodes: string[] = [];
const traverse = (
currentNode: FilterScopeTreeNode | undefined,
depth: number,
): void => {
if (!currentNode) {
return;
}
if (currentNode.children && (depthLimit === -1 || depth < depthLimit)) {
parentNodes.push(currentNode.value);
if (currentNode.value !== undefined) {
parentNodes.push(String(currentNode.value));
}
currentNode.children.forEach(child => traverse(child, depth + 1));
}
};

View File

@@ -18,19 +18,31 @@
*/
import { getChartIdAndColumnFromFilterKey } from './getDashboardFilterKey';
interface ActiveFilterEntry {
values: unknown;
}
type ActiveFiltersInput = Record<string, ActiveFilterEntry>;
type SerializedFilters = Record<string, Record<string, unknown>>;
// input: { [id_column1]: values, [id_column2]: values }
// output: { id: { column1: values, column2: values } }
export default function serializeActiveFilterValues(activeFilters) {
return Object.entries(activeFilters).reduce((map, entry) => {
const [filterKey, { values }] = entry;
const { chartId, column } = getChartIdAndColumnFromFilterKey(filterKey);
const entryByChartId = {
...map[chartId],
[column]: values,
};
return {
...map,
[chartId]: entryByChartId,
};
}, {});
export default function serializeActiveFilterValues(
activeFilters: ActiveFiltersInput,
): SerializedFilters {
return Object.entries(activeFilters).reduce<SerializedFilters>(
(map, entry) => {
const [filterKey, { values }] = entry;
const { chartId, column } = getChartIdAndColumnFromFilterKey(filterKey);
const entryByChartId = {
...map[chartId],
[column]: values,
};
return {
...map,
[chartId]: entryByChartId,
};
},
{},
);
}