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

axis date function #1101

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 10 additions & 7 deletions src/containers/datasets/alerts/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ const getData = (data) =>
title: month.label,
name: `${monthsConversion[month.label]} '${new Date(year + 1, 0, 0).toLocaleDateString(
'en',
{ year: '2-digit' }
{
year: '2-digit',
}
)}`,
alerts: d.count,
label: `${month.label}, ${year}`,
Expand Down Expand Up @@ -121,7 +123,7 @@ const TickSmall = ({ x, y, payload }) => {
);
};

const getTotal = (data) =>
const getTotal = (data: { count: number }[]) =>
data?.reduce((previous: number, current: { count: number }) => current.count + previous, 0);

export function useAlerts<T>(
Expand Down Expand Up @@ -201,12 +203,12 @@ export function useAlerts<T>(
);

const chartData = getData(dataFiltered);

const startIndex = fullData.findIndex((d) => d.startDate?.value === selectedStartDate?.value);
const endIndex = fullData.findIndex((d) => d.endDate?.value === selectedEndDate?.value);

return useMemo(() => {
const alertsTotal = getTotal(dataFiltered);
const dataLimitOverflow = dataFiltered.length > 16;

const config = {
data: chartData,
Expand All @@ -219,7 +221,7 @@ export function useAlerts<T>(
},
margin: { top: 50, right: 10, left: 10, bottom: 35 },
label: 'alerts',
xKey: 'name',
xKey: dataLimitOverflow ? 'year' : 'name',
chartBase: {
lines: {
alerts: {
Expand All @@ -231,7 +233,8 @@ export function useAlerts<T>(
},
xAxis: {
tick: TickSmall,
interval: 0,
...(dataLimitOverflow && { ticks: Array.from(new Set(chartData.map((d) => d.year))) }),
interval: dataLimitOverflow ? 'preserveStartEnd' : 0,
type: 'category',
},
yAxis: {
Expand Down Expand Up @@ -347,7 +350,7 @@ export function useAlerts<T>(
},
},

xKey: 'name',
xKey: 'year',
chartBase: {
lines: {
alerts: {
Expand All @@ -359,7 +362,7 @@ export function useAlerts<T>(
},
xAxis: {
tick: TickSmall,
interval: 0,
interval: 'preserveStartEnd',
type: 'category',
},

Expand Down
3 changes: 2 additions & 1 deletion src/containers/datasets/customize-widgets-deck/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ARROW_SVG from 'svgs/ui/arrow-filled.svg?sprite';

const CustomizeWidgetsDeck = () => {
const displayedWidgets = useRecoilValue(activeWidgetsAtom);

const [animateState, setAnimateState] = useState('start');

useEffect(() => {
Expand Down Expand Up @@ -49,7 +50,7 @@ const CustomizeWidgetsDeck = () => {
<Dialog>
<DialogTrigger asChild>
<span className={`${WIDGET_SELECT_STYLES} print:border-hidden`}>
{displayedWidgets.length} of {widgets.length}
{displayedWidgets.length} of {widgets.length - 1}
<Icon
icon={ARROW_SVG}
className={`${WIDGET_SELECT_ARROW_STYLES} print:hidden`}
Expand Down
12 changes: 7 additions & 5 deletions src/containers/datasets/drawing-upload-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ const WidgetDrawingUploadTool = () => {
'cursor-default opacity-30': !!customGeojson || isDrawingToolEnabled,
})}
>
<input
data-testid="shapefile-upload"
{...getInputProps()}
disabled={isDrawingToolEnabled || !!customGeojson}
/>
{!uploadedGeojson && (
<input
data-testid="shapefile-upload"
{...getInputProps()}
disabled={isDrawingToolEnabled || !!customGeojson || !!uploadedGeojson}
/>
)}
<div className="flex flex-col items-center space-y-1">
{uploadedGeojson || isDrawingUploadToolEnabled ? (
<DeleteDrawingButton size="sm" />
Expand Down
2 changes: 0 additions & 2 deletions src/containers/map/delete-drawing-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ export const DeleteDrawingButton = ({ size = 'md' }: { size?: 'sm' | 'md' }) =>
if (locationTool === 'worldwide') {
handleWorldwideView();
}

resetDrawingState();
resetAnalysisState();

// eslint-disable-next-line @typescript-eslint/no-floating-promises
replace(`/?${queryParams}`, null);
}, [
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/analysis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const fetchUploadFile = (data: FormData) =>
export const useUploadFile = (
file: File,
onUploadFile?: (geojson: UploadFileResponse) => void,
enabled?: boolean,
queryOptions?: QueryObserverOptions<UploadFileResponse>
) => {
const [, setUploadErrorModal] = useRecoilState(uploadFileAtom);
Expand All @@ -32,7 +33,7 @@ export const useUploadFile = (

return useQuery(['converter'], () => fetchUploadFile(data), {
...queryOptions,
enabled: !!file,
enabled: !!file && enabled,
onSuccess: (geojson) => {
onUploadFile?.(geojson);
},
Expand Down
Loading