Skip to content

Commit

Permalink
feat(metadata-sidebar): PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
karolinaru committed Aug 21, 2024
1 parent 0ce21f3 commit b08bc35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/elements/content-sidebar/hooks/useSidebarMetadataFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { type BoxItem } from '../../../common/types/core';
import { MetadataTemplate, type MetadataEditor } from '../../../common/types/metadata';
import { type ExternalProps } from '../MetadataSidebarRedesign';

enum Status {
enum STATUS {
IDLE = 'idle',
LOADING = 'loading',
ERROR = 'error',
Expand All @@ -27,7 +27,7 @@ interface DataFetcher {
editors: Array<MetadataEditor>;
errorMessage: MessageDescriptor | null;
file: BoxItem | null;
status: Status;
status: STATUS;
templates: Array<MetadataTemplate>;
}

Expand All @@ -37,7 +37,7 @@ function useSidebarMetadataFetcher(
onError: ErrorContextProps['onError'],
isFeatureEnabled: ExternalProps['isFeatureEnabled'],
): DataFetcher {
const [status, setStatus] = React.useState<Status>(Status.IDLE);
const [status, setStatus] = React.useState<STATUS>(STATUS.IDLE);
const [file, setFile] = React.useState<BoxItem>(null);
const [templates, setTemplates] = React.useState(null);
const [errorMessage, setErrorMessage] = React.useState<MessageDescriptor | null>(null);
Expand All @@ -47,7 +47,7 @@ function useSidebarMetadataFetcher(
(error: ElementsXhrError, code: string, message: MessageDescriptor) => {
const { status: errorStatus } = error;
const isValidError = isUserCorrectableError(errorStatus);
setStatus(Status.ERROR);
setStatus(STATUS.ERROR);
setErrorMessage(message);
onError(error, code, {
error,
Expand All @@ -67,7 +67,7 @@ function useSidebarMetadataFetcher(
}) => {
setEditors(fetchedEditors);
setErrorMessage(null);
setStatus(Status.SUCCESS);
setStatus(STATUS.SUCCESS);
setTemplates(fetchedTemplates);
},
[],
Expand Down Expand Up @@ -105,7 +105,7 @@ function useSidebarMetadataFetcher(
if (shouldFetchMetadata && fetchedFile) {
fetchMetadata(fetchedFile);
} else {
setStatus(Status.SUCCESS);
setStatus(STATUS.SUCCESS);
}
},
[fetchMetadata, file],
Expand All @@ -120,8 +120,8 @@ function useSidebarMetadataFetcher(
);

React.useEffect(() => {
if (status === Status.IDLE) {
setStatus(Status.LOADING);
if (status === STATUS.IDLE) {
setStatus(STATUS.LOADING);
api.getFileAPI().getFile(fileId, fetchFileSuccessCallback, fetchFileErrorCallback, {
fields: [FIELD_IS_EXTERNALLY_OWNED, FIELD_PERMISSIONS],
refreshCache: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import MetadataSidebarRedesign from '../MetadataSidebarRedesign';
import ContentSidebar from '../ContentSidebar';

const fileIdWithNoMetadata = '416047501580';
const token = global.TOKEN;
const mockFeatures = {
'metadata.redesign.enabled': true,
};

const mockLogger = {
onReadyMetric: ({ endMarkName }) => {
console.log(`Logger: onReadyMetric called with endMarkName: ${endMarkName}`);
Expand All @@ -30,7 +28,7 @@ export default {
features: mockFeatures,
logger: mockLogger,
hasMetadata: true,
token,
token: global.TOKEN,
metadataSidebarProps: defaultMetadataSidebarProps,
},
render: args => {
Expand Down

0 comments on commit b08bc35

Please sign in to comment.