Skip to content

Commit

Permalink
update components to use locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Buczacka authored and Walter Buczacka committed Jul 15, 2024
1 parent 0dac204 commit 890eeb6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/components/ParamsExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ type Props = {};
function ParamsExplorer(props: Props) {
const {} = props;
return (
<Box>
<Box mb="md">
<>
<Box mb="xl">
<SelectLocale />
</Box>
<SelectCube />
</Box>
</>
);
}

Expand Down
14 changes: 3 additions & 11 deletions src/components/SelectCubes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ function SelectCubeInternal(props: {items: PlainCube[]; selectedItem: PlainCube
);
}

// check accordion
function AccordionControl(props: AccordionControlProps) {
return (
<Box sx={{display: "flex", alignItems: "center"}}>
Expand Down Expand Up @@ -169,8 +168,8 @@ function getCube(items: AnnotatedCube[], table: string, subtopic: string, locale
return cube;
}

function useBuildGraph(items, locale) {
const [graph, setGraph] = useState<Graph>(new Graph());
function useBuildGraph(items, locale, graph, setGraph) {
// const [graph, setGraph] = useState<Graph>(new Graph());

useEffect(() => {
const graph = new Graph();
Expand Down Expand Up @@ -204,13 +203,8 @@ function CubeTree({
selectedItem?: PlainCube;
}) {
const {graph, setGraph, map} = useSideBar();
const {graph: graphInit} = useBuildGraph(items, locale);
useBuildGraph(items, locale, graph, setGraph);
const actions = useActions();

useEffect(() => {
graphInit && setGraph(graphInit);
}, [graphInit, setGraph, locale]);

const onSelectCube = (table: string, subtopic: string) => {
const cube = items.find(
item =>
Expand Down Expand Up @@ -262,7 +256,6 @@ function useAccordionValue(key: Keys, locale) {
}

function RootAccordions({items, graph, locale, selectedItem, onSelectCube}) {
console.log(items, "items");
const {value, setValue} = useAccordionValue("topic", locale);
return (
<Accordion
Expand Down Expand Up @@ -362,7 +355,6 @@ function SubtopicAccordion({
selectedItem,
locale
}: PropsWithChildren<NestedAccordionType>) {
console.log(items, "Sub");
const {value, setValue} = useAccordionValue("subtopic", locale);
return (
<Accordion
Expand Down
19 changes: 11 additions & 8 deletions src/components/SelectLocale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {useTranslation} from "../hooks/translation";
import {selectLocale} from "../state/queries";
import {selectServerState} from "../state/server";
import {SelectObject} from "./Select";
import {useSideBar} from "./SideBar";

type LocaleOptions = {label: string, value: LanguageCode};
type LocaleOptions = {label: string; value: LanguageCode};

/** */
export function SelectLocale() {
const actions = useActions();

const {resetGraph} = useSideBar();
const {translate: t, locale} = useTranslation();

const {code: currentCode} = useSelector(selectLocale);
Expand All @@ -22,17 +23,19 @@ export function SelectLocale() {
const options: LocaleOptions[] = useMemo(() => {
const languages = ISO6391.getLanguages(localeOptions);
return languages.map(lang => ({
label: t("params.label_localeoption", {
code: lang.code,
engName: lang.name,
nativeName: lang.nativeName,
customName: t(`params.label_localecustom_${lang.code}`)
}) || lang.nativeName,
label:
t("params.label_localeoption", {
code: lang.code,
engName: lang.name,
nativeName: lang.nativeName,
customName: t(`params.label_localecustom_${lang.code}`)
}) || lang.nativeName,
value: lang.code
}));
}, [locale, localeOptions]);

const localeChangeHandler = useCallback((locale: LocaleOptions) => {
resetGraph();
actions.updateLocale(locale.value);
}, []);

Expand Down
12 changes: 9 additions & 3 deletions src/components/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Graph from "../utils/graph";
import {useSelector} from "react-redux";
import {getKeys} from "./SelectCubes";
import {AnnotatedCube} from "./SelectCubes";
import {SelectLocale} from "./SelectLocale";

type SidebarProviderProps = {
expanded: boolean;
Expand All @@ -21,17 +20,23 @@ type SidebarProviderProps = {
setInput: React.Dispatch<React.SetStateAction<string>>;
map: Map<string, string[]> | undefined;
setMap: React.Dispatch<React.SetStateAction<Map<string, string[]> | undefined>>;
resetGraph: () => void;
};

export const [useSideBar, Provider] =
createContext<PropsWithChildren<SidebarProviderProps>>("SideBar");

export function SideBarProvider(props: PropsWithChildren<{}>) {
const {code: locale} = useSelector(selectLocale);
const [input, setInput] = useState<string>("");
const [expanded, setExpanded] = useState<boolean>(false);
const [results, setResults] = useState<string[]>([]);
const [map, setMap] = useState<Map<string, string[]>>();
const [graph, setGraph] = useState(new Graph());
const resetGraph = () => {
console.log("me llama");
setGraph(new Graph());
};

return (
<Provider
Expand All @@ -46,7 +51,8 @@ export function SideBarProvider(props: PropsWithChildren<{}>) {
input,
map,
setMap,
setInput
setInput,
resetGraph
}}
/>
);
Expand All @@ -61,7 +67,7 @@ function SideBar(props: PropsWithChildren<SidebarProps>) {
<Box
p="md"
sx={t => ({
height: "calc(100vh - 80px)",
height: "calc(100vh - 90px)",
border: "1px solid",
backgroundColor: t.colors.gray[2],
borderColor: t.colors.gray[1],
Expand Down
5 changes: 2 additions & 3 deletions src/components/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {selectCurrentQueryParams} from "../state/queries";
import {useSelector} from "react-redux";
import {PlainCube, PlainLevel, PlainMeasure, PlainProperty} from "@datawheel/olap-client";
import {ViewProps} from "../utils/types";
import {isNumeric} from "../utils/validation";
import OptionsMenu from "./OptionsMenu";
import {
IconSortAscendingLetters as SortAsc,
Expand Down Expand Up @@ -498,8 +497,8 @@ export function TableView({table}: TableView) {
component="th"
key={header.id}
sx={theme => ({
// backgroundColor: getEntityColor(column.columnDef.entityType, theme),
backgroundColor: "white",
backgroundColor: theme.colors.gray[0],
// backgroundColor: "white",
align: isNumeric ? "right" : "left",
height: 140,
paddingBottom: 15,
Expand Down

0 comments on commit 890eeb6

Please sign in to comment.