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

Improve serialization of VFS URL query parameters #165

Closed
wants to merge 15 commits into from

Conversation

mahsashadi
Copy link
Contributor

@mahsashadi mahsashadi commented Aug 29, 2021

The implementation of encodeQueryData method changes to support encoding of nested objects.

Relevant:

src/utils/fetch.js Outdated Show resolved Hide resolved
Copy link
Member

@andersevenrud andersevenrud left a comment

Choose a reason for hiding this comment

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

Could you please amend the commit message so that it says:

Improve serialization of VFS URL query parameters

@mahsashadi mahsashadi changed the title Update fetch.js Improve serialization of VFS URL query parameters Sep 3, 2021
src/utils/fetch.js Show resolved Hide resolved
Copy link
Member

@andersevenrud andersevenrud left a comment

Choose a reason for hiding this comment

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

Here is a test that you can place in a new file called __tests__/utils/fetch.js:

import * as fetch from '../../src/utils/fetch';

describe('utils.fetch#encodeQueryData', () => {
  test('should create valid query string', () => {
    const result1 = fetch.encodeQueryData({
      a: 1,
      b: true,
      c: null,
      d: 'foo'
    });

    const result2 = fetch.encodeQueryData({
      a: {
        a: 1,
        b: true,
        c: null,
        d: 'foo'
      },
      b: {
        c: {
          d: 'foo'
        }
      }
    });

    expect(result1).toEqual('a=1&b=true&c=null&d=foo');
    expect(result2).toEqual('a.a=1&a.b=true&a.c=null&a.d=foo&b.c.d=foo');
  });
});

As you can see from this test and the one in osjs-server, it demonstrates that issue with all values being strings 🤓

@mahsashadi
Copy link
Contributor Author

As you can see from this test and the one in osjs-server, it demonstrates that issue with all values being strings

Yes, You are totally right. We should preserve value type somehow.

@mahsashadi
Copy link
Contributor Author

mahsashadi commented Sep 5, 2021

To support encoding arrays, we can change method as below 🤔

function encodeQueryData(data, nesting = '') {
  const pairs = Object.entries(data).map(([key, val]) => {
    if (typeof val === 'object' && val !== null) {
      return Array.isArray(val)
        ? encodeQueryData(val, nesting + `${key}`)
        : encodeQueryData(val, nesting + `${key}.`);
    } else {
      return Array.isArray(data)
        ? encodeURIComponent(nesting) + '=' + encodeURIComponent(val)
        : encodeURIComponent(nesting + key) + '=' + encodeURIComponent(val);
    }
  });
  return pairs.join('&');
}

Do you have a better idea?

@mahsashadi
Copy link
Contributor Author

We should preserve value type somehow.

I have not yet reached a solution to this problem 🤔

@andersevenrud
Copy link
Member

Technically the serialization is correct, so I don't really think this needs to be changed to support arrays.

Copy link
Member

@andersevenrud andersevenrud left a comment

Choose a reason for hiding this comment

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

Good stuff!

Now that we're on the same wavelength on how this all should work, I thought I'd open a new review thread on the final issue which is to solve the preservation of types.

I have added a possible solution to this here: #165 (comment)

src/utils/fetch.js Outdated Show resolved Hide resolved
src/utils/fetch.js Outdated Show resolved Hide resolved
Copy link
Member

@andersevenrud andersevenrud left a comment

Choose a reason for hiding this comment

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

Sweet. I think this is done now.

I'm at work now, but I will test this myself etc. and merge when I get home.

@mahsashadi
Copy link
Contributor Author

Thanks a lot for your help :)
Sorry if it takes your time.
I learned a lot during this PR 👍

@andersevenrud
Copy link
Member

Thanks a lot for your help :)

And thank you for making these changes.

Sorry if it takes your time.

Don't worry about that. I haven't spent any time I don't have to look at this.

I learned a lot during this PR

Glad to hear that :)

@mahsashadi
Copy link
Contributor Author

mahsashadi commented Nov 7, 2021

Hi again :)
To continue work on filemanager pagination, I have commited some changes:

  • capabilities method is added to vfs (suggested here)
  • I have merged changes in this PR here.

@mahsashadi
Copy link
Contributor Author

Hi again, did you find anytime to take a look at my new commited codes?

@andersevenrud
Copy link
Member

Sorry. Personal stuff has prevented me from doing much lately. Sorry about that, but I will get to this ASAP.

@andersevenrud
Copy link
Member

Could you split up this PR so that it only contains the URL changes ?

Right now this technically contains two different kinds of work, and I don't want to merge everything at once.

@mahsashadi
Copy link
Contributor Author

@andersevenrud Here is the subset of changes for URL serialization:

#182

Here is the subset of changes for URL unserialization:

os-js/osjs-server#63

@mahsashadi
Copy link
Contributor Author

Do you agree to split like this:

  1. URL serialization (done)
  2. Client option filtering (maybe should be considered in url serialization)
  3. Add VFS capabilities method
  4. Improve client sorting algorithm

@andersevenrud
Copy link
Member

andersevenrud commented Jul 28, 2022

I'm closing this since we've agreed on a way to move forward.

I've also opened an issue where we can concentrate the discussion. Things got a bit confusing with the client/server stuff :D

os-js/OS.js#804

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants