Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose FileTypeIcons as HTML strings #15405

Merged
merged 13 commits into from
Nov 17, 2020

Conversation

arkogupta
Copy link
Contributor

@arkogupta arkogupta commented Oct 7, 2020

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file using $ yarn change

Description of changes

Rather than exposing the src of the img elements, we can just clone the whole JSX element as a string. If in the future, the implementation changes from <img> to something else, then the corresponding DOM element which will be used can again be stored as a string in the same dictionary, so that the consumer can continue to consume it seamlessly.

Focus areas to test

(optional)

@msft-github-bot msft-github-bot added the needs cherry-pick Temporary label for PRs which may need to be cherry-picked to master label Oct 7, 2020
@arkogupta arkogupta marked this pull request as draft October 7, 2020 16:07
@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 7, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 78b40ff:

Sandbox Source
Fluent UI Button Configuration
codesandbox-react-template Configuration

@msft-github-bot
Copy link
Contributor

msft-github-bot commented Oct 7, 2020

Perf Analysis

No significant results to display.

All results

Scenario Render type 7.0 Ticks PR Ticks Iterations Status
BaseButton mount 894 826 5000
Breadcrumb mount 42004 42134 5000
Checkbox mount 1497 1497 5000
CheckboxBase mount 1218 1267 5000
ChoiceGroup mount 4828 4787 5000
ComboBox mount 885 874 1000
CommandBar mount 7503 7556 1000
ContextualMenu mount 13415 14136 1000
DefaultButton mount 1124 1109 5000
DetailsRow mount 3465 3467 5000
DetailsRowFast mount 3534 3451 5000
DetailsRowNoStyles mount 3313 3320 5000
Dialog mount 1485 1438 1000
DocumentCardTitle mount 1833 1820 1000
Dropdown mount 2459 2482 5000
FocusTrapZone mount 1632 1669 5000
FocusZone mount 1830 1826 5000
IconButton mount 1732 1718 5000
Label mount 317 319 5000
Layer mount 1923 1905 5000
Link mount 445 426 5000
MenuButton mount 1491 1431 5000
MessageBar mount 2007 2002 5000
Nav mount 3189 3179 1000
OverflowSet mount 1377 1350 5000
Panel mount 1445 1384 1000
Persona mount 814 810 1000
Pivot mount 1439 1405 1000
PrimaryButton mount 1242 1246 5000
Rating mount 7434 7386 5000
SearchBox mount 1228 1226 5000
Shimmer mount 2523 2468 5000
Slider mount 1429 1463 5000
SpinButton mount 4995 4892 5000
Spinner mount 415 394 5000
SplitButton mount 3091 3086 5000
Stack mount 478 487 5000
StackWithIntrinsicChildren mount 1481 1484 5000
StackWithTextChildren mount 4583 4541 5000
SwatchColorPicker mount 9926 9977 5000
TagPicker mount 2674 2708 5000
TeachingBubble mount 50344 50168 5000
Text mount 421 404 5000
TextField mount 1338 1295 5000
Toggle mount 792 787 5000
button mount 110 95 5000

@size-auditor
Copy link

size-auditor bot commented Oct 7, 2020

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 52f5d891a274c6ea84aa4bb14cd961c1b89b2cf0 (build)

@arkogupta arkogupta marked this pull request as ready for review October 7, 2020 18:46
@layershifter layershifter reopened this Oct 8, 2020

src = `${baseUrlSizeType}.png`;
iconName = type + size + PNG_SUFFIX;
fileTypeIcons[iconName] = <img src={src} alt="" />;

Choose a reason for hiding this comment

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

minor question. Does this alt do something? Looks like it doesn't play any role here.

Copy link
Member

Choose a reason for hiding this comment

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

May be wrong, but I believe this is due to accessibility scanners which will warn when you have an image without considering the alt tag (even providing a blank one is considered "accessible")...

Copy link
Contributor

Choose a reason for hiding this comment

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

Might not be a bad idea to populate this alt text with type + " icon" ~ the type is not always super descriptive but we try our best to make it so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good suggestion! Will take that up as a separate PR. Thanks!

src = `${baseUrlSizeType}.svg`;
iconName = type + size + SVG_SUFFIX;
fileTypeIcons[iconName] = <img src={src} alt="" />;
_fileTypeIconsAsString[iconName] = `<img src="${src}" alt="" />`;
Copy link
Member

Choose a reason for hiding this comment

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

Rather than defining this on every definition, why not just generate it on demand in the exported functiongetFileTypeIconAsHTMLString

Copy link
Member

Choose a reason for hiding this comment

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

This icon map is quite large in memory so it would be nice if made on-demand rather than bloat the page more.

// }
// }
// }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @dzearing @KevinTCoughlin
Please have a look at this iteration. I had to do some refactoring and export a couple of functions from getFileTypeIconProps to be able to implement the function getFileTypeIconAsHTMLString which is basically kind of a sister clone of getFileTypeIconProps in that it accepts the same kind of object but rather than just returning the iconName, it returns the entire DOM element as a string.

The other option I had considered is this commented snippet; in which the consumer had to call getFileTypeIconProps to get the iconName and then just pass the iconName to the getFileTypeIconAsHTMLString function, but that IMO required some regEx parsing, and hence I avoided this approach.

Copy link
Member

Choose a reason for hiding this comment

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

can you remove the commented code

Copy link
Contributor Author

@arkogupta arkogupta Nov 5, 2020

Choose a reason for hiding this comment

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

@dzearing , removed.

@khmakoto
Copy link
Member

Now that we're publishing beta versions of 8.0 please also port this to the master branch once it merges.

@arkogupta
Copy link
Contributor Author

@KevinTCoughlin @dzearing please have a look whenever you get time. Thanks :)

IFileTypeIconOptions,
} from './getFileTypeIconProps';

export function getFileTypeIconAsHTMLString(
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment to this? Also the function is not being exported through the index file. And you will probably need to run yarn update-api to update the api-extractor definition of the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment and exported through the index file. I couldn't find an existing api.md or api-extractor.json file for this package. Should I add one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dzearing gentle ping! :)

Copy link
Member

Choose a reason for hiding this comment

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

We should add an API extractor config and API file for this package (same pattern as other packages).

@@ -5,8 +5,8 @@ import { FileTypeIconMap } from './FileTypeIconMap';
const PNG_SUFFIX = '_png';
const SVG_SUFFIX = '_svg';

const DEFAULT_BASE_URL = 'https://spoprod-a.akamaihd.net/files/fabric-cdn-prod_20201008.001/assets/item-types/';
const ICON_SIZES: number[] = [16, 20, 24, 32, 40, 48, 64, 96];
export const DEFAULT_BASE_URL = 'https://spoprod-a.akamaihd.net/files/fabric-cdn-prod_20201008.001/assets/item-types/';
Copy link
Member

Choose a reason for hiding this comment

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

A little confused why these are being exported.

Copy link
Member

Choose a reason for hiding this comment

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

(and the icon_sizes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am importing both of these in my test file. Also I need the default url while emitting the HTML as string from the new API.

@ecraig12345 ecraig12345 closed this Nov 7, 2020
@ecraig12345 ecraig12345 reopened this Nov 7, 2020
@dzearing
Copy link
Member

I am going to sign off to unblock the scenario; however I do think longer term we need to split out a separate @fluentui/file-type-icons package which is more the base package that has no React dependencies. This is where we'd do something like export a getFileTypeIcon api which returns more agnostic information in a structure.

@dzearing dzearing merged commit fef6e99 into microsoft:7.0 Nov 17, 2020
Copy link
Member

@ecraig12345 ecraig12345 left a comment

Choose a reason for hiding this comment

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

Coming in late here (sorry) but a couple comments to potentially address in the future.

@@ -0,0 +1,8 @@
{
"type": "patch",
Copy link
Member

Choose a reason for hiding this comment

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

For future reference, changes adding new public APIs should be minor not patch.

IFileTypeIconOptions,
} from './getFileTypeIconProps';

export function getFileTypeIconAsHTMLString(
Copy link
Member

Choose a reason for hiding this comment

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

We should add an API extractor config and API file for this package (same pattern as other packages).

@msft-github-bot
Copy link
Contributor

🎉@uifabric/[email protected] has been released which incorporates this pull request.:tada:

Handy links:

@kubkon kubkon self-assigned this Jan 29, 2021
@kubkon kubkon removed their assignment Feb 8, 2021
@ecraig12345 ecraig12345 removed the needs cherry-pick Temporary label for PRs which may need to be cherry-picked to master label Feb 19, 2021
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.