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

Fix Table Cells rule based styling by applying the first valid rule f… #1036

Merged
merged 2 commits into from
Feb 18, 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
22 changes: 14 additions & 8 deletions src/chart/table/TableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export const NeoTableChart = (props: ChartProps) => {
ColumnSortedDescendingIcon: () => <></>,
ColumnSortedAscendingIcon: () => <></>,
},
// TODO: if mixing and matching row and cell styling, row rules MUST be set first or will not populate correctly
getRowClassName: (params) => {
return ['row color', 'row text color']
.map((e) => {
Expand All @@ -256,21 +255,28 @@ export const NeoTableChart = (props: ChartProps) => {
getCellClassName: (params) => {
return ['cell color', 'cell text color']
.map((e) => {
let trueRulesList = [''];
let trueRule;
let validRuleClass = '';
for (const [index, rule] of styleRules.entries()) {
let ruleClass = '';
// If the rule target is not the current cell
if (rule.targetField) {
if (rule.targetField === params.field) {
trueRule = `rule${evaluateSingleRuleOnDict({ [rule.field]: params.row[rule.field] }, rule, index, [
ruleClass = `rule${evaluateSingleRuleOnDict({ [rule.field]: params.row[rule.field] }, rule, index, [
e,
])}`;
}
} else {
trueRule = `rule${evaluateSingleRuleOnDict({ [params.field]: params.value }, rule, index, [e])}`;
}
trueRulesList.push(trueRule);
// If the rule target is the current cell
else {
ruleClass = `rule${evaluateSingleRuleOnDict({ [params.field]: params.value }, rule, index, [e])}`;
}
// If rule class is valid (rule-1 means rule check has failed)
if (ruleClass && ruleClass !== 'rule-1') {
validRuleClass = ruleClass;
break;
}
}
return trueRulesList.join(' ');
return validRuleClass;
})
.join(' ');
},
Expand Down
5 changes: 4 additions & 1 deletion src/extensions/styling/StyleRuleEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export const evaluateRulesOnDict = (dict, rules, customizations) => {
}
for (const [index, rule] of rules.entries()) {
// Only check customizations that are specified
return evaluateSingleRuleOnDict(dict, rule, index, customizations);
const evaluationResult = evaluateSingleRuleOnDict(dict, rule, index, customizations);
if (evaluationResult !== -1) {
return evaluationResult;
}
}
// If no rules are met, return not found (index=-1)
return -1;
Expand Down
Loading