Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate AlteredSliceTag to typescript #27030

Merged
merged 14 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
import { QueryFormData } from '@superset-ui/core';
import { ControlPanelConfig } from 'packages/superset-ui-chart-controls/src/types';
import { Row } from './index';

export const defaultProps = {
export const defaultProps: Record<string, Partial<QueryFormData>> = {
origFormData: {
viz_type: 'altered_slice_tag_spec',
adhoc_filters: [
Expand Down Expand Up @@ -57,7 +60,7 @@ export const defaultProps = {
},
};

export const expectedDiffs = {
export const expectedDiffs: Record<string, Partial<QueryFormData>> = {
adhoc_filters: {
before: [
{
Expand Down Expand Up @@ -103,7 +106,7 @@ export const expectedDiffs = {
after: { x: 'y', z: 'z' },
},
};
export const expectedRows = [
export const expectedRows: Partial<Row>[] = [
{
control: 'Fake Filters',
before: 'a == hello',
Expand All @@ -128,7 +131,7 @@ export const expectedRows = [
after: '{"x":"y","z":"z"}',
},
];
export const fakePluginControls = {
export const fakePluginControls: ControlPanelConfig = {
controlPanelSections: [
{
label: 'Fake Control Panel Sections',
Expand Down
24 changes: 13 additions & 11 deletions superset-frontend/src/components/AlteredSliceTag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@ export interface ControlMap {
};
}

interface Diff {
type Diff = {
before: [];
after: [];
}
};

interface Row {
export type Row = {
control: string;
before: string;
after: string;
}
interface FilterItem {
before: string | number;
after: string | number;
};

type FilterItem = {
comparator?: string | string[];
subject: string;
operator: string;
label?: string;
}
};

interface AlteredSliceTagState {
rows: Row[];
hasDiffs: boolean;
Expand Down Expand Up @@ -198,7 +200,7 @@ class AlteredSliceTag extends React.Component<
return safeStringify(value);
}

renderModalBody(): JSX.Element {
renderModalBody(): React.ReactNode {
const columns = [
{
accessor: 'control',
Expand Down Expand Up @@ -227,15 +229,15 @@ class AlteredSliceTag extends React.Component<
);
}

renderTriggerNode(): JSX.Element {
renderTriggerNode(): React.ReactNode {
return (
<Tooltip id="difference-tooltip" title={t('Click to see difference')}>
<StyledLabel className="label">{t('Altered')}</StyledLabel>
</Tooltip>
);
}

render(): JSX.Element | null {
render() {
// Return nothing if there are no differences
if (!this.state.hasDiffs) {
return null;
Expand Down