bc4ae35bc4
## Summary - **Enhanced the `matching-state-variable` ESLint rule** to enforce consistent naming for `ComponentState`, `FamilyState`, and `ComponentFamilyState` hooks — previously it only covered `useAtomState` and `useAtomStateValue` - **The rule now checks 12 hooks** across three categories: value hooks (`useAtomComponentStateValue`, `useAtomFamilyStateValue`, etc.), state hooks (`useAtomComponentState`, `useAtomComponentFamilyState`), and setter hooks (`useSetAtomState`, `useSetAtomComponentState`, `useSetAtomFamilyState`, `useSetAtomComponentFamilyState`) - **Fixed all 225 resulting lint violations** across 151 files, renaming variables to match their state atom names (e.g. `currentViewId` → `contextStoreCurrentViewId`, `selectedRecord` → `recordStore`). Cases where the same state is accessed with different family keys/instance IDs are suppressed with `eslint-disable-next-line`. ## Naming convention | Hook | State argument | Valid | Invalid | |------|---------------|-------|---------| | `useAtomStateValue` | `fooState` | `const foo = ...` | `const bar = ...` | | `useAtomComponentStateValue` | `fooComponentState` | `const foo = ...` | `const bar = ...` | | `useAtomFamilyStateValue` | `fooFamilyState` | `const foo = ...` | `const bar = ...` | | `useAtomComponentFamilyStateValue` | `fooComponentFamilyState` | `const foo = ...` | `const bar = ...` | | `useAtomState` | `fooState` | `const [foo, setFoo] = ...` | `const [bar, setBar] = ...` | | `useAtomComponentState` | `fooComponentState` | `const [foo, setFoo] = ...` | `const [bar, setBar] = ...` | | `useAtomComponentFamilyState` | `fooComponentFamilyState` | `const [foo, setFoo] = ...` | `const [bar, setBar] = ...` | | `useSetAtomState` | `fooState` | `const setFoo = ...` | `const setBar = ...` | | `useSetAtomComponentState` | `fooComponentState` | `const setFoo = ...` | `const setBar = ...` | | `useSetAtomFamilyState` | `fooFamilyState` | `const setFoo = ...` | `const setBar = ...` | | `useSetAtomComponentFamilyState` | `fooComponentFamilyState` | `const setFoo = ...` | `const setBar = ...` |
97 lines
3.2 KiB
TypeScript
97 lines
3.2 KiB
TypeScript
import { FrontComponentRendererProvider } from '@/front-components/components/FrontComponentRendererProvider';
|
|
import { useFrontComponentExecutionContext } from '@/front-components/hooks/useFrontComponentExecutionContext';
|
|
import { useOnFrontComponentUpdated } from '@/front-components/hooks/useOnFrontComponentUpdated';
|
|
import { frontComponentApplicationTokenPairComponentState } from '@/front-components/states/frontComponentApplicationTokenPairComponentState';
|
|
import { getFrontComponentUrl } from '@/front-components/utils/getFrontComponentUrl';
|
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
|
import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
|
|
import { useTheme } from '@emotion/react';
|
|
import { t } from '@lingui/core/macro';
|
|
import { useCallback } from 'react';
|
|
import { FrontComponentRenderer as SharedFrontComponentRenderer } from 'twenty-sdk/front-component-renderer';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
|
import { useFindOneFrontComponentQuery } from '~/generated-metadata/graphql';
|
|
|
|
type FrontComponentRendererProps = {
|
|
frontComponentId: string;
|
|
};
|
|
|
|
export const FrontComponentRenderer = ({
|
|
frontComponentId,
|
|
}: FrontComponentRendererProps) => {
|
|
const theme = useTheme();
|
|
const { enqueueErrorSnackBar } = useSnackBar();
|
|
|
|
const setFrontComponentApplicationTokenPair = useSetAtomComponentState(
|
|
frontComponentApplicationTokenPairComponentState,
|
|
frontComponentId,
|
|
);
|
|
|
|
const { executionContext, frontComponentHostCommunicationApi } =
|
|
useFrontComponentExecutionContext({ frontComponentId });
|
|
|
|
const handleError = useCallback(
|
|
(error?: Error) => {
|
|
if (!isDefined(error)) {
|
|
return;
|
|
}
|
|
|
|
const errorMessage = error.message;
|
|
|
|
enqueueErrorSnackBar({
|
|
message: t`Failed to load front component: ${errorMessage}`,
|
|
});
|
|
},
|
|
[enqueueErrorSnackBar],
|
|
);
|
|
|
|
const { data, loading } = useFindOneFrontComponentQuery({
|
|
variables: { id: frontComponentId },
|
|
onError: handleError,
|
|
onCompleted: (completedData) => {
|
|
const tokenPair = completedData.frontComponent?.applicationTokenPair;
|
|
|
|
if (isDefined(tokenPair)) {
|
|
setFrontComponentApplicationTokenPair(tokenPair);
|
|
}
|
|
},
|
|
});
|
|
|
|
useOnFrontComponentUpdated({
|
|
frontComponentId,
|
|
});
|
|
|
|
const componentUrl = getFrontComponentUrl({
|
|
frontComponentId,
|
|
checksum: data?.frontComponent?.builtComponentChecksum,
|
|
});
|
|
|
|
const applicationTokenPair =
|
|
data?.frontComponent?.applicationTokenPair ?? null;
|
|
|
|
if (
|
|
loading ||
|
|
!isDefined(data?.frontComponent) ||
|
|
!isDefined(applicationTokenPair)
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<FrontComponentRendererProvider frontComponentId={frontComponentId}>
|
|
<SharedFrontComponentRenderer
|
|
theme={theme}
|
|
componentUrl={componentUrl}
|
|
applicationAccessToken={
|
|
applicationTokenPair.applicationAccessToken.token
|
|
}
|
|
apiUrl={REACT_APP_SERVER_BASE_URL}
|
|
executionContext={executionContext}
|
|
frontComponentHostCommunicationApi={frontComponentHostCommunicationApi}
|
|
onError={handleError}
|
|
/>
|
|
</FrontComponentRendererProvider>
|
|
);
|
|
};
|