26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
|
|
import { useMemo } from 'react';
|
||
|
|
import type { DeploymentPageFormState } from './useDeploymentPageState';
|
||
|
|
|
||
|
|
export interface PerTabDirty {
|
||
|
|
monitoring: boolean;
|
||
|
|
resources: boolean;
|
||
|
|
variables: boolean;
|
||
|
|
sensitiveKeys: boolean;
|
||
|
|
anyLocalEdit: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useFormDirty(
|
||
|
|
form: DeploymentPageFormState,
|
||
|
|
serverState: DeploymentPageFormState,
|
||
|
|
stagedJar: File | null,
|
||
|
|
): PerTabDirty {
|
||
|
|
return useMemo(() => {
|
||
|
|
const monitoring = JSON.stringify(form.monitoring) !== JSON.stringify(serverState.monitoring);
|
||
|
|
const resources = JSON.stringify(form.resources) !== JSON.stringify(serverState.resources);
|
||
|
|
const variables = JSON.stringify(form.variables) !== JSON.stringify(serverState.variables);
|
||
|
|
const sensitiveKeys = JSON.stringify(form.sensitiveKeys) !== JSON.stringify(serverState.sensitiveKeys);
|
||
|
|
const anyLocalEdit = monitoring || resources || variables || sensitiveKeys || !!stagedJar;
|
||
|
|
return { monitoring, resources, variables, sensitiveKeys, anyLocalEdit };
|
||
|
|
}, [form, serverState, stagedJar]);
|
||
|
|
}
|