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

[cleanup] Leverage our strict TypeScript configuration in additional projects #4370

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Specifiers can contribute dedicated AQL services for this feature using implemen
=== Improvements

- https://github.com/eclipse-sirius/sirius-web/issues/4368[#4368] [sirius-web] Add GraphQL subscription exception handler
- [charts] Make the npm package `sirius-components-charts` use the strict version of our TypeScript configuration
- [trees] Make the npm package `sirius-components-trees` use the strict version of our TypeScript configuration


== v2025.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2024 Obeo.
* Copyright (c) 2022, 2025 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -13,7 +13,7 @@
import * as d3 from 'd3';
import { useEffect, useRef } from 'react';
import { getFontSize, getFontStyle, getFontWeight, getTextDecoration } from '../chartOperations';
import { BarChartProps } from './BarChart.types';
import { BarChartProps, BarChartRepresentationEntry } from './BarChart.types';

const marginTop = 30;
const marginBottom = 30;
Expand All @@ -22,8 +22,9 @@ const marginLeft = 50;
const xPadding = 0.1;
const yType = d3.scaleLinear;
const yFormat = 'f';
const x = (d) => d.key;
const y = (d) => d.value;

const x = (entry: BarChartRepresentationEntry) => entry.key;
const y = (entry: BarChartRepresentationEntry) => entry.value;

export const BarChart = ({ chart }: BarChartProps) => {
const d3Container = useRef<SVGSVGElement | null>(null);
Expand Down Expand Up @@ -52,10 +53,10 @@ export const BarChart = ({ chart }: BarChartProps) => {

// Compute default domains, and unique the x-domain.
const xDomain = new d3.InternSet(X);
const yDomain = [0, d3.max(Y)];
const yDomain = [0, d3.max(Y) ?? 0];

// Omit any data not present in the x-domain.
const I = d3.range(X.length).filter((i) => xDomain.has(X[i]));
const I = d3.range(X.length).filter((i) => X[i] && xDomain.has(X[i] ?? ''));

// Construct scales, axes, and formats.
const xScale = d3.scaleBand(xDomain, xRange).padding(xPadding);
Expand All @@ -65,7 +66,7 @@ export const BarChart = ({ chart }: BarChartProps) => {

// Compute titles.
const formatValue = yScale.tickFormat(100, yFormat);
const title = (i) => `${X[i]}\n${formatValue(Y[i])}`;
const title = (index: number) => `${X[index]}\n${formatValue(Y[index] ?? 0)}`;

const selection = d3.select(d3Container.current);
selection.selectAll('*').remove(); // Remove existing content.
Expand Down Expand Up @@ -103,9 +104,9 @@ export const BarChart = ({ chart }: BarChartProps) => {
.selectAll('rect')
.data(I)
.join('rect')
.attr('x', (i) => xScale(X[i]))
.attr('y', (i) => yScale(Y[i]))
.attr('height', (i) => yScale(0) - yScale(Y[i]))
.attr('x', (index: number) => xScale(X[index] ?? '') ?? '')
.attr('y', (index: number) => yScale(Y[index] ?? 0))
.attr('height', (index: number) => yScale(0) - yScale(Y[index] ?? 0))
.attr('width', xScale.bandwidth());

if (title) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@eclipse-sirius/sirius-components-tsconfig/react-library.json",
"extends": "@eclipse-sirius/sirius-components-tsconfig/strict-react-library.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"outDir": "./dist"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Obeo.
* Copyright (c) 2023, 2025 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -46,11 +46,6 @@ export const TreeToolBar = ({
}: TreeToolBarProps) => {
const { classes } = useTreeToolbarStyles();

let treeFiltersMenu: JSX.Element;
if (treeFilters.length > 0) {
treeFiltersMenu = <TreeFiltersMenu filters={treeFilters} onTreeFilterMenuItemClick={onTreeFilterMenuItemClick} />;
}

const preferenceButtonSynchronizeTitle = synchronized
? 'Disable synchronization with representation'
: 'Enable synchronization with representation';
Expand All @@ -66,7 +61,9 @@ export const TreeToolBar = ({
const element = React.createElement(component, props);
return element;
})}
{treeFiltersMenu}
{treeFilters.length > 0 ? (
<TreeFiltersMenu filters={treeFilters} onTreeFilterMenuItemClick={onTreeFilterMenuItemClick} />
) : null}
{children}
<IconButton
color="inherit"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2024 Obeo.
* Copyright (c) 2019, 2025 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -123,19 +123,15 @@ export const TreeItem = ({
markedItemIds,
treeItemActionRender,
}: TreeItemProps) => {
const { classes } = useTreeItemStyle({ depth });

const initialState: TreeItemState = {
const [state, setState] = useState<TreeItemState>({
editingMode: false,
editingKey: null,
partHovered: null,
};

const [state, setState] = useState<TreeItemState>(initialState);
const { editingMode } = state;
});

const refDom = useRef() as any;

const { classes } = useTreeItemStyle({ depth });
const { selection, setSelection } = useSelection();
const { onDropTreeItem } = useDropTreeItem(editingContextId, treeId);

Expand All @@ -161,7 +157,7 @@ export const TreeItem = ({
}));
};

let content = null;
let content: JSX.Element | null = null;
if (item.expanded && item.children) {
content = (
<ul className={classes.ul}>
Expand Down Expand Up @@ -191,7 +187,7 @@ export const TreeItem = ({
}

let className = classes.treeItem;
let dataTestid = undefined;
let dataTestid: string | undefined = undefined;

const selected = selection.entries.find((entry) => entry.id === item.id);
if (selected) {
Expand Down Expand Up @@ -225,7 +221,7 @@ export const TreeItem = ({
};

const marked: boolean = markedItemIds.some((id) => id === item.id);
if (editingMode) {
if (state.editingMode) {
text = (
<TreeItemDirectEditInput
editingContextId={editingContextId}
Expand All @@ -238,7 +234,7 @@ export const TreeItem = ({
const styledLabelProps = {
styledString: item.label,
selected: false,
textToHighlight: textToHighlight,
textToHighlight: textToHighlight ?? '',
marked: marked,
};
text = <StyledLabel {...styledLabelProps}></StyledLabel>;
Expand Down Expand Up @@ -277,7 +273,7 @@ export const TreeItem = ({
};

const onBeginEditing = (event) => {
if (!item.editable || editingMode || readOnly || !event.currentTarget.contains(event.target as HTMLElement)) {
if (!item.editable || state.editingMode || readOnly || !event.currentTarget.contains(event.target as HTMLElement)) {
return;
}
const { key } = event;
Expand Down Expand Up @@ -335,7 +331,7 @@ export const TreeItem = ({
const query = item.kind.substring(item.kind.indexOf('?') + 1, item.kind.length);
const params = new URLSearchParams(query);
if (params.has('type')) {
tooltipText = params.get('type');
tooltipText = params.get('type') ?? 'representation';
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -10,10 +10,10 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import IconButton from '@mui/material/IconButton';
import { makeStyles } from 'tss-react/mui';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import IconButton from '@mui/material/IconButton';
import { useState } from 'react';
import { makeStyles } from 'tss-react/mui';
import { getString } from './TreeItem';
import { TreeItemActionProps, TreeItemActionState } from './TreeItemAction.types';
import { TreeItemContextMenu } from './TreeItemContextMenu';
Expand Down Expand Up @@ -56,8 +56,8 @@ export const TreeItemAction = ({
}
};

let contextMenu = null;
if (state.showContextMenu) {
let contextMenu: JSX.Element | null = null;
if (state.showContextMenu && state.menuAnchor) {
const closeContextMenu = () => {
setState((prevState) => ({
...prevState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Obeo.
* Copyright (c) 2023, 2025 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -85,24 +85,26 @@ export const TreeItemDirectEditInput = ({
});

useEffect(() => {
let cleanup = undefined;
if (initialLabelTreeItemItemError) {
addErrorMessage('An unexpected error has occurred, please refresh the page');
}
if (initialLabelTreeItemItemData?.viewer.editingContext.representation.description.initialDirectEditTreeItemLabel) {
const initialLabel =
initialLabelTreeItemItemData?.viewer.editingContext.representation.description.initialDirectEditTreeItemLabel;
const initialLabel =
initialLabelTreeItemItemData?.viewer.editingContext.representation.description.initialDirectEditTreeItemLabel;
if (initialLabel) {
if (!editingKey) {
setState((prevState) => {
return { ...prevState, newLabel: initialLabel };
});
const timeOutId = setTimeout(() => {
textInput.current.select();
if (textInput.current) {
textInput.current.select();
}
}, 0);
cleanup = () => clearTimeout(timeOutId);

return () => clearTimeout(timeOutId);
}
}
return cleanup;
return () => {};
}, [initialLabelTreeItemItemError, initialLabelTreeItemItemData]);

const [renameTreeItem, { data: renameTreeItemData, error: renameTreeItemError }] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Obeo.
* Copyright (c) 2023, 2025 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -15,7 +15,7 @@ export interface TreeItemDirectEditInputProps {
editingContextId: string;
treeId: string;
treeItemId: string;
editingKey: string;
editingKey: string | null;
onClose: () => void;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Obeo.
* Copyright (c) 2023, 2025 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -22,12 +22,12 @@ export const isFilterCandidate = (treeItem: GQLTreeItem, textToFilter: string |
filter = false;
} else if (
!treeItem.hasChildren &&
splitLabelWithTextToHighlight.length === 1 &&
splitLabelWithTextToHighlight[0] &&
splitLabelWithTextToHighlight[0].toLocaleLowerCase() !== textToFilter.toLocaleLowerCase()
) {
filter = true;
} else if (
splitLabelWithTextToHighlight.length === 1 &&
splitLabelWithTextToHighlight[0] &&
splitLabelWithTextToHighlight[0].toLocaleLowerCase() === textToFilter.toLocaleLowerCase()
) {
filter = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2024 Obeo.
* Copyright (c) 2019, 2025 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -36,7 +36,7 @@ export const Tree = ({
treeItemActionRender,
}: TreeProps) => {
const { classes } = useTreeStyle();
const treeElement = useRef(null);
const treeElement = useRef<HTMLDivElement | null>(null);

useEffect(() => {
const downHandler = (event) => {
Expand All @@ -50,42 +50,44 @@ export const Tree = ({
event.preventDefault();

const previousItem = document.activeElement as HTMLElement;
const dataset = (previousItem as any).dataset;
const dataset = previousItem.dataset;
if (dataset.treeitemid) {
const treeItemDomElements = document.querySelectorAll<HTMLElement>('[data-treeitemid]');
const index = Array.from(treeItemDomElements).indexOf(previousItem);
const id = dataset.treeitemid;
const hasChildren = dataset.haschildren === 'true';
const isExpanded = dataset.expanded === 'true';
const depth: number = parseInt(dataset.depth ?? '0');

switch (event.key) {
case 'ArrowLeft':
if (hasChildren && isExpanded) {
onExpand(id, dataset.depth);
onExpand(id, depth);
} else if (index > 0) {
const parentDepth = (dataset.depth - 1).toString();
let positionFromParent = 0;
while (!(treeItemDomElements[index - positionFromParent].dataset.depth === parentDepth)) {
const parentDepth = (depth - 1).toString();

let positionFromParent: number = 0;
while (!(treeItemDomElements[index - positionFromParent]?.dataset.depth === parentDepth)) {
positionFromParent++;
}
treeItemDomElements[index - positionFromParent].click();
treeItemDomElements[index - positionFromParent]?.click();
}
break;
case 'ArrowRight':
if (hasChildren && !isExpanded) {
onExpand(id, dataset.depth);
onExpand(id, depth);
} else if (index < treeItemDomElements.length - 1) {
treeItemDomElements[index + 1].click();
treeItemDomElements[index + 1]?.click();
}
break;
case 'ArrowUp':
if (index > 0) {
treeItemDomElements[index - 1].click();
treeItemDomElements[index - 1]?.click();
}
break;
case 'ArrowDown':
if (index < treeItemDomElements.length - 1) {
treeItemDomElements[index + 1].click();
treeItemDomElements[index + 1]?.click();
}
break;
default:
Expand All @@ -94,15 +96,15 @@ export const Tree = ({
}
};

const element = treeElement?.current;
const element = treeElement.current;
if (element) {
element.addEventListener('keydown', downHandler);

return () => {
element.removeEventListener('keydown', downHandler);
};
}
return null;
return () => {};
}, [treeElement, onExpand]);

return (
Expand Down
Loading
Loading