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

visualise non string filter values (closes #387) #388

Merged
merged 1 commit into from
Jul 9, 2021
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
6 changes: 3 additions & 3 deletions frontend/cypress/integration/visualization/filter.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ context('Filter', () => {
cy.get('.FilterSelect').first().click();

// Assert
cy.contains('Error: No string').click();
cy.contains('[Trinity]').click();
});

it('applies filter', () => {
Expand All @@ -141,7 +141,7 @@ context('Filter', () => {
cy.get('.FilterSelect').first().click();

// Assert
cy.contains('Error: No string').click();
cy.contains('[Trinity]').click();

cy.get('body').click(0, 0);
cy.get('.ApplyFilter').click();
Expand All @@ -156,7 +156,7 @@ context('Filter', () => {
cy.get('.FilterSelect').first().click();

// Assert
cy.contains('Error: No string').click();
cy.contains('[Trinity]').click();

cy.get('body').click(0, 0);
cy.get('.ApplyFilter').click();
Expand Down
29 changes: 25 additions & 4 deletions frontend/src/visualization/filtering/FilterLineProperty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ const FilterLineProperty = (props: {
setSelectedValues(event.target.value as string[]);
};

/**
* Returns the property as string or returns an error string.
* Does return the 'real' value if the property is of type string, boolean,
* number or array.
* @param property value
*/
const asString = (property: unknown): string => {
if (Array.isArray(property)) {
return `[${property.map(asString).join(', ')}]`;
}

switch (typeof property) {
case 'string':
case 'boolean':
case 'number':
return `${property}`;
default:
return 'Error: No string';
}
};

return (
<div className="FilterSelect">
<FormControl className={classes.select}>
Expand All @@ -87,15 +108,15 @@ const FilterLineProperty = (props: {
>
{filterModelEntry.values.map((name) => (
<MenuItem
key={typeof name === 'string' ? name : 'Error: No string'}
value={typeof name === 'string' ? name : 'Error: No string'}
key={asString(name)}
value={asString(name)}
style={getStyles(
typeof name === 'string' ? name : 'Error: No string',
asString(name),
filterModelEntry.values as string[],
theme
)}
>
{typeof name === 'string' ? name : 'Error: No string'}
{asString(name)}
</MenuItem>
))}
</Select>
Expand Down