Skip to content

Commit

Permalink
Use Paths settings toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
terotik committed Oct 14, 2024
1 parent a7a187b commit ed6b068
Show file tree
Hide file tree
Showing 11 changed files with 1,688 additions and 46 deletions.
4 changes: 2 additions & 2 deletions app/[domain]/[lang]/[plan]/(with-layout-elements)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode } from 'react';

import Footer from '@/components/Footer';
import Header from '@/components/Header';
import PathsToolbar from '@/components/paths/PathsToolbar';
import SettingsPanelFull from '@/components/paths/toolbar/SettingsPanelFull';

import { JsonLd } from './JsonLd';
import { StyledMain } from './StyledMain';
Expand All @@ -23,7 +23,7 @@ export default function Layout({ children, params }: Props) {
<Header />
<StyledMain id="main">{children}</StyledMain>
<Footer />
<PathsToolbar />
<SettingsPanelFull />
</>
);
}
130 changes: 130 additions & 0 deletions common/__generated__/paths/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions components/paths/NormalizationWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {
GetParametersQuery,
SetNormalizationMutation,
SetNormalizationMutationVariables,
} from 'common/__generated__/paths/graphql';
import { GET_PARAMETERS } from 'queries/getParameters';
import { useTranslation } from 'react-i18next';
import { FormGroup, Input, Label } from 'reactstrap';
import styled from 'styled-components';

import { gql, useMutation, useQuery } from '@apollo/client';

const SwitchWrapper = styled.div`
max-width: 160px;
.form-label {
margin-bottom: 0;
line-height: 1;
font-size: 0.8rem;
}
`;

const SET_NORMALIZATION_MUTATION = gql`
mutation SetNormalizationFromWidget($id: ID) {
setNormalizer(id: $id) {
ok
}
}
`;

type NormalizationWidgetProps = {
availableNormalizations: GetParametersQuery['availableNormalizations'];
};

function NormalizationWidget(props: NormalizationWidgetProps) {
const { t } = useTranslation();

const { loading, error, data, previousData, refetch, networkStatus } =
useQuery<GetParametersQuery>(GET_PARAMETERS, {
notifyOnNetworkStatusChange: true,
});

const [
setNormalization,
{ data: mutationData, loading: mutationLoading, error: mutationError },
] = useMutation<SetNormalizationMutation, SetNormalizationMutationVariables>(
SET_NORMALIZATION_MUTATION,
{
refetchQueries: 'active',
}
);

if ((loading && !previousData) || !data || !data.parameters) {
return <>-</>;
}
if (error) {
return (
<>
<div>{t('error-loading-data')}</div>
</>
);
}

const { availableNormalizations } = data;
if (!availableNormalizations.length) return null;

const norm = availableNormalizations[0];
const label = t('normalize-by', { node: norm.label });
return (
<SwitchWrapper>
<FormGroup switch>
<Label for={norm.id}>{label}</Label>
<Input
disabled={mutationLoading}
type="switch"
role="switch"
id={norm.id}
name={norm.id}
checked={norm.isActive}
onChange={(e) => {
setNormalization({
variables: {
id: norm.isActive ? null : norm.id,
},
});
}}
/>
</FormGroup>
</SwitchWrapper>
);
}

export default NormalizationWidget;
2 changes: 1 addition & 1 deletion components/paths/contentblocks/PathsOutcomeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function PathsOutcomeBlock(props) {
const router = useRouter();
const pathname = usePathname();
const queryNodeId = searchParams.get('node') ?? undefined;
console.log('PathsOutcomeBlock', props);
//console.log('PathsOutcomeBlock', props);
const [lastActiveNodeId, setLastActiveNodeId] = useState<string | undefined>(
queryNodeId
);
Expand Down
Loading

0 comments on commit ed6b068

Please sign in to comment.