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

Settings: Metric Configuration: Playtesting Followups - Default Definition Hover State (3/n) #113

Merged
merged 4 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ export const DefinitionSelection = styled.div`

export const DefinitionMiniButton = styled(RevertToDefaultButton)<{
selected?: boolean;
showDefault?: boolean;
}>`
width: unset;
padding: 9px 16px;
Expand All @@ -574,6 +575,9 @@ export const DefinitionMiniButton = styled(RevertToDefaultButton)<{


`};

${({ showDefault, selected }) =>
showDefault && !selected && `color: ${palette.highlight.grey4};`};
`;

export const NoDefinitionsSelected = styled.div`
Expand Down
117 changes: 69 additions & 48 deletions publisher/src/components/MetricConfiguration/MetricDefinitions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =============================================================================

import React, { Fragment } from "react";
import React, { Fragment, useState } from "react";

import {
Metric,
Expand Down Expand Up @@ -62,6 +62,8 @@ export const MetricDefinitions: React.FC<MetricDefinitionsProps> = ({
contexts,
saveAndUpdateMetricSettings,
}) => {
const [showDefaultSettings, setShowDefaultSettings] = useState(false);

const selectionOptions: MetricConfigurationSettingsOptions[] = [
"N/A",
"No",
Expand Down Expand Up @@ -131,65 +133,84 @@ export const MetricDefinitions: React.FC<MetricDefinitionsProps> = ({
</span>
</DefinitionsDescription>

<RevertToDefaultButton onClick={revertToDefaultValues}>
Revert to Default Definition
<RevertToDefaultButton
onClick={() => {
setShowDefaultSettings(false);
revertToDefaultValues();
}}
onMouseEnter={() =>
!showDefaultSettings && setShowDefaultSettings(true)
}
onMouseLeave={() => setShowDefaultSettings(false)}
>
Choose Default Definition
</RevertToDefaultButton>

<Definitions>
{activeSettings?.map((setting) => (
<DefinitionItem key={setting.key}>
<DefinitionDisplayName>{setting.label}</DefinitionDisplayName>

<DefinitionSelection>
{selectionOptions.map((option) => (
<Fragment key={option}>
<DefinitionMiniButton
selected={setting.included === option}
onClick={() => {
if (isMetricSettings(activeDimensionOrMetric)) {
return saveAndUpdateMetricSettings(
"METRIC_SETTING",
{
key: activeMetricKey,
settings: [{ ...setting, included: option }],
}
);
}
{(showDefaultSettings ? defaultSettings : activeSettings)?.map(
Copy link
Contributor Author

@mxosman mxosman Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and L162) are the only things that changed within this block. It will render the defaultSettings list if the flag is true and the activeSettings if the flag is false.

(setting) => (
<DefinitionItem key={setting.key}>
<DefinitionDisplayName>
{setting.label}
</DefinitionDisplayName>

<DefinitionSelection>
{selectionOptions.map((option) => (
<Fragment key={option}>
<DefinitionMiniButton
selected={setting.included === option}
showDefault={showDefaultSettings}
onClick={() => {
if (isMetricSettings(activeDimensionOrMetric)) {
return saveAndUpdateMetricSettings(
"METRIC_SETTING",
{
key: activeMetricKey,
settings: [
{ ...setting, included: option },
],
}
);
}

const activeDimensionKey =
activeDimensionOrMetric.key;
const activeDimensionKey =
activeDimensionOrMetric.key;

return (
activeDisaggregation &&
saveAndUpdateMetricSettings("DIMENSION_SETTING", {
key: activeMetricKey,
disaggregations: [
return (
activeDisaggregation &&
saveAndUpdateMetricSettings(
"DIMENSION_SETTING",
{
key: activeDisaggregation.key,
dimensions: [
key: activeMetricKey,
disaggregations: [
{
key: activeDimensionKey,
settings: [
key: activeDisaggregation.key,
dimensions: [
{
...setting,
included: option,
key: activeDimensionKey,
settings: [
{
...setting,
included: option,
},
],
},
],
},
],
},
],
})
);
}}
>
{option}
</DefinitionMiniButton>
</Fragment>
))}
</DefinitionSelection>
</DefinitionItem>
))}
}
)
);
}}
>
{option}
</DefinitionMiniButton>
</Fragment>
))}
</DefinitionSelection>
</DefinitionItem>
)
)}
</Definitions>
</>
)}
Expand Down