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

docs(versions): add versions #3486

Merged
merged 30 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0aed97d
docs(Checkbox): add examples to .mdx
Jul 11, 2024
3de264a
docs(Checkbox): add examples to .mdx
Jul 11, 2024
28cb039
Merge branch 'mdx-checkbox' of github.com:skbkontur/retail-ui into md…
Jul 11, 2024
f39efc3
docs(ValidationContainer): returned deleted screenshot img from Valid…
Jul 11, 2024
e9cb6ba
Merge branch 'mdx-exaples-on-storybook-7' into mdx-checkbox
SchwJ Jul 12, 2024
958b8df
fix(): mini-fix indents to start CI tests
SchwJ Jul 12, 2024
06f1821
Merge branch 'mdx-exaples-on-storybook-7' into mdx-checkbox
SchwJ Jul 14, 2024
6206426
docs(Versions): add versions react-ui library
Jul 16, 2024
1bc96a8
docs(LocaleDecorator): add locale decarator in storybook
Jul 17, 2024
b3ba4da
docs(LocaleDecorator): add hideLocaleBtnInUnsupportedControls
Jul 18, 2024
fea442c
docs(LocaleDecorator): add dynamic text with icon, prettier
Jul 22, 2024
08fe4db
Merge branch 'mdx-exaples-on-storybook-7' into mdx-toolbar-locale
SchwJ Jul 30, 2024
2be392b
Merge branch 'mdx-exaples-on-storybook-7' into mdx-checkbox
SchwJ Jul 30, 2024
aa18c41
chore(Checkbox): fix screenshots
SchwJ Jul 30, 2024
a457625
chore(Checkbox): fix screenshots and lint
SchwJ Jul 30, 2024
05b0a55
Merge pull request #3466 from skbkontur/mdx-checkbox
SchwJ Jul 30, 2024
5315b84
chore(): fix merge error
SchwJ Jul 30, 2024
ddcceed
chore(): fix lint errors
SchwJ Jul 31, 2024
7cc21b0
docs(featureFlags): update featureFlagsConfig.tsx
Aug 7, 2024
a3193de
docs(LocaleDecorator): update LocaleDecorator
Aug 8, 2024
65a5de8
Merge pull request #3473 from skbkontur/mdx-toolbar-features
SchwJ Aug 8, 2024
86eb79b
Merge branch 'mdx-exaples-on-storybook-7' into mdx-toolbar-locale
SchwJ Aug 8, 2024
f7c5816
Merge pull request #3471 from skbkontur/mdx-toolbar-locale
SchwJ Aug 8, 2024
7e90d78
Merge remote-tracking branch 'origin/mdx-exaples-on-storybook-7' into…
Aug 14, 2024
66a27cb
docs(versions): update Versions mdx,tsx
Aug 16, 2024
0afbb46
Merge branch 'mdx-exaples-on-storybook-7' into mdx-versions
Aug 16, 2024
8ce9224
docs(versions): fix lint
Aug 16, 2024
d6978ba
docs(versions): update catch err
Aug 19, 2024
d60e023
docs(versions): update error message
Aug 20, 2024
ff2701e
docs(versions): update error message
Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { VersionsLibrary } from './Versions';
import { Meta } from '@storybook/blocks';

<Meta title="Versions" />

# Версии React UI

<VersionsLibrary />
80 changes: 80 additions & 0 deletions packages/react-ui/components/__stories__/Versions/Versions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';

import { Loader } from '../../Loader';
import { Link } from '../../Link';

interface LibraryVersion {
version: string;
path: string;
}
interface ResponseData {
versions: LibraryVersion[];
}

const baseUrl = 'https://ui.gitlab-pages.kontur.host/docs/react-ui-storybook';
const createEndpoint = (path: string) => `${baseUrl}/${path}`;
const jsonEndpoint = createEndpoint('reactUIStorybookVersions.json');

const renderLibraryVersionItem = ({ path, version }: LibraryVersion) => {
return (
<li key={path}>
<Link target="_blank" href={path}>
{version}
</Link>
</li>
);
};

const renderLibraryVersions = (libraryVersions: LibraryVersion[]) => {
if (libraryVersions.length === 0) {
return <p>Список версий пуст.</p>;
}

return <ul>{libraryVersions.map((libraryVersion) => renderLibraryVersionItem(libraryVersion))}</ul>;
Copy link
Member

Choose a reason for hiding this comment

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

Давай запишем это в несколько строчек: ul и его содержимое. Код, записанный так, более удобно читать

Copy link
Member Author

Choose a reason for hiding this comment

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

При запуске prettier все собирается в 1 строчку

Copy link
Member

Choose a reason for hiding this comment

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

👌

};

const renderErrorMessage = (errMessage?: string) => {
return (
<>
<p style={{ margin: '0' }}>Не удалось загрузить список версий.</p>
<p style={{ margin: '0' }}>{errMessage ? `Ошибка при запросе: ${errMessage}.` : 'Ошибка при запросе.'}</p>
</>
);
};

export const VersionsLibrary = () => {
const [errMessage, setErrorMessage] = React.useState('');
const [libraryVersions, setLibraryVersions] = React.useState<LibraryVersion[]>([]);
const [isLoading, setIsLoading] = React.useState(false);

React.useEffect(() => {
const fetchAllVersionsLibrary = async () => {
try {
setIsLoading(true);
const response = await fetch(jsonEndpoint);
if (!response.ok) {
setErrorMessage(`${response.status}`);
setLibraryVersions([]);
return;
}
const { versions }: ResponseData = await response.json();
setErrorMessage('');
setLibraryVersions(versions);
} catch (err) {
setErrorMessage(err?.message);
setLibraryVersions([]);
} finally {
setIsLoading(false);
}
};

void fetchAllVersionsLibrary();
}, []);

return (
<Loader active={isLoading}>
{errMessage && renderErrorMessage(errMessage)}
{!errMessage && !isLoading && renderLibraryVersions(libraryVersions)}
</Loader>
);
};