import { ChoiceGroup, Dropdown, IChoiceGroupOption, IDropdownOption, IDropdownStyles, Stack } from "@fluentui/react"; import React, { FunctionComponent, useEffect, useState } from "react"; import { IGraphConfigUiData, NeighborType } from "../../../Contracts/ViewModels"; import { IGraphConfig } from "../../Tabs/GraphTab"; const IGraphConfigType = { NODE_CAPTION: "NODE_CAPTION", NODE_COLOR: "NODE_COLOR", NODE_ICON: "NODE_ICON", SHOW_NEIGHBOR_TYPE: "SHOW_NEIGHBOR_TYPE", }; export interface GraphStyleProps { igraphConfig: IGraphConfig; igraphConfigUiData: IGraphConfigUiData; getValues: (igraphConfig?: IGraphConfig) => void; } export const GraphStyleComponent: FunctionComponent = ({ igraphConfig, igraphConfigUiData, getValues, }: GraphStyleProps): JSX.Element => { const [igraphConfigState, setIGraphConfig] = useState(igraphConfig); const [selected, setSelected] = useState(false); const nodePropertiesOptions = igraphConfigUiData.nodeProperties.map((nodeProperty) => ({ key: nodeProperty, text: nodeProperty, })); const nodePropertiesWithNoneOptions = igraphConfigUiData.nodePropertiesWithNone.map((nodePropertyWithNone) => ({ key: nodePropertyWithNone, text: nodePropertyWithNone, })); const showNeighborTypeOptions: IChoiceGroupOption[] = [ { key: NeighborType.BOTH.toString(), text: "All neighbors" }, { key: NeighborType.SOURCES_ONLY.toString(), text: "Sources" }, { key: NeighborType.TARGETS_ONLY.toString(), text: "Targets" }, ]; const dropdownStyles: Partial = { dropdown: { height: 32, marginRight: 10 }, }; const choiceButtonStyles = { flexContainer: [ { selectors: { ".ms-ChoiceField-wrapper label": { fontSize: 14, paddingTop: 0, }, }, }, ], }; useEffect(() => { if (selected) { getValues(igraphConfigState); } //eslint-disable-next-line }, [igraphConfigState]); const handleOnChange = (val: string, igraphConfigType: string) => { switch (igraphConfigType) { case IGraphConfigType.NODE_CAPTION: setSelected(true); setIGraphConfig({ ...igraphConfigState, nodeCaption: val, }); break; case IGraphConfigType.NODE_COLOR: setSelected(true); setIGraphConfig({ ...igraphConfigState, nodeColorKey: val, }); break; case IGraphConfigType.SHOW_NEIGHBOR_TYPE: setSelected(true); setIGraphConfig({ ...igraphConfigState, showNeighborType: parseInt(val), }); break; } }; return (
handleOnChange(options.key.toString(), IGraphConfigType.NODE_CAPTION) } />
handleOnChange(options.key.toString(), IGraphConfigType.NODE_COLOR) } />
handleOnChange(options.key.toString(), IGraphConfigType.SHOW_NEIGHBOR_TYPE) } />
); };