Merge pull request #19811 from strapi/fix/ctb-not-reloading

fix: reload ctb after save
This commit is contained in:
Bassel Kanso 2024-03-19 12:55:21 +02:00 committed by GitHub
commit 88d4b5dc38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 3 deletions

View File

@ -43,6 +43,7 @@ import {
REMOVE_FIELD_FROM_DISPLAYED_COMPONENT,
SET_MODIFIED_DATA,
UPDATE_SCHEMA,
UPDATE_INITIAL_STATE,
} from './constants';
import { makeSelectDataManagerProvider } from './selectors';
import { formatMainDataType, getComponentsToPost, sortContentType } from './utils/cleanData';
@ -555,7 +556,7 @@ const DataManagerProvider = ({ children }: DataManagerProviderProps) => {
await serverRestartWatcher(true);
// Unlock the app
await unlockAppWithAutoreload?.();
unlockAppWithAutoreload?.();
if (
isCreating &&
@ -579,6 +580,10 @@ const DataManagerProvider = ({ children }: DataManagerProviderProps) => {
trackUsage('didSaveComponent');
}
// refetch and update initial state after the data has been saved
await getDataRef.current();
dispatch({ type: UPDATE_INITIAL_STATE });
// Update the app's permissions
await updatePermissions();
} catch (err: any) {

View File

@ -21,3 +21,4 @@ export const REMOVE_COMPONENT_FROM_DYNAMIC_ZONE =
export const REMOVE_FIELD = 'ContentTypeBuilder/DataManagerProvider/REMOVE_FIELD';
export const SET_MODIFIED_DATA = 'ContentTypeBuilder/DataManagerProvider/SET_MODIFIED_DATA';
export const UPDATE_SCHEMA = 'ContentTypeBuilder/DataManagerProvider/UPDATE_SCHEMA';
export const UPDATE_INITIAL_STATE = 'ContentTypeBuilder/DataManagerProvider/UPDATE_INITIAL_STATE';

View File

@ -542,6 +542,10 @@ const reducer = (state = initialState, action: Action) =>
draftState.contentTypes = action.contentTypes;
draftState.reservedNames = action.reservedNames;
draftState.isLoading = false;
break;
}
case actions.UPDATE_INITIAL_STATE: {
draftState.initialData = draftState.modifiedData;
break;
}

View File

@ -41,7 +41,7 @@ export interface DataManagerContextValue {
removeComponentFromDynamicZone: (dzName: string, componentToRemoveIndex: number) => void;
setModifiedData: () => void;
sortedContentTypesList: any[]; // Define the actual type
submitData: (additionalContentTypeData?: Record<string, any>) => void;
submitData: (additionalContentTypeData?: Record<string, any>) => Promise<void>;
updateSchema: (data: Record<string, any>, schemaType: SchemaType, componentUID: UID.Any) => void;
components: Record<UID.Component, Component>;
componentsGroupedByCategory: Record<string, Component[]>;

View File

@ -142,7 +142,7 @@ const ListView = () => {
)}
<Button
startIcon={<Check />}
onClick={() => submitData()}
onClick={async () => await submitData()}
type="submit"
disabled={isEqual(modifiedData, initialData)}
>