Skip to content

feat(content-sidebar): add archived date to content preview sidebar - #3625

Merged
mergify[bot] merged 22 commits into
box:masterfrom
michalkowalczyk-box:add-archived-date-for-content-sidebar
Sep 26, 2024
Merged

mergify[bot] merged 22 commits into
box:masterfrom
michalkowalczyk-box:add-archived-date-for-content-sidebar

Conversation

@michalkowalczyk-box

@michalkowalczyk-box michalkowalczyk-box commented Aug 29, 2024 •

Copy link
Copy Markdown
Contributor

Adding archive date to details sidebar. When feature is enabled it's fetched along rest of the file information from global metadata template archivedItemTemplate

image

@michalkowalczyk-box
michalkowalczyk-box requested review from a team as code owners August 29, 2024 18:24
@michalkowalczyk-box michalkowalczyk-box changed the title Add archived date for content sidebar feat(content-sidebar): add archived date to content preview sidebar Aug 29, 2024

const { accessStats, accessStatsError, file, fileError, isLoadingAccessStats }: State = this.state;

const shouldShowArchivedAt = isFeatureEnabled(features, 'details.archivedAt.enabled');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be moved all the way to down the bottom where the archivedAt is actually used, if you put a tenary at this level to decide if it should have the archivedAt or not because you wont know if the archivedAt is actually present but the split is off or its undefined when its retrieved from the server or if the split is on and the archivedAt is undefined

@michalkowalczyk-box michalkowalczyk-box Sep 2, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems better. Just to make sure - you mean move features all the way down to ItemProperties.js or should I just move the shouldShowArchivedAt as a prop?

@michalkowalczyk-box
michalkowalczyk-box force-pushed the add-archived-date-for-content-sidebar branch from e172d3b to 8079044 Compare September 4, 2024 14:11
Comment on lines +117 to +132
archivedAt: null,
features: {
details: {
archivedAt: {
enabled: false,
},
},
},
});

expect(wrapper).toMatchSnapshot();
});

test('should not render archived date when feature is not set', () => {
const wrapper = getWrapper({
archivedAt: null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should actually supply a archivedAt here so we are certain that the tests are passing because the feature is off or undefined. from reading the test itself, we dont know if its not rendering because archivedAt is null or feature is null/undefined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


ItemProperties.propTypes = {
/** the datetime this item was archived, accepts any value that can be passed to the Date() constructor */
archivedAt: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it actually be a number?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to string

@michalkowalczyk-box michalkowalczyk-box Sep 20, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed again since we're probably are going to be using unix epoch timestamps

greg-in-a-box
greg-in-a-box previously approved these changes Sep 5, 2024

@greg-in-a-box greg-in-a-box left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

{hasVersions && <SidebarVersions file={file} onVersionHistoryClick={onVersionHistoryClick} />}
<SidebarFileProperties
archivedAt={archivedAt}
file={file}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems more appropriate for archived_at to be a field on the File model.


export default ItemProperties;
export { ItemProperties as ItemPropertiesComponent };
export default withFeatureConsumer(ItemProperties);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a hook? If so, let's use it; if not, let's create one.

url,
}) => {
const descriptionId = uniqueid('description_');
const shouldShowArchivedAt = isFeatureEnabled(features, 'details.archivedAt.enabled');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the endpoint to not return the value if the feature isn't enabled yet, instead?

Comment on lines +42 to +43
<ItemProperties
archivedAt={Number(getProp(file, FIELD_METADATA_ARCHIVE)?.archiveDate) * 1000}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we plan to store unix epoch timestamps as strings in our template, but we're discussing changing their type to number.

Just in case we don't change it - is this conversion okay if we decide to store them as strings?

@michalkowalczyk-box michalkowalczyk-box Sep 20, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I will need to make sure whether they will be stored in seconds or milliseconds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our linter may complain about using a static built-in method like this. If so, use parseInt(value, 10) instead.

That said, we should handle formatting/display within ItemProperties rather than here, as well as handling non-number values better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good with linter, I will wait with fixes for after we finalize type and format in which we store archiveDate in our metadata template.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But also - do we need something better than js Date() for handling this?

If so, I can try implementing something here, if you tell me which cases you need handled.

But if not, shouldn't passing correct date format be responsibility of parent component using ItemProperties?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly refactored conversion here, now it passes undefined to prop when we don't have it metadata. My team finalized discussions and we'll have unix epoch timestamp in seconds stored as a string, so this should be correct conversion

Comment thread src/utils/fields.js Outdated
Comment on lines +87 to +88
const SIDEBAR_FIELDS_TO_FETCH = [
const SIDEBAR_FIELDS_TO_FETCH: Array<string> = [

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add type because flow was showing error
image

I could also add same type to other field arrays in this file to be consistent or move concat to functions in which we fetch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I'm not seeing this error locally. Flow is pretty terrible, but it should be able to infer one string array from another. Are you using the local Flow binary installed with the project? If so, maybe try removing the type annotations to see if it was a temporary issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed type annotation from SIDEBAR_FIELDS_TO_FETCH, but left one on SIDEBAR_FIELDS_TO_FETCH_ARCHIVE, without this one the flow error was still showing

@jstoffan jstoffan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach LGTM. Left some feedback on a few other touch-ups that are needed.

import type { BoxItem } from '../../common/types/core';
import type { FeatureConfig } from '../common/feature-checking';
import './DetailsSidebar.scss';
import { isFeatureEnabled, withFeatureConsumer } from '../common/feature-checking';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this line above the SCSS and type imports.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread src/elements/content-sidebar/DetailsSidebar.js
className="loading-indicator-wrapper "
>
<ItemProperties
archivedAt={NaN}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should handle cases where the value isn't a number by hiding the line item.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed after conversion change

jest.mock('../SidebarClassification', () => 'SidebarClassification');
jest.mock('../SidebarContentInsights', () => 'SidebarContentInsights');
jest.mock('../../common/feature-checking', () => ({
...jest.requireActual('../../common/feature-checking'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the rest of the module or can we just mock the whole thing?

jest.mock('../../common/feature-checking');

@michalkowalczyk-box michalkowalczyk-box Sep 20, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not needed, fixed here and in ContentSidebar.test.js

Comment thread src/elements/content-sidebar/__tests__/ContentSidebar.test.js
Comment on lines +42 to +43
<ItemProperties
archivedAt={Number(getProp(file, FIELD_METADATA_ARCHIVE)?.archiveDate) * 1000}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our linter may complain about using a static built-in method like this. If so, use parseInt(value, 10) instead.

That said, we should handle formatting/display within ItemProperties rather than here, as well as handling non-number values better.

jstoffan
jstoffan previously approved these changes Sep 20, 2024

@jstoffan jstoffan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working to refine the solution!

Comment thread src/utils/fields.js Outdated
Comment on lines +87 to +88
const SIDEBAR_FIELDS_TO_FETCH = [
const SIDEBAR_FIELDS_TO_FETCH: Array<string> = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I'm not seeing this error locally. Flow is pretty terrible, but it should be able to infer one string array from another. Are you using the local Flow binary installed with the project? If so, maybe try removing the type annotations to see if it was a temporary issue?

@michalkowalczyk-box
michalkowalczyk-box force-pushed the add-archived-date-for-content-sidebar branch from 9505cdb to 0aac903 Compare September 23, 2024 11:02
exports[`elements/content-sidebar/SidebarFileProperties render() should render ItemProperties for anonymous uploaders 1`] = `
<LoadingIndicatorWrapper>
<ItemProperties
archivedAt={1726832355000}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, all our endpoints should use the same format for dates. We can address that as a separate change, though, if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants