Skip to content

Commit

Permalink
Use new types for matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexd-bes committed Jan 24, 2024
1 parent 320a3c4 commit c366962
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Dispatch, ReactNode, createContext } from 'react';
import { MatrixConfig, PresentationOptions } from '@tupaia/types';
import { MatrixConfig } from '@tupaia/types';
import { MatrixColumnType, MatrixRowType } from '../../types';

type RowTitle = MatrixRowType['title'];
Expand Down
14 changes: 8 additions & 6 deletions packages/ui-components/src/components/Matrix/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import { find, isString, isNumber } from 'lodash';
import {
PresentationOptions,
MatrixPresentationOptions,
ConditionValue,
RangePresentationOptions,
ConditionalPresentationOptions,
Expand All @@ -29,7 +29,7 @@ export const getFullHex = (hex: string) => {
};

export const findByKey = (
collection: PresentationOptions['conditions'],
collection: MatrixPresentationOptions['conditions'],
key: string,
caseSensitive = true,
) =>
Expand Down Expand Up @@ -57,8 +57,10 @@ const CONDITION_CHECK_METHOD = {
};

// This function is used to get the presentation option from the conditions, where the key is the value
const getPresentationOptionFromKey = (options: PresentationOptions['conditions'], value: any) =>
findByKey(options, value, false) || null;
const getPresentationOptionFromKey = (
options: MatrixPresentationOptions['conditions'],
value: any,
) => findByKey(options, value, false) || null;

// This function is used to get the presentation option from the conditions, when conditions is an array
const getPresentationOptionFromCondition = (
Expand Down Expand Up @@ -110,7 +112,7 @@ export const getPresentationOptionFromRange = (options: RangePresentationOptions
};

// This function returns the applicable presentation option from the presentation options, for the value
export const getPresentationOption = (options: PresentationOptions, value: any) => {
export const getPresentationOption = (options: MatrixPresentationOptions, value: any) => {
switch (options.type) {
case PRESENTATION_TYPES.RANGE:
return getPresentationOptionFromRange(options as RangePresentationOptions, value);
Expand All @@ -121,7 +123,7 @@ export const getPresentationOption = (options: PresentationOptions, value: any)
}
};

export function getIsUsingDots(presentationOptions: PresentationOptions = {}) {
export function getIsUsingDots(presentationOptions: MatrixPresentationOptions = {}) {
return (
Object.keys(presentationOptions).filter(optionName => !optionName.includes('export')).length > 0
);
Expand Down

0 comments on commit c366962

Please sign in to comment.