chore(frontend): migrate utility JS files to TypeScript (#36721)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2025-12-18 13:54:40 -08:00
committed by GitHub
parent 32435bc3e9
commit da8e077a44
12 changed files with 146 additions and 153 deletions

View File

@@ -1,52 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import memoizeOne from 'memoize-one';
import { isControlPanelSectionConfig } from '@superset-ui/chart-controls';
import { getChartControlPanelRegistry } from '@superset-ui/core';
import { controls } from '../explore/controls';
const memoizedControls = memoizeOne((vizType, controlPanel) => {
const controlsMap = {};
(controlPanel?.controlPanelSections || [])
.filter(isControlPanelSectionConfig)
.forEach(section => {
section.controlSetRows.forEach(row => {
row.forEach(control => {
if (!control) return;
if (typeof control === 'string') {
// For now, we have to look in controls.jsx to get the config for some controls.
// Once everything is migrated out, delete this if statement.
controlsMap[control] = controls[control];
} else if (control.name && control.config) {
// condition needed because there are elements, e.g. <hr /> in some control configs (I'm looking at you, FilterBox!)
controlsMap[control.name] = control.config;
}
});
});
});
return controlsMap;
});
const getControlsForVizType = vizType => {
const controlPanel = getChartControlPanelRegistry().get(vizType);
return memoizedControls(vizType, controlPanel);
};
export default getControlsForVizType;

View File

@@ -1,71 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { nanoid } from 'nanoid';
export function addToObject(state, arrKey, obj) {
const newObject = { ...state[arrKey] };
const copiedObject = { ...obj };
if (!copiedObject.id) {
copiedObject.id = nanoid();
}
newObject[copiedObject.id] = copiedObject;
return { ...state, [arrKey]: newObject };
}
export function alterInObject(state, arrKey, obj, alterations) {
const newObject = { ...state[arrKey] };
newObject[obj.id] = { ...newObject[obj.id], ...alterations };
return { ...state, [arrKey]: newObject };
}
export function alterInArr(state, arrKey, obj, alterations) {
// Finds an item in an array in the state and replaces it with a
// new object with an altered property
const idKey = 'id';
const newArr = [];
state[arrKey].forEach(arrItem => {
if (obj[idKey] === arrItem[idKey]) {
newArr.push({ ...arrItem, ...alterations });
} else {
newArr.push(arrItem);
}
});
return { ...state, [arrKey]: newArr };
}
export function removeFromArr(state, arrKey, obj, idKey = 'id') {
const newArr = [];
state[arrKey].forEach(arrItem => {
if (!(obj[idKey] === arrItem[idKey])) {
newArr.push(arrItem);
}
});
return { ...state, [arrKey]: newArr };
}
export function addToArr(state, arrKey, obj) {
const newObj = { ...obj };
if (!newObj.id) {
newObj.id = nanoid();
}
const newState = {};
newState[arrKey] = [...state[arrKey], newObj];
return { ...state, ...newState };
}