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

feat(media dir nav): navigation through sub directories and breadcrumbs #4670

Draft
wants to merge 63 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d915617
feat(media dir nav): navigation through sub directories and breadcrumbs
andrew-paterson Dec 2, 2020
b712a7e
refactor: simplify code by listing files recursively
erezrokah Dec 6, 2020
1ce6f50
feat(media dir nav): uploading to nested directories works
andrew-paterson Dec 21, 2020
0c6fdef
feat(media dir nav): basic ui for multiple asset selection
andrew-paterson Dec 21, 2020
b6f6a81
feat(media dir nav): selected assets array cleared when user changes …
andrew-paterson Dec 21, 2020
4089afa
feat(media dir nav): delete button enabled when at least one media as…
andrew-paterson Dec 22, 2020
391aede
feat(media dir nav): synchronous deletion of multiple files
andrew-paterson Dec 22, 2020
a6499c9
feat(media dir nav): navigation through sub directories and breadcrumbs
andrew-paterson Dec 2, 2020
16195ef
refactor: simplify code by listing files recursively
erezrokah Dec 6, 2020
3c64681
feat(media dir nav): uploading to nested directories works
andrew-paterson Dec 21, 2020
405e04d
feat(media dir nav): basic ui for multiple asset selection
andrew-paterson Dec 21, 2020
49bc289
feat(media dir nav): selected assets array cleared when user changes …
andrew-paterson Dec 21, 2020
7b0bcc6
feat(media dir nav): delete button enabled when at least one media as…
andrew-paterson Dec 22, 2020
97709e3
feat(media dir nav): synchronous deletion of multiple files
andrew-paterson Dec 22, 2020
cada8c9
refactor: code cleanup
erezrokah Jan 12, 2021
cdd4842
feat(media dir nav): fixed merge conflicts
andrew-paterson Jan 18, 2021
bfec05d
feat(media dir nav): current media folder initially derived from file…
andrew-paterson Jan 18, 2021
efdc470
feat(media dir nav): nav with collections works and is optional
andrew-paterson Jan 18, 2021
7d26160
feat(media dir nav): disabling dir nav works for fields and collections
andrew-paterson Jan 18, 2021
8fe35ca
feat(media dir nav): current media navigation forgotten when user clo…
andrew-paterson Jan 18, 2021
318c0c0
chore: fix linting, formating, tests
erezrokah Jan 28, 2021
cde1467
Merge branch 'master' into feat/nested_media_dirs
erezrokah Jan 28, 2021
1a44004
Merge branch 'master' into feat/nested_media_dirs
erezrokah Feb 7, 2021
0247ceb
Merge branch 'master' into feat/nested_media_dirs
erezrokah Feb 7, 2021
0ca4286
Merge branch 'master' into feat/nested_media_dirs
erezrokah Feb 7, 2021
0a2ab86
Merge branch 'master' into feat/nested_media_dirs
erezrokah Feb 14, 2021
198c4b1
feat(media dir nav): empty folder creation
andrew-paterson Feb 15, 2021
eb41f0e
Update packages/netlify-cms-core/src/components/MediaLibrary/MediaLib…
andrew-paterson Feb 15, 2021
3b822c4
feat(media dir nav): remove junk file
andrew-paterson Feb 15, 2021
2aa5ee2
feat(media dir nav): revert dev-test config
andrew-paterson Feb 24, 2021
7adaff1
Merge branch 'master' into feat/nested_media_dirs
erezrokah Mar 11, 2021
88cdf88
style: run prettier
erezrokah Mar 11, 2021
af24db8
Merge branch 'master' into feat/nested_media_dirs
erezrokah Mar 14, 2021
7540d60
fix: config access
erezrokah Mar 14, 2021
9041de0
fix: add missing translation
erezrokah Mar 14, 2021
8546b30
feat(media dir nav): revert dev-test config
andrew-paterson Mar 17, 2021
23ff683
Merge branch 'feat/nested_media_dirs' of github.com:andrew-paterson/n…
andrew-paterson Mar 17, 2021
f07937f
feat(media dir nav): fix breadcrumbs bug
andrew-paterson Mar 23, 2021
39a2e39
feat(media dir nav): use current media folder for select media file p…
andrew-paterson Mar 31, 2021
b8b2367
feat(media dir nav): accommodate collection and field level media fol…
andrew-paterson Apr 6, 2021
e0452c8
Merge branch 'master' into feat/nested_media_dirs
erezrokah Apr 6, 2021
e462272
chore: fix formatting and lint warnings
erezrokah Apr 6, 2021
9c3419e
Merge branch 'master' into feat/nested_media_dirs
erezrokah Apr 7, 2021
ccdbf6f
Merge branch 'master' into feat/nested_media_dirs
erezrokah Apr 7, 2021
73de67d
fix: typetcript error
erezrokah Apr 7, 2021
84a3063
feat(media dir nav): bugfix - current media folder returned correctly
andrew-paterson Apr 8, 2021
7369c12
Merge branch 'feat/nested_media_dirs' of github.com:andrew-paterson/n…
andrew-paterson Apr 8, 2021
23bc33b
feat(media dir nav): media files filtered in new way
andrew-paterson Apr 12, 2021
d04ef68
feat(media dir nav): remove console statement
andrew-paterson Apr 12, 2021
f31cdcd
fix: format and lint errors
erezrokah Apr 18, 2021
d2ef185
Merge branch 'feat/nested_media_dirs' of github.com:andrew-paterson/n…
andrew-paterson Apr 19, 2021
ab1dab8
feat(media dir nav): derive current media folder in entries module
andrew-paterson Apr 19, 2021
11ee881
feat(media dir nav): bugfix
Apr 20, 2021
7a27a65
feat(media dir nav): bugfix
Apr 20, 2021
f9ce92e
feat(media dir nav): small refactor to fix failing tests.
Apr 21, 2021
da3ff3e
feat(media dir nav): handle relative media_folder set on field
andrew-paterson Apr 26, 2021
25d49a3
Merge branch 'master' into feat/nested_media_dirs
erezrokah May 3, 2021
ddf8b98
Merge branch 'master' into feat/nested_media_dirs
erezrokah May 9, 2021
bcb07a1
Merge branch 'master' into feat/nested_media_dirs
erezrokah May 30, 2021
10fe4f2
style: run prettier
erezrokah May 30, 2021
0eb6f36
Merge branch 'main' into feat/nested_media_dirs
martinjagodic Aug 29, 2024
d3736d5
fix: css lint
martinjagodic Aug 29, 2024
fbee623
fix: js lint
martinjagodic Aug 29, 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
28 changes: 19 additions & 9 deletions packages/decap-cms-backend-github/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ export interface Config {
getUser: ({ token }: { token: string }) => Promise<GitHubUser>;
}

export enum TreeFileType {
TREE = 'tree',
BLOB = 'blob',
}

interface TreeFile {
type: 'blob' | 'tree';
type: TreeFileType;
sha: string;
path: string;
raw?: string;
Expand Down Expand Up @@ -382,7 +387,9 @@ export default class API {
this.request(`${this.repoURL}/git/trees`, {
method: 'POST',
body: JSON.stringify({
tree: [{ path: 'README.md', mode: '100644', type: 'blob', sha: item.sha }],
tree: [
{ path: 'README.md', mode: '100644', type: TreeFileType.BLOB, sha: item.sha },
],
}),
}),
)
Expand Down Expand Up @@ -676,8 +683,8 @@ export default class API {

async listFiles(
path: string,
{ repoURL = this.repoURL, branch = this.branch, depth = 1 } = {},
): Promise<{ type: string; id: string; name: string; path: string; size: number }[]> {
{ repoURL = this.repoURL, branch = this.branch, depth = 1, types = [TreeFileType.BLOB] } = {},
): Promise<{ type: TreeFileType; id: string; name: string; path: string; size: number }[]> {
const folder = trim(path, '/');
try {
const result: Octokit.GitGetTreeResponse = await this.request(
Expand All @@ -691,9 +698,12 @@ export default class API {
return (
result.tree
// filter only files and up to the required depth
.filter(file => file.type === 'blob' && file.path.split('/').length <= depth)
.filter(
file =>
types.includes(file.type as TreeFileType) && file.path.split('/').length <= depth,
)
.map(file => ({
type: file.type,
type: file.type as TreeFileType,
id: file.sha,
name: basename(file.path),
path: `${folder}/${file.path}`,
Expand Down Expand Up @@ -1394,7 +1404,7 @@ export default class API {
const entry = {
path: trimStart(file.path, '/'),
mode: '100644',
type: 'blob',
type: TreeFileType.BLOB,
sha: file.sha,
} as TreeEntry;

Expand All @@ -1416,14 +1426,14 @@ export default class API {
tree.push({
path: file.path,
mode: '100644',
type: 'blob',
type: TreeFileType.BLOB,
sha: null,
});
// create in new path
tree.push({
path: file.path.replace(sourceDir, destDir),
mode: '100644',
type: 'blob',
type: TreeFileType.BLOB,
sha: file.path === from ? sha : file.id,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('github GraphQL API', () => {
];
const path = 'posts';

expect(api.getAllFiles(entries, path)).toEqual([
expect(api.getAllFiles(entries, path, ['blob'])).toEqual([
{
name: 'post-1.md',
id: 'sha-1',
Expand All @@ -65,5 +65,70 @@ describe('github GraphQL API', () => {
},
]);
});

it('should should return directories when types includes `tree`', () => {
const api = new GraphQLAPI({ branch: 'gh-pages', repo: 'owner/my-repo' });
const entries = [
{
name: 'post-1.md',
sha: 'sha-1',
type: 'blob',
blob: { size: 1 },
},
{
name: 'post-2.md',
sha: 'sha-2',
type: 'blob',
blob: { size: 2 },
},
{
name: '2019',
sha: 'dir-sha',
type: 'tree',
object: {
entries: [
{
name: 'nested-post.md',
sha: 'nested-post-sha',
type: 'blob',
blob: { size: 3 },
},
],
},
},
];
const path = 'posts';

expect(api.getAllFiles(entries, path, ['blob', 'tree'])).toEqual([
{
name: 'post-1.md',
id: 'sha-1',
type: 'blob',
size: 1,
path: 'posts/post-1.md',
},
{
name: 'post-2.md',
id: 'sha-2',
type: 'blob',
size: 2,
path: 'posts/post-2.md',
},
{
name: '2019',
id: 'dir-sha',
type: 'tree',
size: 0,
path: 'posts/2019',
},
{
name: 'nested-post.md',
id: 'nested-post-sha',
type: 'blob',
size: 3,
path: 'posts/2019/nested-post.md',
},
]);
});
});
});
1 change: 0 additions & 1 deletion packages/decap-cms-core/src/actions/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export function getAsset({ collection, entry, path, field }: GetAssetArgs) {

const state = getState();
const resolvedPath = selectMediaFilePath(state.config, collection, entry, path, field);

let { asset, isLoading, error } = state.medias[resolvedPath] || {};
if (isLoading) {
return emptyAsset;
Expand Down
27 changes: 22 additions & 5 deletions packages/decap-cms-core/src/actions/mediaLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,24 @@ function createMediaFileFromAsset({
}

export function persistMedia(file: File, opts: MediaOptions = {}) {
const { privateUpload, field } = opts;
const { privateUpload, field, currentMediaFolder } = opts;
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
const state = getState();
const backend = currentBackend(state.config);
const integration = selectIntegration(state, null, 'assetStore');
const files: MediaFile[] = selectMediaFiles(state, field);
const files: MediaFile[] = selectMediaFiles(state);
const fileName = sanitizeSlug(file.name.toLowerCase(), state.config.slug);
const existingFile = files.find(existingFile => existingFile.name.toLowerCase() === fileName);

const entry = state.entryDraft.get('entry');
const collection = state.collections.get(entry?.get('collection'));
const path = selectMediaFilePath(
state.config,
collection,
entry,
fileName,
field,
currentMediaFolder,
);
const existingFile = files.find(existingFile => existingFile.path.toLowerCase() === path);
const editingDraft = selectEditingDraft(state.entryDraft);

/**
Expand Down Expand Up @@ -265,7 +274,14 @@ export function persistMedia(file: File, opts: MediaOptions = {}) {
} else {
const entry = state.entryDraft.get('entry');
const collection = state.collections.get(entry?.get('collection'));
const path = selectMediaFilePath(state.config, collection, entry, fileName, field);
const path = selectMediaFilePath(
state.config,
collection,
entry,
fileName,
field,
currentMediaFolder,
);
assetProxy = createAssetProxy({
file,
path,
Expand Down Expand Up @@ -437,6 +453,7 @@ export function mediaLoading(page: number) {
interface MediaOptions {
privateUpload?: boolean;
field?: EntryField;
currentMediaFolder?: string;
page?: number;
canPaginate?: boolean;
dynamicSearch?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/decap-cms-core/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export interface MediaFile {
url?: string;
file?: File;
field?: EntryField;
isDirectory?: boolean;
}

interface BackupEntry {
Expand Down
Loading
Loading