Skip to content

Commit

Permalink
Fixes typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Jan 21, 2025
1 parent 9f202d7 commit 2ae5364
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@ckeditor/ckeditor5-react": "^3.0.0",
"@helsenorge/ckeditor5-build-markdown": "^24.0.0",
"@nosferatu500/react-sortable-tree": "^4.4.0",
"@types/remove-markdown": "^0.3.4",
"axios": "^1.6.0",
"crypto-js": "^4.2.0",
"date-fns": "^2.17.0",
Expand Down
20 changes: 13 additions & 7 deletions src/components/AnchorMenu/AnchorMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ interface Node {

interface ExtendedNode {
node: Node;
path: string[];
path: string[] | number[];
}

// Event type definitions for moving nodes and toggling node visibility in the tree
interface NodeMoveEvent {
treeData: Node[];
nextParentNode: Node;
node: Node;
nextPath: string[];
prevPath: string[];
nextPath: number[];
prevPath: number[];
}

interface NodeVisibilityToggleEvent {
Expand Down Expand Up @@ -105,6 +105,11 @@ const YourExternalNodeComponent = ({ node }: { node: Node }): JSX.Element | null
);
};

// Add a helper function to handle both types of paths
const convertPath = (path: string[] | number[]): string[] => {
return path.map(String);
};

// The main component "AnchorMenu"
const AnchorMenu = (props: AnchorMenuProps): JSX.Element => {
const { t } = useTranslation();
Expand Down Expand Up @@ -132,10 +137,11 @@ const AnchorMenu = (props: AnchorMenuProps): JSX.Element => {
return extendedNode.node.title;
};

const treePathToOrderArray = (treePath: string[]): string[] => {
// Update treePathToOrderArray to use the helper
const treePathToOrderArray = (treePath: number[]): string[] => {
const newPath = [...treePath];
newPath.splice(-1);
return newPath;
return convertPath(newPath);
};

const hasValidationError = (linkId: string): boolean => {
Expand Down Expand Up @@ -242,7 +248,7 @@ const AnchorMenu = (props: AnchorMenuProps): JSX.Element => {
props.dispatch(
updateMarkedLinkIdAction(
extendedNode.node.title,
treePathToOrderArray(extendedNode.path),
convertPath(extendedNode.path),
),
);
}}
Expand All @@ -258,7 +264,7 @@ const AnchorMenu = (props: AnchorMenuProps): JSX.Element => {
buttons: generateItemButtons(
t,
props.qItems[extendedNode.node.title],
treePathToOrderArray(extendedNode.path),
convertPath(extendedNode.path),
false,
props.dispatch,
),
Expand Down
2 changes: 1 addition & 1 deletion src/components/Languages/Translation/TranslationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ const TranslationModal = (props: TranslationModalProps): JSX.Element => {
)}
<div>
<div className="translation-section-header">{t('Elements')}</div>
{renderItems(flattOrder.filter((val, i) => i <= count))}
{renderItems(flattOrder.filter((_, i) => i <= count))}
</div>
<div
id="bottom-translation-modal"
Expand Down
4 changes: 2 additions & 2 deletions src/components/MarkdownEditor/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ interface MarkdownEditorProps {

const MarkdownEditor = (props: MarkdownEditorProps): JSX.Element => {
const [value, setValue] = useState<string>(props.data);
const handleChange = (event: Event, editor: Editor) => {
const handleChange = (_unused: unknown, editor: Editor) => {
setValue(editor.getData());
};
const handleBlur = (event: Event, editor: Editor) => {
const handleBlur = (_unused: unknown, editor: Editor) => {
if (props.onBlur) {
props.onBlur(editor.getData());
}
Expand Down
12 changes: 0 additions & 12 deletions src/components/Metadata/MetadataEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { TreeContext } from '../../store/treeStore/treeStore';
import { updateQuestionnaireMetadataAction } from '../../store/treeStore/treeActions';
import RadioBtn from '../RadioBtn/RadioBtn';
import InputField from '../InputField/inputField';
import { UseContextSystem } from '../../types/IQuestionnareItemType';

const MetadataEditor = (): JSX.Element => {
const { t } = useTranslation();
Expand All @@ -31,17 +30,6 @@ const MetadataEditor = (): JSX.Element => {
dispatch(updateQuestionnaireMetadataAction(propName, value));
};

const getUseContextSystem = (): string => {
const system =
qMetadata.useContext &&
qMetadata.useContext.length > 0 &&
qMetadata.useContext[0].valueCodeableConcept?.coding &&
qMetadata.useContext[0].valueCodeableConcept.coding.length > 0 &&
qMetadata.useContext[0].valueCodeableConcept.coding[0].system;

return system || UseContextSystem.helsetjeneste_full;
};

return (
<div id="metadata-editor">
<FormField label={t('Identifier')}>
Expand Down
7 changes: 3 additions & 4 deletions src/components/Question/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const Question = (props: QuestionProps): JSX.Element => {
{instructionType()}
</div>
<div className="horizontal">
{/* <FormField>
<FormField>
Markdown not currently supported
<SwitchBtn
label={t('Text formatting')}
Expand All @@ -183,7 +183,7 @@ const Question = (props: QuestionProps): JSX.Element => {
}
}}
/>
</FormField> */}
</FormField>
{canTypeBeRequired(props.item) && (
<FormField>
<SwitchBtn
Expand Down Expand Up @@ -293,7 +293,6 @@ const Question = (props: QuestionProps): JSX.Element => {
</FormField>
}
{isSlider && <SliderSettings item={props.item} /> }
{/* Sublabel is not currently supported
{canTypeHaveSublabel(props.item) && (
<FormField label={t('Sublabel')} isOptional>
<MarkdownEditor
Expand All @@ -311,7 +310,7 @@ const Question = (props: QuestionProps): JSX.Element => {
}}
/>
</FormField>
)} */}
)}
{respondType()}
</div>
<div className="question-addons">
Expand Down
2 changes: 1 addition & 1 deletion src/components/Question/QuestionType/Choice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import SwitchBtn from '../../SwitchBtn/SwitchBtn';
import { createUriUUID } from '../../../helpers/uriHelper';
import DraggableAnswerOptions from '../../AnswerOption/DraggableAnswerOptions';
import PredefinedValueSets from './PredefinedValueSets';
import { ItemControlType, isItemControlCheckbox, isItemControlDropDown } from '../../../helpers/itemControl';
import { ItemControlType, isItemControlCheckbox } from '../../../helpers/itemControl';
import { checkboxExtension } from '../../../helpers/QuestionHelper';

type Props = {
Expand Down
2 changes: 1 addition & 1 deletion src/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
process.env.PUBLIC_URL,
process.env.PUBLIC_URL || '', // Provide empty string as fallback
window.location.href
);
if (publicUrl.origin !== window.location.origin) {
Expand Down

0 comments on commit 2ae5364

Please sign in to comment.