<commit_before>import { sortBy } from "common/collections";
import { Box, Stack } from "../../../../../components";
import { Feature, FeatureChoicedServerData, FeatureValueProps, StandardizedDropdown } from "../base";

type HexValue = {
  lightness: number,
  value: string,
};

type SkinToneServerData = FeatureChoicedServerData & {
  display_names: NonNullable<FeatureChoicedServerData["display_names"]>,
  to_hex: Record<string, HexValue>,
};

const sortHexValues
  = sortBy<[string, HexValue]>(([_, hexValue]) => -hexValue.lightness);

export const skin_tone: Feature<string, string, SkinToneServerData> = {
  name: "Skin tone",
  component: (props: FeatureValueProps<string, string, SkinToneServerData>) => {
    const {
      handleSetValue,
      serverData,
      value,
    } = props;

    if (!serverData) {
      return null;
    }

    return (
      <StandardizedDropdown
        choices={sortHexValues(Object.entries(serverData.to_hex))
          .map(([key]) => key)}
        displayNames={Object.fromEntries(
          Object.entries(serverData.display_names)
            .map(([key, displayName]) => {
              const hexColor = serverData.to_hex[key];

              return [key, (
                <Stack align="center" fill key={key}>
                  <Stack.Item>
                    <Box style={{
                      background: `#${hexColor.value}`,
                      "box-sizing": "content-box",
                      "height": "11px",
                      "width": "11px",
                    }} />
                  </Stack.Item>

                  <Stack.Item grow>
                    {displayName}
                  </Stack.Item>
                </Stack>
              )];
            })
        )}
        onSetValue={handleSetValue}
        value={value}
      />
    );
  },
};<commit_msg>Fix skin tones on the preferences menu not having colors (#63370)<commit_after>import { sortBy } from "common/collections";
import { Box, Stack } from "../../../../../components";
import { Feature, FeatureChoicedServerData, FeatureValueProps, StandardizedDropdown } from "../base";

type HexValue = {
  lightness: number,
  value: string,
};

type SkinToneServerData = FeatureChoicedServerData & {
  display_names: NonNullable<FeatureChoicedServerData["display_names"]>,
  to_hex: Record<string, HexValue>,
};

const sortHexValues
  = sortBy<[string, HexValue]>(([_, hexValue]) => -hexValue.lightness);

export const skin_tone: Feature<string, string, SkinToneServerData> = {
  name: "Skin tone",
  component: (props: FeatureValueProps<string, string, SkinToneServerData>) => {
    const {
      handleSetValue,
      serverData,
      value,
    } = props;

    if (!serverData) {
      return null;
    }

    return (
      <StandardizedDropdown
        choices={sortHexValues(Object.entries(serverData.to_hex))
          .map(([key]) => key)}
        displayNames={Object.fromEntries(
          Object.entries(serverData.display_names)
            .map(([key, displayName]) => {
              const hexColor = serverData.to_hex[key];

              return [key, (
                <Stack align="center" fill key={key}>
                  <Stack.Item>
                    <Box style={{
                      background: hexColor.value,
                      "box-sizing": "content-box",
                      "height": "11px",
                      "width": "11px",
                    }} />
                  </Stack.Item>

                  <Stack.Item grow>
                    {displayName}
                  </Stack.Item>
                </Stack>
              )];
            })
        )}
        onSetValue={handleSetValue}
        value={value}
      />
    );
  },
};
{'fraction_non_alphanumeric': 0.13450134770889488, 'fraction_numerical': 0.003504043126684636, 'mean_word_length': 1.8879377431906614, 'pattern_counts': {'":': 6, '<': 29, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6005329', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1012, 'n_words': 202}